From 51a4a6acf3b936ce3940bc9dd6823e472d848c54 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 27 Jun 2016 16:02:10 +0200 Subject: [PATCH] user profile, help wiki --- .../de/hsadmin/web/GenericFormWindow.java | 2 +- .../main/java/de/hsadmin/web/HSAdminUI.java | 5 +- .../java/de/hsadmin/web/HSConfirmBox.java | 2 +- web/src/main/java/de/hsadmin/web/HSTab.java | 8 +- .../main/java/de/hsadmin/web/HelpWindow.java | 24 ++-- .../main/java/de/hsadmin/web/IHSWindow.java | 4 + .../main/java/de/hsadmin/web/LoginWindow.java | 2 +- .../main/java/de/hsadmin/web/MainPanel.java | 15 +-- .../main/java/de/hsadmin/web/MainToolbar.java | 26 ++++- .../main/java/de/hsadmin/web/MainWindow.java | 2 +- .../java/de/hsadmin/web/PanelToolbar.java | 2 +- .../java/de/hsadmin/web/SubWindowFactory.java | 4 +- .../de/hsadmin/web/UserProfileWindow.java | 106 ++++++++++++++++++ .../resources/de/hsadmin/web/main.properties | 1 + .../de/hsadmin/web/main_de.properties | 3 +- .../de/hsadmin/web/main_es.properties | 1 + 16 files changed, 180 insertions(+), 27 deletions(-) create mode 100644 web/src/main/java/de/hsadmin/web/UserProfileWindow.java diff --git a/web/src/main/java/de/hsadmin/web/GenericFormWindow.java b/web/src/main/java/de/hsadmin/web/GenericFormWindow.java index 14b5062..bd95b01 100644 --- a/web/src/main/java/de/hsadmin/web/GenericFormWindow.java +++ b/web/src/main/java/de/hsadmin/web/GenericFormWindow.java @@ -60,7 +60,7 @@ public class GenericFormWindow extends Window implements IHSWindow { @Override public Map getFormData() { - Map formData = new HashMap(); + final Map formData = new HashMap(); final Set keySet = inputFields.keySet(); for (String key : keySet) { final IHSEditor ihsEditor = inputFields.get(key); diff --git a/web/src/main/java/de/hsadmin/web/HSAdminUI.java b/web/src/main/java/de/hsadmin/web/HSAdminUI.java index 3202f71..eba84b1 100644 --- a/web/src/main/java/de/hsadmin/web/HSAdminUI.java +++ b/web/src/main/java/de/hsadmin/web/HSAdminUI.java @@ -9,11 +9,12 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinServlet; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; import de.hsadmin.model.TicketService; @Title("HSAdmin Web") -@Theme("valo") +@Theme(ValoTheme.THEME_NAME) public class HSAdminUI extends UI { private static final long serialVersionUID = 1L; @@ -44,4 +45,4 @@ public class HSAdminUI extends UI { public void setGrantingTicket(String grantingTicket, String username) { layout.addComponent(new MainWindow(ticketService, grantingTicket, username)); } -} \ No newline at end of file +} diff --git a/web/src/main/java/de/hsadmin/web/HSConfirmBox.java b/web/src/main/java/de/hsadmin/web/HSConfirmBox.java index a99b648..813a309 100644 --- a/web/src/main/java/de/hsadmin/web/HSConfirmBox.java +++ b/web/src/main/java/de/hsadmin/web/HSConfirmBox.java @@ -25,7 +25,7 @@ public class HSConfirmBox extends HorizontalLayout { private Button okButton, cancelButton; - public HSConfirmBox(final GenericFormWindow parent, final String module, final String action, final HSAdminSession session) { + public HSConfirmBox(final IHSWindow parent, final String module, final String action, final HSAdminSession session) { okButton = new Button("OK"); okButton.setStyleName(ValoTheme.BUTTON_PRIMARY); okButton.setClickShortcut(KeyCode.ENTER); diff --git a/web/src/main/java/de/hsadmin/web/HSTab.java b/web/src/main/java/de/hsadmin/web/HSTab.java index 6a8fe1a..0e4bca4 100644 --- a/web/src/main/java/de/hsadmin/web/HSTab.java +++ b/web/src/main/java/de/hsadmin/web/HSTab.java @@ -37,7 +37,8 @@ public class HSTab extends CustomComponent { private Table grid; - public HSTab(final String source, final HSAdminSession session, final String selectPropertyName, final Object selectPropertyValue, final String rowIdPropertyName) { + public HSTab(final String source, final HSAdminSession session, final String selectPropertyName, final Object selectPropertyValue, final String rowIdPropertyName) + { super(); setSizeFull(); this.module = source; @@ -56,6 +57,11 @@ public class HSTab extends CustomComponent { dataTable.setHeight("100%"); setCompositionRoot(layout); } + + public String getModule() + { + return module; + } public void fillTable() { diff --git a/web/src/main/java/de/hsadmin/web/HelpWindow.java b/web/src/main/java/de/hsadmin/web/HelpWindow.java index fd60faa..6d0ad64 100644 --- a/web/src/main/java/de/hsadmin/web/HelpWindow.java +++ b/web/src/main/java/de/hsadmin/web/HelpWindow.java @@ -1,9 +1,11 @@ package de.hsadmin.web; +import com.vaadin.server.ExternalResource; +import com.vaadin.ui.BrowserFrame; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Label; +import com.vaadin.ui.Component; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; @@ -11,19 +13,23 @@ public class HelpWindow extends Window { private static final long serialVersionUID = 1L; - private static final String HELP_HTML_SNIPPET = "Contact us in case of further questions"; - public HelpWindow() { + public HelpWindow(final String helpTopic) { // Create a sub-window and set the content super("Help Window"); + setWidth("80%"); + setHeight("80%"); // Center it in the browser window center(); - VerticalLayout subContent = new VerticalLayout(); + final VerticalLayout subContent = new VerticalLayout(); subContent.setMargin(true); - - subContent.addComponent(new Label(HELP_HTML_SNIPPET)); - Button ok = new Button("OK"); + subContent.setSizeFull(); + final String helpBaseURL = I18N.getText("help.baseurl"); + final Component helpContent = new BrowserFrame("Help Window", new ExternalResource(helpBaseURL + helpTopic)); + helpContent.setSizeFull(); + subContent.addComponent(helpContent); + final Button ok = new Button("OK"); ok.addClickListener(new ClickListener() { private static final long serialVersionUID = -6121701552072481416L; @@ -32,7 +38,9 @@ public class HelpWindow extends Window { } }); subContent.addComponent(ok); + subContent.setExpandRatio(helpContent, 1.0f); + subContent.setExpandRatio(ok, 0.0f); setContent(subContent); } -} \ No newline at end of file +} diff --git a/web/src/main/java/de/hsadmin/web/IHSWindow.java b/web/src/main/java/de/hsadmin/web/IHSWindow.java index 810048e..8619312 100644 --- a/web/src/main/java/de/hsadmin/web/IHSWindow.java +++ b/web/src/main/java/de/hsadmin/web/IHSWindow.java @@ -2,6 +2,8 @@ package de.hsadmin.web; import java.util.Map; +import com.vaadin.server.ErrorMessage; + public interface IHSWindow { public void setFormData(Map value, Map selector); @@ -14,4 +16,6 @@ public interface IHSWindow { public boolean isValid(); + public void setComponentError(ErrorMessage componentError); + } diff --git a/web/src/main/java/de/hsadmin/web/LoginWindow.java b/web/src/main/java/de/hsadmin/web/LoginWindow.java index 1241300..f97ab51 100644 --- a/web/src/main/java/de/hsadmin/web/LoginWindow.java +++ b/web/src/main/java/de/hsadmin/web/LoginWindow.java @@ -99,7 +99,7 @@ public class LoginWindow extends Window { } }); subContent.addComponent(okButton); - final Link linkToOld = new Link(I18N.getText("main.panel.link_to_old"), new ExternalResource("https://admin.hostsharing.net/")); + final Link linkToOld = new Link(I18N.getText("main.panel.link_to_old"), new ExternalResource("https://admin.hostsharing.net/hsarweb")); subContent.addComponent(linkToOld); setContent(subContent); diff --git a/web/src/main/java/de/hsadmin/web/MainPanel.java b/web/src/main/java/de/hsadmin/web/MainPanel.java index 51a16e6..a7fa611 100644 --- a/web/src/main/java/de/hsadmin/web/MainPanel.java +++ b/web/src/main/java/de/hsadmin/web/MainPanel.java @@ -1,18 +1,19 @@ package de.hsadmin.web; +import com.vaadin.server.ExternalResource; +import com.vaadin.ui.BrowserFrame; +import com.vaadin.ui.Component; import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.Label; -import com.vaadin.ui.Panel; public class MainPanel extends CustomComponent{ private static final long serialVersionUID = -1085100738394404620L; public MainPanel() { - final Label dialog = new Label(); - final Panel panel = new Panel(I18N.getText("main.panel.title")); - dialog.setValue(I18N.getText("main.panel.text")); - panel.setContent(dialog); - setCompositionRoot(panel); + final String helpBaseURL = I18N.getText("help.baseurl"); + final Component helpContent = new BrowserFrame(I18N.getText("main.panel.title"), new ExternalResource(helpBaseURL + "hsadmin")); + helpContent.setSizeFull(); + setCompositionRoot(helpContent); + setSizeFull(); } } diff --git a/web/src/main/java/de/hsadmin/web/MainToolbar.java b/web/src/main/java/de/hsadmin/web/MainToolbar.java index dedcd81..85458f5 100644 --- a/web/src/main/java/de/hsadmin/web/MainToolbar.java +++ b/web/src/main/java/de/hsadmin/web/MainToolbar.java @@ -1,5 +1,7 @@ package de.hsadmin.web; +import java.util.HashMap; + import com.vaadin.server.ThemeResource; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinService; @@ -11,12 +13,19 @@ import com.vaadin.ui.CustomComponent; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Panel; import com.vaadin.ui.UI; +import com.vaadin.ui.Window; +import com.vaadin.ui.themes.ValoTheme; + +import de.hsadmin.rpc.HSAdminSession; public class MainToolbar extends CustomComponent implements ClickListener { private static final long serialVersionUID = 1L; - public MainToolbar() { + private final HSAdminSession session; + + public MainToolbar(final HSAdminSession session) { + this.session = session; final Panel toolbar = new Panel(); toolbar.setSizeFull(); final HorizontalLayout layout = new HorizontalLayout(); @@ -25,6 +34,13 @@ public class MainToolbar extends CustomComponent implements ClickListener { whitespace.setStyleName("borderless"); layout.addComponent(whitespace); layout.setExpandRatio(whitespace, 1.0f); + final String login = session.getUser(); + final Button profileBtn = new Button(login); + profileBtn.setStyleName(ValoTheme.BUTTON_LINK); + layout.addComponent(profileBtn); + layout.setExpandRatio(profileBtn, 0.0f); + profileBtn.setId("profile-btn"); + profileBtn.addClickListener(this); final Button logoutBtn = createButton("logout", "x"); layout.addComponent(logoutBtn); layout.setExpandRatio(logoutBtn, 0.0f); @@ -51,6 +67,14 @@ public class MainToolbar extends CustomComponent implements ClickListener { vaadinUI.getSession().close(); vaadinUI.getPage().setLocation(currentRequest.getContextPath()); } + if ("profile-btn".equals(btnId)) { + final HashMap where = new HashMap(); + where.put("name", session.getUser()); + final Window window = new UserProfileWindow(session, where); + if (window != null) { + getUI().addWindow(window); + } + } } } diff --git a/web/src/main/java/de/hsadmin/web/MainWindow.java b/web/src/main/java/de/hsadmin/web/MainWindow.java index 2adefe1..30cbc9a 100644 --- a/web/src/main/java/de/hsadmin/web/MainWindow.java +++ b/web/src/main/java/de/hsadmin/web/MainWindow.java @@ -52,7 +52,7 @@ public class MainWindow extends CustomComponent implements HSAdminSession { mainPanel.setContent(vl); try { - final MainToolbar mainToolbar = new MainToolbar(); + final MainToolbar mainToolbar = new MainToolbar(this); vl.addComponent(mainToolbar); vl.setExpandRatio(mainToolbar, 0.0f); final ModulesManagerFactory modulesManagerFactory = new ModulesManagerFactory(grantingTicket, username); diff --git a/web/src/main/java/de/hsadmin/web/PanelToolbar.java b/web/src/main/java/de/hsadmin/web/PanelToolbar.java index 1fdc5eb..9fb9645 100644 --- a/web/src/main/java/de/hsadmin/web/PanelToolbar.java +++ b/web/src/main/java/de/hsadmin/web/PanelToolbar.java @@ -67,7 +67,7 @@ public class PanelToolbar extends HorizontalLayout implements ClickListener { } @Override - public void buttonClick(ClickEvent event) + public void buttonClick(final ClickEvent event) { String action = null; if (event.getButton().equals(newBtn)) { diff --git a/web/src/main/java/de/hsadmin/web/SubWindowFactory.java b/web/src/main/java/de/hsadmin/web/SubWindowFactory.java index cd03f37..89092ae 100644 --- a/web/src/main/java/de/hsadmin/web/SubWindowFactory.java +++ b/web/src/main/java/de/hsadmin/web/SubWindowFactory.java @@ -10,13 +10,13 @@ import de.hsadmin.rpc.HSAdminSession; public class SubWindowFactory extends AbstractWindowFactory { @Override - public Window getSubWindow(HSTab parent, String type, String action, HSAdminSession session) + public Window getSubWindow(final HSTab parent, final String type, final String action, final HSAdminSession session) { if (type == null) { return null; } if (action.equalsIgnoreCase("help")) { - return new HelpWindow(); + return new HelpWindow(parent.getModule()); } final Map whereContext = new HashMap<>(); whereContext.put(parent.getSelectPropertyName(), parent.getSelectPropertyValue().toString()); diff --git a/web/src/main/java/de/hsadmin/web/UserProfileWindow.java b/web/src/main/java/de/hsadmin/web/UserProfileWindow.java new file mode 100644 index 0000000..cec28f2 --- /dev/null +++ b/web/src/main/java/de/hsadmin/web/UserProfileWindow.java @@ -0,0 +1,106 @@ +package de.hsadmin.web; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.xmlrpc.XmlRpcException; + +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.Window; + +import de.hsadmin.rpc.HSAdminSession; +import de.hsadmin.rpc.PropertyInfo; +import de.hsadmin.rpc.RpcException; + +public class UserProfileWindow extends Window implements IHSWindow { + + private static final long serialVersionUID = 1L; + + final private FormLayout contentForm; + final private Map inputFields; + + private Map uniqueRecordSelect; + + public UserProfileWindow(final HSAdminSession session, final Map whereContext) + { + super(I18N.getText("edit") + " " + I18N.getText("user")); + center(); + setModal(true); + setWidth("640px"); + inputFields = new HashMap(); + contentForm = new FormLayout(); + contentForm.setMargin(true); + + final Iterator iterator = session.getModulesManager().module("user").properties(); + final Collection visibleFields = Arrays.asList(new String[] { "name", "password", "pac", "comment", "shell", "homedir" }); + while (iterator.hasNext()) { // "name", "password", "pac", "comment", "shell", "homedir" + final PropertyInfo propertyInfo = iterator.next(); + final String inputName = propertyInfo.getName(); + if (visibleFields.contains(inputName)) { + final IEditorFactory editorFactory = FactoryProducer.getEditorFactory("user"); + final IHSEditor field = editorFactory.getEditor(inputName.equals("password") ? "edit" : "view", propertyInfo, session, whereContext); + inputFields.put(inputName, field); + contentForm.addComponent(field); + } + } + contentForm.addComponent(new HSConfirmBox(this, "user", "edit", session)); + try { + final List> list = session.getModulesManager().proxy("user").search(session.getUser(), session.getTicketService().getServiceTicket(session.getGrantingTicket()), whereContext); + if (list.size() == 1) { + setFormData(list.get(0), whereContext); + setContent(contentForm); + } + } catch (XmlRpcException | RpcException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public void setFormData(final Map valuesMap, final Map uniqueWhereSelector) { + this.uniqueRecordSelect = uniqueWhereSelector; + final Set keySet = inputFields.keySet(); + for (final String key : keySet) { + inputFields.get(key).setValues(valuesMap); + } + } + + @Override + public Map getFormData() { + final Map formData = new HashMap(); + final Set keySet = inputFields.keySet(); + for (String key : keySet) { + final IHSEditor ihsEditor = inputFields.get(key); + if (ihsEditor.isEnabled()) { + formData.put(key, ihsEditor.getValue()); + } + } + return formData; + } + + @Override + public boolean isValid() { + boolean valid = true; + for (IHSEditor editor : inputFields.values()) { + valid &= editor.isValid(); + } + return valid; + } + + @Override + public Map getUniqueWhereSelector() { + return uniqueRecordSelect; + } + + @Override + public void reload() { + // TODO Auto-generated method stub + + } + +} diff --git a/web/src/main/resources/de/hsadmin/web/main.properties b/web/src/main/resources/de/hsadmin/web/main.properties index 4b9fa6a..be469bf 100644 --- a/web/src/main/resources/de/hsadmin/web/main.properties +++ b/web/src/main/resources/de/hsadmin/web/main.properties @@ -1,6 +1,7 @@ main.panel.title=Welcome main.panel.text=to the hostsharing admin application main.panel.link_to_old=Link to the old HSAdmin-UI +help.baseurl=https://admin.hostsharing.net/de/Wiki.jsp?skin=reader&page= user=User domain=Domain emailaddress=Email Address diff --git a/web/src/main/resources/de/hsadmin/web/main_de.properties b/web/src/main/resources/de/hsadmin/web/main_de.properties index 566979b..8ed70ac 100644 --- a/web/src/main/resources/de/hsadmin/web/main_de.properties +++ b/web/src/main/resources/de/hsadmin/web/main_de.properties @@ -1,6 +1,7 @@ main.panel.title=Willkommen main.panel.text=in der Hostsharing Administration main.panel.link_to_old=Schnell zum alten HSAdmin-UI +help.baseurl=https://admin.hostsharing.net/de/Wiki.jsp?skin=reader&page= user=User/Postfach domain=Domain emailaddress=EMail-Adresse @@ -48,7 +49,7 @@ mysqldb.encoding=Zeichen-Kodierung postgresqluser.name=PostgreSQL User postgresqluser.instance=Datenbank-System postgresqluser.pac=Web-Paket -postgresqldb.name=PostgreQL Datenbank +postgresqldb.name=PostgreSQL Datenbank postgresqldb.instance=Datenbank-System postgresqldb.owner=Postgres User postgresqldb.pac=Web-Paket diff --git a/web/src/main/resources/de/hsadmin/web/main_es.properties b/web/src/main/resources/de/hsadmin/web/main_es.properties index 008f2fd..9cd034d 100644 --- a/web/src/main/resources/de/hsadmin/web/main_es.properties +++ b/web/src/main/resources/de/hsadmin/web/main_es.properties @@ -1,6 +1,7 @@ user=Usuario domain=Dominio emailaddress=Dirección de correo +help.baseurl=https://admin.hostsharing.net/de/Wiki.jsp?skin=reader&page= pac=Paquete emailalias=Email Alias mysqluser=Usuario MySql