Add page that shows all bookmarks.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 17 Feb 2011 10:26:26 +0000 (11:26 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 17 Feb 2011 10:26:26 +0000 (11:26 +0100)
src/main/java/net/pterodactylus/sone/web/BookmarksPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/bookmarks.html [new file with mode: 0644]

diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java
new file mode 100644 (file)
index 0000000..d8a18c8
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Sone - BookmarksPage.java - Copyright © 2011 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.number.Numbers;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+/**
+ * Page that lets the user browse all his bookmarked posts.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class BookmarksPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new bookmarks page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public BookmarksPage(Template template, WebInterface webInterface) {
+               super("bookmarks.html", template, "Page.Bookmarks.Title", webInterface);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @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);
+               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());
+       }
+
+}
index d0cd564..89cec92 100644 (file)
@@ -522,6 +522,7 @@ public class WebInterface implements CoreListener {
                Template createSoneTemplate = TemplateParser.parse(createReader("/templates/createSone.html"));
                Template createPostTemplate = TemplateParser.parse(createReader("/templates/createPost.html"));
                Template createReplyTemplate = TemplateParser.parse(createReader("/templates/createReply.html"));
+               Template bookmarksTemplate = TemplateParser.parse(createReader("/templates/bookmarks.html"));
                Template editProfileTemplate = TemplateParser.parse(createReader("/templates/editProfile.html"));
                Template editProfileFieldTemplate = TemplateParser.parse(createReader("/templates/editProfileField.html"));
                Template deleteProfileFieldTemplate = TemplateParser.parse(createReader("/templates/deleteProfileField.html"));
@@ -562,6 +563,7 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownPage(emptyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarkPage(emptyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UnbookmarkPage(emptyTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarksPage(bookmarksTemplate, this), "Bookmarks"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(emptyTemplate, this), "Logout"));
index 08f5f6d..2165bb5 100644 (file)
@@ -8,6 +8,8 @@ Navigation.Menu.Item.CreateSone.Name=Create Sone
 Navigation.Menu.Item.CreateSone.Tooltip=Create a new Sone
 Navigation.Menu.Item.KnownSones.Name=Known Sones
 Navigation.Menu.Item.KnownSones.Tooltip=Shows all known Sones
+Navigation.Menu.Item.Bookmarks.Name=Bookmarks
+Navigation.Menu.Item.Bookmarks.Tooltip=Show bookmarked posts
 Navigation.Menu.Item.EditProfile.Name=Edit Profile
 Navigation.Menu.Item.EditProfile.Tooltip=Edit the Profile of your Sone
 Navigation.Menu.Item.DeleteSone.Name=Delete Sone
@@ -162,6 +164,9 @@ Page.MarkAsKnown.Title=Mark as Known - Sone
 
 Page.Bookmark.Title=Bookmark - Sone
 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.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
new file mode 100644 (file)
index 0000000..ddf2bfc
--- /dev/null
@@ -0,0 +1,17 @@
+<%include include/head.html>
+
+       <div class="page-id hidden">bookmarks</div>
+
+       <h1><%= Page.Bookmarks.Page.Title|l10n|html></h1>
+
+       <div id="posts">
+               <%include include/pagination.html>
+               <%foreach posts post>
+                       <%include include/viewPost.html>
+               <%foreachelse>
+                       <p><%= Page.Bookmarks.Text.NoBookmarks|l10n|html></p>
+               <%/foreach>
+               <%include include/pagination.html>
+       </div>
+
+<%include include/tail.html>