Add “known Sones” page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Oct 2010 02:58:35 +0000 (04:58 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Oct 2010 02:58:35 +0000 (04:58 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/web/KnownSonesPage.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/knownSones.html [new file with mode: 0644]

index eb517fc..c910799 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.core;
 
 import java.net.MalformedURLException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -141,6 +142,15 @@ public class Core extends AbstractService {
        }
 
        /**
+        * Returns all known sones.
+        *
+        * @return All known sones
+        */
+       public Collection<Sone> getKnownSones() {
+               return soneCache.values();
+       }
+
+       /**
         * Creates a new post.
         *
         * @param sone
diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java
new file mode 100644 (file)
index 0000000..0127172
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Sone - KnownSonesPage.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.util.template.Template;
+
+/**
+ * This page shows all known Sones.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class KnownSonesPage extends SoneTemplatePage {
+
+       /**
+        * Creates a “known Sones” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public KnownSonesPage(Template template, WebInterface webInterface) {
+               super("knownSones.html", template, "Page.KnownSones.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               super.processTemplate(request, template);
+               template.set("knownSones", webInterface.core().getKnownSones());
+       }
+
+}
index e628533..4545ac5 100644 (file)
@@ -160,6 +160,9 @@ public class WebInterface extends AbstractService {
                Template addSoneTemplate = templateFactory.createTemplate(createReader("/templates/addSone.html"));
                addSoneTemplate.set("formPassword", formPassword);
 
+               Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html"));
+               knownSonesTemplate.set("formPassword", formPassword);
+
                Template createSoneTemplate = templateFactory.createTemplate(createReader("/templates/createSone.html"));
                createSoneTemplate.set("formPassword", formPassword);
 
@@ -190,6 +193,7 @@ public class WebInterface extends AbstractService {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new AddSonePage(addSoneTemplate, this), "AddSone"));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
index 7ee2d98..2d3c1d3 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.AddSone.Name=Add Sone
 Navigation.Menu.Item.AddSone.Tooltip=Add a Sone by Freenet URI
+Navigation.Menu.Item.KnownSones.Name=Known Sones
+Navigation.Menu.Item.KnownSones.Tooltip=Shows all known Sones
 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
@@ -61,6 +63,10 @@ Page.AddSone.Text.ReturnToIndex=Or {link}return to the index{/link}.
 Page.AddSone.Text.AddAnotherSone=Or you can add another Sone by entering it’s Freenet URI below:
 Page.AddSone.Button.AddSone=Add Sone
 
+Page.KnownSones.Title=Known Sones - Sone
+Page.KnownSones.Page.Title=Known Sones
+Page.KnownSones.Text.NoKnownSones=There are currently no known Sones.
+
 Page.EditProfile.Title=Edit Profile - Sone
 Page.EditProfile.Page.Title=Edit Profile
 Page.EditProfile.Page.Description=On this page you can enter your profile data.
diff --git a/src/main/resources/templates/knownSones.html b/src/main/resources/templates/knownSones.html
new file mode 100644 (file)
index 0000000..2ff7b82
--- /dev/null
@@ -0,0 +1,13 @@
+<div id="sone">
+
+       <h1><%= Page.KnownSones.Page.Title|l10n|html></h1>
+
+       <div id="known-sones">
+               <%foreach knownSones sone>
+                       <div><a href="viewSone.html?sone=<% sone.id>"><% sone.niceName|html></a> (<% sone.requestUri|html>)</div>
+               <%foreachelse>
+                       <div><%= Page.KnownSones.Text.NoKnownSones|l10n|html></div>
+               <%/foreach>
+       </div>
+
+</div>