From 70ae6c8bb784c24ac183bb485d0efa324fa0acd2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 12 Mar 2011 08:44:11 +0100 Subject: [PATCH] Add link to unbookmark all not loaded posts at once. --- .../java/net/pterodactylus/sone/web/BookmarksPage.java | 14 ++++++++++++-- src/main/resources/i18n/sone.en.properties | 2 +- src/main/resources/templates/bookmarks.html | 17 +++++------------ 3 files changed, 18 insertions(+), 15 deletions(-) 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>
-- 2.7.4