user profile, help wiki

This commit is contained in:
Peter Hormanns 2016-06-27 16:02:10 +02:00
parent 97d61727e0
commit 51a4a6acf3
16 changed files with 180 additions and 27 deletions

View File

@ -60,7 +60,7 @@ public class GenericFormWindow extends Window implements IHSWindow {
@Override
public Map<String, Object> getFormData() {
Map<String, Object> formData = new HashMap<String, Object>();
final Map<String, Object> formData = new HashMap<String, Object>();
final Set<String> keySet = inputFields.keySet();
for (String key : keySet) {
final IHSEditor ihsEditor = inputFields.get(key);

View File

@ -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;

View File

@ -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);

View File

@ -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;
@ -57,6 +58,11 @@ public class HSTab extends CustomComponent {
setCompositionRoot(layout);
}
public String getModule()
{
return module;
}
public void fillTable()
{
grid.removeAllItems();

View File

@ -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,6 +38,8 @@ public class HelpWindow extends Window {
}
});
subContent.addComponent(ok);
subContent.setExpandRatio(helpContent, 1.0f);
subContent.setExpandRatio(ok, 0.0f);
setContent(subContent);
}

View File

@ -2,6 +2,8 @@ package de.hsadmin.web;
import java.util.Map;
import com.vaadin.server.ErrorMessage;
public interface IHSWindow {
public void setFormData(Map<String, Object> value, Map<String, String> selector);
@ -14,4 +16,6 @@ public interface IHSWindow {
public boolean isValid();
public void setComponentError(ErrorMessage componentError);
}

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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<String, String> where = new HashMap<String, String>();
where.put("name", session.getUser());
final Window window = new UserProfileWindow(session, where);
if (window != null) {
getUI().addWindow(window);
}
}
}
}

View File

@ -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);

View File

@ -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)) {

View File

@ -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<String, String> whereContext = new HashMap<>();
whereContext.put(parent.getSelectPropertyName(), parent.getSelectPropertyValue().toString());

View File

@ -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<String, IHSEditor> inputFields;
private Map<String, String> uniqueRecordSelect;
public UserProfileWindow(final HSAdminSession session, final Map<String, String> whereContext)
{
super(I18N.getText("edit") + " " + I18N.getText("user"));
center();
setModal(true);
setWidth("640px");
inputFields = new HashMap<String, IHSEditor>();
contentForm = new FormLayout();
contentForm.setMargin(true);
final Iterator<PropertyInfo> iterator = session.getModulesManager().module("user").properties();
final Collection<String> 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<Map<String,Object>> 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<String, Object> valuesMap, final Map<String, String> uniqueWhereSelector) {
this.uniqueRecordSelect = uniqueWhereSelector;
final Set<String> keySet = inputFields.keySet();
for (final String key : keySet) {
inputFields.get(key).setValues(valuesMap);
}
}
@Override
public Map<String, Object> getFormData() {
final Map<String, Object> formData = new HashMap<String, Object>();
final Set<String> 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<String, String> getUniqueWhereSelector() {
return uniqueRecordSelect;
}
@Override
public void reload() {
// TODO Auto-generated method stub
}
}

View File

@ -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

View File

@ -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

View File

@ -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