Add page that views a Sone.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 13:28:40 +0000 (15:28 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Oct 2010 13:28:40 +0000 (15:28 +0200)
src/main/java/net/pterodactylus/sone/web/ViewSonePage.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/viewSone.html [new file with mode: 0644]

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 (file)
index 0000000..4a12ed9
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web;
+
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * Lets the user browser another Sone.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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;
+       }
+
+}
index e85b066..5856aa4 100644 (file)
@@ -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"));
index d56627f..5a99acb 100644 (file)
@@ -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 (file)
index 0000000..a984ce5
--- /dev/null
@@ -0,0 +1,29 @@
+<div id="sone">
+
+       <%ifnull sone.name>
+
+               <h1><%= Page.ViewSone.Page.TitleWithoutSone|l10n|html></h1>
+
+               <div><%= Page.ViewSone.UnknownSone.Description|l10n|html></div>
+
+       <%else>
+
+               <h1></h1><%= Page.ViewSone.Page.TitleWithSone|l10n|insert needle="{sone}" key=sone.name|html></h1>
+
+               <h1><%= Page.ViewSone.PostList.Title|l10n|insert needle="{sone}" key=sone.name|html></h1>
+
+               <div id="posts">
+                       <%foreach sone.posts post>
+                               <div class="post">
+                                       <div class="author"><a href="viewSone.html?sone=<% post.sone.id>"><% post.sone.name|html></a></div>
+                                       <div class="text"><% post.text|html></div>
+                                       <div class="time"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></div>
+                               </div>
+                       <%foreachelse>
+                               <div><%= Page.ViewSone.PostList.Text.NoPostYet|l10n|html></div>
+                       <%/foreach>
+               </div>
+
+       <%/if>
+
+</div>