From d94f4ab1052fc15248396a062c56ffd45bfefb85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 14 Oct 2010 15:28:40 +0200 Subject: [PATCH] Add page that views a Sone. --- .../net/pterodactylus/sone/web/ViewSonePage.java | 69 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 4 ++ src/main/resources/i18n/sone.en.properties | 7 +++ src/main/resources/templates/viewSone.html | 29 +++++++++ 4 files changed, 109 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/web/ViewSonePage.java create mode 100644 src/main/resources/templates/viewSone.html diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java new file mode 100644 index 0000000..4a12ed9 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -0,0 +1,69 @@ +/* + * Sone - ViewSonePage.java - Copyright © 2010 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 net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.template.Template; + +/** + * Lets the user browser another Sone. + * + * @author David ‘Bombe’ Roden + */ +public class ViewSonePage extends SoneTemplatePage { + + /** + * Creates a new “view Sone” page. + * + * @param template + * The template to render + * @param webInterface + * The Sone web interface + */ + public ViewSonePage(Template template, WebInterface webInterface) { + super("viewSone.html", template, "Page.ViewSone.Title", webInterface); + } + + // + // TEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(Request request, Template template) throws RedirectException { + super.processTemplate(request, template); + String soneId = request.getHttpRequest().getParam("sone"); + Sone sone = webInterface.core().getSone(soneId); + template.set("sone", sone); + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected boolean requiresLogin() { + return true; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index e85b066..5856aa4 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -160,6 +160,9 @@ public class WebInterface extends AbstractService { Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html")); editProfileTemplate.set("formPassword", formPassword); + Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html")); + viewSoneTemplate.set("formPassword", formPassword); + Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html")); deleteSoneTemplate.set("formPassword", formPassword); @@ -170,6 +173,7 @@ public class WebInterface extends AbstractService { pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone")); pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile")); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone")); pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login")); pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(logoutTemplate, this), "Logout")); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index d56627f..5a99acb 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -65,4 +65,11 @@ Page.CreatePost.Label.Text=Post text: Page.CreatePost.Button.Post=Post! Page.CreatePost.Error.EmptyText=You did not enter any text, which is a pity. You should try writing more! +Page.ViewSone.Title=View Sone - Sone +Page.ViewSone.Page.TitleWithoutSone=View unknown Sone +Page.ViewSone.Page.TitleWithSone=View Sone “{sone}” +Page.ViewSone.UnknownSone.Description=This Sone has not yet been retrieved. Please check back in a short time. +Page.ViewSone.PostList.Title=Posts by “{sone}” +Page.ViewSone.PostList.Text.NoPostYet=This Sone has not yet posted anything. + Page.Logout.Title=Logout - Sone diff --git a/src/main/resources/templates/viewSone.html b/src/main/resources/templates/viewSone.html new file mode 100644 index 0000000..a984ce5 --- /dev/null +++ b/src/main/resources/templates/viewSone.html @@ -0,0 +1,29 @@ +
+ + <%ifnull sone.name> + +

<%= Page.ViewSone.Page.TitleWithoutSone|l10n|html>

+ +
<%= Page.ViewSone.UnknownSone.Description|l10n|html>
+ + <%else> + +

<%= Page.ViewSone.Page.TitleWithSone|l10n|insert needle="{sone}" key=sone.name|html> + +

<%= Page.ViewSone.PostList.Title|l10n|insert needle="{sone}" key=sone.name|html>

+ +
+ <%foreach sone.posts post> +
+ +
<% post.text|html>
+
<% post.time|date format="MMM d, yyyy, HH:mm:ss">
+
+ <%foreachelse> +
<%= Page.ViewSone.PostList.Text.NoPostYet|l10n|html>
+ <%/foreach> +
+ + <%/if> + +
-- 2.7.4