Show enabled and disabled identities on the index page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 14:36:43 +0000 (16:36 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 14:38:36 +0000 (16:38 +0200)
src/main/java/net/pterodactylus/wotns/ui/web/IndexPage.java
src/main/resources/templates/index.html

index 933f9a6..172cfa8 100644 (file)
 
 package net.pterodactylus.wotns.ui.web;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.wotns.freenet.wot.OwnIdentity;
 import net.pterodactylus.wotns.web.FreenetRequest;
 
 /**
@@ -48,6 +53,20 @@ public class IndexPage extends BasicPage {
        @Override
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
+
+               Set<OwnIdentity> ownIdentities = identityManager.getAllOwnIdentities();
+               List<OwnIdentity> enabledIdentities = new ArrayList<OwnIdentity>();
+               List<OwnIdentity> disabledIdentities = new ArrayList<OwnIdentity>();
+               for (OwnIdentity ownIdentity : ownIdentities) {
+                       if (ownIdentity.hasContext("WoTNS")) {
+                               enabledIdentities.add(ownIdentity);
+                       } else {
+                               disabledIdentities.add(ownIdentity);
+                       }
+               }
+               templateContext.set("enabledIdentities", enabledIdentities);
+               templateContext.set("disabledIdentities", disabledIdentities);
+
        }
 
 }
index a0c8bee..2da3f2d 100644 (file)
@@ -1,12 +1,26 @@
 <h1>WoTNS</h1>
 <p>Yay, Index!</p>
-<h1>Manage Names</h1>
-<form method="get" action="manage.html">
-       <select name="ownIdentity">
-               <option disabled="true">Choose identity…</option>
-               <%foreach ownIdentities ownIdentity>
-                       <option value="<%ownIdentity.id|html>"><%ownIdentity.nickname|html></option>
-               <%/foreach>
-       </select>
-       <button type="submit" name="manage">Manage</button>
-</form>
+
+<%foreach enabledIdentities identity>
+       <%first>
+               <h1>Enabled Identities</h1>
+       <%/first>
+       <form action="enableIdentity.html" method="post">
+               <input type="hidden" name="formPassword" value="<%formPassword|html>"/>
+               <input type="hidden" name="ownIdentity" value="<%identity.id|html>"/>
+               <a href="manage.html?ownIdentity=<%identity.id|html>"><%identity.nickname|html></a>
+               <button type="submit" name="disable">Disable</button>
+       </form>
+<%/foreach>
+
+<%foreach disabledIdentities identity>
+       <%first>
+               <h1>Disabled Identities</h1>
+       <%/first>
+       <form action="enableIdentity.html" method="post">
+               <input type="hidden" name="formPassword" value="<%formPassword|html>"/>
+               <input type="hidden" name="ownIdentity" value="<%identity.id|html>"/>
+               <%identity.nickname|html>
+               <button type="submit" name="enable">Enable</button>
+       </form>
+<%/foreach>