From: David ‘Bombe’ Roden <bombe@pterodactylus.net>
Date: Thu, 14 Oct 2010 13:28:40 +0000 (+0200)
Subject: Add page that views a Sone.
X-Git-Tag: 0.1-RC1~379
X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d94f4ab1052fc15248396a062c56ffd45bfefb85;p=Sone.git

Add page that views a Sone.
---

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 <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;
+	}
+
+}
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 @@
+<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>