Commit 2c2d1a61 authored by michael.simon's avatar michael.simon
Browse files

List and show admin users

parent 76bd27fe
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import org.primefaces.model.LazyDataModel;
import edu.kit.scc.webreg.entity.AdminUserEntity;
import edu.kit.scc.webreg.model.GenericLazyDataModelImpl;
import edu.kit.scc.webreg.service.AdminUserService;
@ManagedBean
@ViewScoped
public class ListAdminUserBean implements Serializable {
private static final long serialVersionUID = 1L;
private LazyDataModel<AdminUserEntity> list;
@Inject
private AdminUserService service;
public void preRenderView(ComponentSystemEvent ev) {
if (list == null) {
list = new GenericLazyDataModelImpl<AdminUserEntity, AdminUserService, Long>(service);
}
}
public LazyDataModel<AdminUserEntity> getUserEntityList() {
return list;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;
import edu.kit.scc.webreg.entity.AdminUserEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.service.AdminUserService;
import edu.kit.scc.webreg.service.RoleService;
@ManagedBean
@ViewScoped
public class ShowAdminUserBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private AdminUserService adminUserService;
@Inject
private RoleService roleService;
private AdminUserEntity entity;
private DualListModel<RoleEntity> roleList;
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = adminUserService.findByIdWithAttrs(id, "roles");
roleList = new DualListModel<RoleEntity>();
List<RoleEntity> targetList = new ArrayList<RoleEntity>(entity.getRoles());
List<RoleEntity> sourceList = roleService.findAll();
sourceList.removeAll(targetList);
roleList.setSource(sourceList);
roleList.setTarget(targetList);
}
}
public void onTransfer(TransferEvent event) {
entity = adminUserService.findByIdWithAttrs(id, "roles");
if (event.isAdd()) {
for (Object o : event.getItems()) {
RoleEntity role = (RoleEntity) o;
entity.getRoles().add(role);
entity = adminUserService.save(entity);
}
}
else {
for (Object o : event.getItems()) {
RoleEntity role = (RoleEntity) o;
entity.getRoles().remove(role);
entity = adminUserService.save(entity);
}
}
entity = adminUserService.findByIdWithAttrs(id, "roles");
}
public AdminUserEntity getEntity() {
return entity;
}
public void setEntity(AdminUserEntity entity) {
this.entity = entity;
}
public DualListModel<RoleEntity> getRoleList() {
return roleList;
}
public void setRoleList(DualListModel<RoleEntity> roleList) {
this.roleList = roleList;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:bw="http://www.scc.kit.edu/bwfacelets"
xmlns:p="http://primefaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<head>
<title></title>
</head>
<body>
<f:view>
<f:metadata>
<f:event type="javax.faces.event.PreRenderViewEvent"
listener="#{listAdminUserBean.preRenderView}" />
</f:metadata>
<ui:composition template="/template/default-admin.xhtml">
<ui:param name="title" value="#{messages.title}"/>
<ui:define name="content">
<h:form id="form">
<p:dataTable id="dataTable" var="user" value="#{listAdminUserBean.userEntityList}" paginator="true"
lazy="true" rows="15">
<p:column sortBy="#{user.id}" style="width:30px;">
<f:facet name="header">
<h:outputText value="#{messages.id}" />
</f:facet>
<h:outputText value="#{user.id}" />
</p:column>
<p:column sortBy="#{user.username}" filterBy="#{user.username}">
<f:facet name="header">
<h:outputText value="#{messages.name}" />
</f:facet>
<h:link outcome="show-admin-user.xhtml" value="#{user.username != null ? user.username : 'null'}">
<f:param name="id" value="#{user.id}"/>
</h:link>
</p:column>
<p:column sortBy="#{user.createdAt}">
<f:facet name="header">
<h:outputText value="#{messages.created_at}" />
</f:facet>
<h:outputText value="#{of:formatDate(user.createdAt, 'dd.MM.yyyy HH:mm')}" />
</p:column>
<p:column sortBy="#{user.updatedAt}">
<f:facet name="header">
<h:outputText value="#{messages.updated_at}" />
</f:facet>
<h:outputText value="#{of:formatDate(user.updatedAt, 'dd.MM.yyyy HH:mm')}" />
</p:column>
<p:column sortBy="#{user.version}" style="width:50px;">
<f:facet name="header">
<h:outputText value="#{messages.version}" />
</f:facet>
<h:outputText value="#{user.version}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<head>
<title></title>
</head>
<body>
<f:view>
<f:metadata>
<f:viewParam name="id" value="#{showAdminUserBean.id}"/>
<f:event type="javax.faces.event.PreRenderViewEvent"
listener="#{showAdminUserBean.preRenderView}" />
</f:metadata>
<ui:composition template="/template/default-admin.xhtml">
<ui:param name="title" value="#{messages.title}"/>
<ui:define name="content">
<h:form id="form">
<h2><h:outputText value="#{messages.user}: #{showAdminUserBean.entity.username}"/></h2>
<p:messages id="messageBox" showDetail="true" />
<div id="panelInline">
<p:panel header="#{messages.user_properties}">
<p:panelGrid id="baseData" columns="2">
<h:outputText value="#{messages.id}:"/>
<h:outputText value="#{showAdminUserBean.entity.id}"/>
<h:outputText value="#{messages.given_name}:"/>
<h:outputText value="#{showAdminUserBean.entity.username}"/>
<h:outputText value="#{messages.created_at}:"/>
<h:outputText value="#{of:formatDate(showAdminUserBean.entity.createdAt, 'dd.MM.yyyy HH:mm')}"/>
<h:outputText value="#{messages.updated_at}:"/>
<h:outputText value="#{of:formatDate(showAdminUserBean.entity.updatedAt, 'dd.MM.yyyy HH:mm')}"/>
<h:outputText value="#{messages.version}:"/>
<h:outputText value="#{showAdminUserBean.entity.version}"/>
</p:panelGrid>
</p:panel>
</div>
<div id="panelInline">
<p:panel id="rolePanel" header="#{messages.roles}">
<p:pickList var="role" value="#{showAdminUserBean.roleList}" itemLabel="#{role.name}"
itemValue="#{role}" converter="#{roleConverter}"
showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains">
<p:ajax event="transfer" listener="#{showAdminUserBean.onTransfer}" />
</p:pickList>
</p:panel>
</div>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
......@@ -36,6 +36,9 @@
<li><span class="ui-icon ui-icon-person" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/admin/user/list-users.xhtml" value="#{messages.users}" />
</li>
<li><span class="ui-icon ui-icon-person" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/admin/user/list-admin-users.xhtml" value="#{messages.admin_users}" />
</li>
<li><span class="ui-icon ui-icon-locked" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/admin/role/list-roles.xhtml" value="#{messages.roles}" />
</li>
......
......@@ -35,6 +35,9 @@
<li><span class="ui-icon ui-icon-person" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/admin/user/list-users.xhtml" value="#{messages.users}" />
</li>
<li><span class="ui-icon ui-icon-person" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/admin/user/list-admin-users.xhtml" value="#{messages.admin_users}" />
</li>
<li><span class="ui-icon ui-icon-locked" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/admin/role/list-roles.xhtml" value="#{messages.roles}" />
</li>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment