Add link to unbookmark all not loaded posts at once.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Mar 2011 07:44:11 +0000 (08:44 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Mar 2011 07:44:11 +0000 (08:44 +0100)
src/main/java/net/pterodactylus/sone/web/BookmarksPage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/bookmarks.html

index d8a18c8..d6f63aa 100644 (file)
@@ -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<Post> posts = webInterface.getCore().getBookmarkedPosts();
-               List<Post> sortedPosts = new ArrayList<Post>(posts);
+               Set<Post> allPosts = webInterface.getCore().getBookmarkedPosts();
+               Set<Post> loadedPosts = Filters.filteredSet(allPosts, new Filter<Post>() {
+
+                       @Override
+                       public boolean filterObject(Post post) {
+                               return post.getSone() != null;
+                       }
+               });
+               List<Post> sortedPosts = new ArrayList<Post>(loadedPosts);
                Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
                Pagination<Post> pagination = new Pagination<Post>(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());
        }
 
 }
index 4d912e9..9b48cad 100644 (file)
@@ -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
index 315a5e1..8768b5a 100644 (file)
@@ -7,20 +7,13 @@
        <div id="posts">
                <%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>
-                       <p><%= Page.Bookmarks.Text.PostsNotLoaded|l10n|html></p>
-               <%else>
-                       <%if !postShown>
-                               <p><%= Page.Bookmarks.Text.NoBookmarks|l10n|html></p>
-                       <%/if>
+               <%if postsNotLoaded>
+                       <p><%= Page.Bookmarks.Text.PostsNotLoaded|l10n|html|replace needle='{link}' replacement='<a href="unbookmark.html?post=allNotLoaded">'|replace needle='{/link}' replacement='</a>'></p>
+               <%elseif posts.empty>
+                       <p><%= Page.Bookmarks.Text.NoBookmarks|l10n|html></p>
                <%/if>
        </div>