From: David ‘Bombe’ Roden Date: Sat, 12 Mar 2011 07:44:11 +0000 (+0100) Subject: Add link to unbookmark all not loaded posts at once. X-Git-Tag: 0.5.1^2~2 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=70ae6c8bb784c24ac183bb485d0efa324fa0acd2;p=Sone.git Add link to unbookmark all not loaded posts at once. --- diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java index d8a18c8..d6f63aa 100644 --- a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java +++ b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java @@ -24,6 +24,8 @@ import java.util.Set; import net.pterodactylus.sone.data.Post; import net.pterodactylus.util.collection.Pagination; +import net.pterodactylus.util.filter.Filter; +import net.pterodactylus.util.filter.Filters; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -57,12 +59,20 @@ public class BookmarksPage extends SoneTemplatePage { @Override protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - Set posts = webInterface.getCore().getBookmarkedPosts(); - List sortedPosts = new ArrayList(posts); + Set allPosts = webInterface.getCore().getBookmarkedPosts(); + Set loadedPosts = Filters.filteredSet(allPosts, new Filter() { + + @Override + public boolean filterObject(Post post) { + return post.getSone() != null; + } + }); + List sortedPosts = new ArrayList(loadedPosts); Collections.sort(sortedPosts, Post.TIME_COMPARATOR); Pagination pagination = new Pagination(sortedPosts, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); templateContext.set("pagination", pagination); templateContext.set("posts", pagination.getItems()); + templateContext.set("postsNotLoaded", allPosts.size() != loadedPosts.size()); } } diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 4d912e9..9b48cad 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -167,7 +167,7 @@ Page.Unbookmark.Title=Remove Bookmark - Sone Page.Bookmarks.Title=Bookmarks - Sone Page.Bookmarks.Page.Title=Bookmarks Page.Bookmarks.Text.NoBookmarks=You don’t have any bookmarks defined right now. You can bookmark posts by clicking the star below the post. -Page.Bookmarks.Text.PostsNotLoaded=Some of your bookmarked posts have not been shown because they could not be loaded. This can happen if your restarted Sone recently or if the originating Sone has deleted the post. +Page.Bookmarks.Text.PostsNotLoaded=Some of your bookmarked posts have not been shown because they could not be loaded. This can happen if you restarted Sone recently or if the originating Sone has deleted the post. If you are reasonable sure that these posts do not exist anymore, you can {link}unbookmark them{/link}. Page.NoPermission.Title=Unauthorized Access - Sone Page.NoPermission.Page.Title=Unauthorized Access diff --git a/src/main/resources/templates/bookmarks.html b/src/main/resources/templates/bookmarks.html index 315a5e1..8768b5a 100644 --- a/src/main/resources/templates/bookmarks.html +++ b/src/main/resources/templates/bookmarks.html @@ -7,20 +7,13 @@
<%include include/pagination.html> <%foreach posts post> - <%if post.loaded> - <%= true|store key=postShown parent=true> - <%include include/viewPost.html> - <%else> - <%= true|store key=postNotLoaded parent=true> - <%/if> + <%include include/viewPost.html> <%/foreach> <%include include/pagination.html> - <%if postNotLoaded> -

<%= Page.Bookmarks.Text.PostsNotLoaded|l10n|html>

- <%else> - <%if !postShown> -

<%= Page.Bookmarks.Text.NoBookmarks|l10n|html>

- <%/if> + <%if postsNotLoaded> +

<%= Page.Bookmarks.Text.PostsNotLoaded|l10n|html|replace needle='{link}' replacement=''|replace needle='{/link}' replacement=''>

+ <%elseif posts.empty> +

<%= Page.Bookmarks.Text.NoBookmarks|l10n|html>

<%/if>