From d34cc2c44a2fb19104988534504f2a96a9f0cb93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 17 Feb 2011 11:26:26 +0100 Subject: [PATCH] Add page that shows all bookmarks. --- .../net/pterodactylus/sone/web/BookmarksPage.java | 68 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 2 + src/main/resources/i18n/sone.en.properties | 5 ++ src/main/resources/templates/bookmarks.html | 17 ++++++ 4 files changed, 92 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/web/BookmarksPage.java create mode 100644 src/main/resources/templates/bookmarks.html 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 index 0000000..d8a18c8 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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 posts = webInterface.getCore().getBookmarkedPosts(); + List sortedPosts = new ArrayList(posts); + 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()); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index d0cd564..89cec92 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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")); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 08f5f6d..2165bb5 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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 index 0000000..ddf2bfc --- /dev/null +++ b/src/main/resources/templates/bookmarks.html @@ -0,0 +1,17 @@ +<%include include/head.html> + + + +

<%= Page.Bookmarks.Page.Title|l10n|html>

+ +
+ <%include include/pagination.html> + <%foreach posts post> + <%include include/viewPost.html> + <%foreachelse> +

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

+ <%/foreach> + <%include include/pagination.html> +
+ +<%include include/tail.html> -- 2.7.4