Group management implemented on the admin page.
authorErik Brakkee <erik@brakkee.org>
Sun, 29 Sep 2013 19:14:25 +0000 (21:14 +0200)
committerErik Brakkee <erik@brakkee.org>
Sun, 29 Sep 2013 19:14:25 +0000 (21:14 +0200)
src/main/java/org/wamblee/photos/wicket/AdminPage.html
src/main/java/org/wamblee/photos/wicket/AdminPage.java
src/main/java/org/wamblee/photos/wicket/EditProfilePage.java
src/main/java/org/wamblee/photos/wicket/photos.css

index 173e1a2a350fcf3ac86934fba66d2de54eefc7cc..4a1ce899c2e45f6f9d8937f416f30aa3d423f33e 100644 (file)
 
 <wicket:extend>
 
+
+    <div id="admin">
+        <h1>Groups</h1>
+
+
+        <table>
+            <tr>
+                <th>Group</th>
+                <th>Action</th>
+            </tr>
+            <tr wicket:id="groupDelete">
+                <td><span wicket:id="groupName">groupname</span></td>
+                <td><a href="#" wicket:id="groupDelete">delete</a></td>
+            </tr>
+        </table>
+        <form method="post" wicket:id="groupCreate">
+            <table>
+                <tr>
+                    <td><input type="text" wicket:id="groupName" value=""/></td>
+                    <td><input type="submit" value="Create Group"/></td>
+                </tr>
+            </table>
+        </form>
+
+    </div>
 </wicket:extend>
 
 </body>
index 30737d9e7f029fa67108dccd1538e09174424675..6ef38c6c07016a15a0f79cdb87767a4d45fcc880 100644 (file)
  */
 package org.wamblee.photos.wicket;
 
+import java.util.List;
 import java.util.logging.Logger;
+import javax.inject.Inject;
 
 import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.model.Model;
+import org.wamblee.security.authentication.UserAdministration;
+import org.wamblee.security.authentication.UserMgtException;
 
 /**
  * Homepage
@@ -28,6 +39,11 @@ public class AdminPage extends BasePage {
 
     private static final long serialVersionUID = 1L;
 
+    @Inject
+    private transient UserAdministration _userAdmin;
+
+    private TextField _groupName;
+
     /**
      * Constructor that is invoked when page is invoked without a session.
      *
@@ -35,6 +51,58 @@ public class AdminPage extends BasePage {
      */
     public AdminPage(final PageParameters parameters) throws Exception {
         super();
+
+        RepeatingView groupDelete = new RepeatingView("groupDelete") {
+            @Override
+            protected void onPopulate() {
+                removeAll();
+                List<String> groups = _userAdmin.getGroups();
+                for (final String group : groups) {
+                    WebMarkupContainer container = new WebMarkupContainer(newChildId());
+                    add(container);
+                    container.add(new Label("groupName", group));
+                    container.add(new Link("groupDelete") {
+                        @Override
+                        public void onClick() {
+                            try {
+                                _userAdmin.removeGroup(group);
+                                info("Group '" + group + "' removed");
+                            }
+                            catch (UserMgtException e) {
+                                error("Could not remove group '" + group + "'");
+                            }
+                        }
+
+                        @Override
+                        public boolean isVisible() {
+                            return _userAdmin.getUsers(group).isEmpty();
+                        }
+                    });
+                }
+            }
+        };
+        add(groupDelete);
+
+        Form groupCreate = new Form("groupCreate") {
+            @Override
+            protected void onSubmit() {
+                String name = _groupName.getValue();
+                if (name == null || name.length() == 0) {
+                    return;
+                }
+                try {
+                    _userAdmin.createGroup(name);
+                    _groupName.setModel(new Model(""));
+                    info("Group '" + name + "' created");
+                }
+                catch (UserMgtException e) {
+                    error("Group '" + name + "' could not be created");
+                }
+            }
+        };
+        add(groupCreate);
+        _groupName = new TextField("groupName", new Model(""));
+        groupCreate.add(_groupName);
     }
 
     @Override
index 967bfa630f896c05081d0568b8107bd7069a8a6f..9351cd4441427df6de9fa404d76352befdde5b45 100644 (file)
@@ -35,10 +35,10 @@ public class EditProfilePage extends BasePage {
     private static final long serialVersionUID = 1L;
 
     @Inject
-    private User user;
+    private transient User user;
 
     @Inject
-    private UserAdministration userAdmin;
+    private transient UserAdministration userAdmin;
 
     private PasswordTextField _currentPassword;
     private PasswordTextField _password1;
index a99f31bc8c6327ffb97b1855c7d2ea590e5d5815..9dbf0e67c52088484803b5d6658807f2ce88c805 100644 (file)
@@ -4,7 +4,11 @@ body {
 }
 
 h1 {
-font-size: 1.3em;
+  font-size: 1.3em;
+}
+
+h2 {
+   font-size: 1.1em;
 }
 
 /* menu styling */
@@ -105,7 +109,6 @@ ul.feedbackPanel {
 #photoentry {
     padding: 0.2em;
     border: 1px;
-    border: 1px;
     border-style: solid;
     border-bottom-color: gray;
 }
@@ -114,4 +117,16 @@ ul.feedbackPanel {
     display: block;
 }
 
+
+#admin table {
+    font-size: small;
+    text-align: left;
+    border-collapse: collapse;
+    border-spacing: 0px;
+}
+
+#admin table tr td {
+    padding: 0.2em;
+    border: 1px;
+    border-style: solid;
 }
\ No newline at end of file