From acb0842f2c1a3fd90615c0d9766819b4133cb3fe Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sun, 29 Sep 2013 21:14:25 +0200 Subject: [PATCH] Group management implemented on the admin page. --- .../org/wamblee/photos/wicket/AdminPage.html | 25 +++++++ .../org/wamblee/photos/wicket/AdminPage.java | 68 +++++++++++++++++++ .../photos/wicket/EditProfilePage.java | 4 +- .../java/org/wamblee/photos/wicket/photos.css | 19 +++++- 4 files changed, 112 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/wamblee/photos/wicket/AdminPage.html b/src/main/java/org/wamblee/photos/wicket/AdminPage.html index 173e1a2..4a1ce89 100644 --- a/src/main/java/org/wamblee/photos/wicket/AdminPage.html +++ b/src/main/java/org/wamblee/photos/wicket/AdminPage.html @@ -10,6 +10,31 @@ + +
+

Groups

+ + + + + + + + + + + +
GroupAction
groupnamedelete
+
+ + + + + +
+
+ +
diff --git a/src/main/java/org/wamblee/photos/wicket/AdminPage.java b/src/main/java/org/wamblee/photos/wicket/AdminPage.java index 30737d9..6ef38c6 100644 --- a/src/main/java/org/wamblee/photos/wicket/AdminPage.java +++ b/src/main/java/org/wamblee/photos/wicket/AdminPage.java @@ -15,9 +15,20 @@ */ 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 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 diff --git a/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java b/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java index 967bfa6..9351cd4 100644 --- a/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java +++ b/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java @@ -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; diff --git a/src/main/java/org/wamblee/photos/wicket/photos.css b/src/main/java/org/wamblee/photos/wicket/photos.css index a99f31b..9dbf0e6 100644 --- a/src/main/java/org/wamblee/photos/wicket/photos.css +++ b/src/main/java/org/wamblee/photos/wicket/photos.css @@ -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 -- 2.31.1