All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.ikasan.dashboard.ui.administration.view.UserManagementView Maven / Gradle / Ivy
package org.ikasan.dashboard.ui.administration.view;
import com.vaadin.componentfactory.Tooltip;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.dialog.GeneratedVaadinDialog;
import com.vaadin.flow.component.grid.HeaderRow;
import com.vaadin.flow.component.grid.ItemDoubleClickEvent;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.data.provider.ConfigurableFilterDataProvider;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.data.renderer.TemplateRenderer;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.UIScope;
import org.ikasan.dashboard.ui.administration.component.NewUserDialog;
import org.ikasan.dashboard.ui.administration.component.UserManagementDialog;
import org.ikasan.dashboard.ui.util.*;
import org.ikasan.dashboard.ui.general.component.TooltipHelper;
import org.ikasan.dashboard.ui.layout.IkasanAppLayout;
import org.ikasan.security.model.User;
import org.ikasan.security.service.SecurityService;
import org.ikasan.security.service.UserService;
import org.ikasan.spec.systemevent.SystemEventService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.ikasan.dashboard.ui.general.component.FilteringGrid;
import org.ikasan.dashboard.ui.administration.filter.UserFilter;
import javax.annotation.Resource;
import java.util.List;
@Route(value = "userManagement", layout = IkasanAppLayout.class)
@UIScope
@Component
@PageTitle("Ikasan - User Management")
public class UserManagementView extends VerticalLayout implements BeforeEnterObserver
{
private Logger logger = LoggerFactory.getLogger(UserManagementView.class);
@Resource
private UserService userService;
@Resource
private SecurityService securityService;
@Resource
private SystemEventService systemEventService;
@Resource
private SystemEventLogger systemEventLogger;
@Resource
private DateFormatter dateFormatter;
private FilteringGrid userGrid;
private DataProvider dataProvider;
private ConfigurableFilterDataProvider filteredDataProvider;
private List users;
private UserFilter userFilter = new UserFilter();
private Tooltip newUserTooltip;
private Button addNewUserButton;
/**
* Constructor
*/
public UserManagementView()
{
super();
init();
}
protected void init()
{
this.setSizeFull();
this.setSpacing(true);
H2 userDirectoriesLabel = new H2(getTranslation("label.user-management", UI.getCurrent().getLocale(), null));
HorizontalLayout labelLayout = new HorizontalLayout();
labelLayout.setJustifyContentMode(JustifyContentMode.START);
labelLayout.setVerticalComponentAlignment(Alignment.CENTER, userDirectoriesLabel);
labelLayout.setWidth("100%");
labelLayout.add(userDirectoriesLabel);
this.addNewUserButton = new Button(VaadinIcon.PLUS.create());
this.addNewUserButton.addClickListener((ComponentEventListener>) buttonClickEvent -> {
NewUserDialog newUserDialog = new NewUserDialog(this.userService, this.systemEventLogger, this.securityService);
newUserDialog.open();
newUserDialog.addOpenedChangeListener((ComponentEventListener>) dialogOpenedChangeEvent ->
{
if(dialogOpenedChangeEvent.isOpened() == false)
{
this.updateUsers();
}
});
});
this.addNewUserButton.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.USER_ADMINISTRATION_WRITE,
SecurityConstants.USER_ADMINISTRATION_ADMIN, SecurityConstants.ALL_AUTHORITY));
this.newUserTooltip = TooltipHelper.getTooltipForComponentBottom(this.addNewUserButton, getTranslation("tooltip.add-new-user"
, UI.getCurrent().getLocale()));
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.setJustifyContentMode(JustifyContentMode.END);
buttonLayout.setMargin(true);
buttonLayout.setVerticalComponentAlignment(Alignment.CENTER, this.addNewUserButton);
buttonLayout.setWidth("100%");
buttonLayout.add(this.addNewUserButton, newUserTooltip);
HorizontalLayout wrapperLayout = new HorizontalLayout();
wrapperLayout.setWidth("100%");
wrapperLayout.add(labelLayout, buttonLayout);
add(wrapperLayout);
this.userGrid = new FilteringGrid<>(userFilter);
this.userGrid.setSizeFull();
this.userGrid.setClassName("my-grid");
this.userGrid.addColumn(User::getUsername)
.setKey("username")
.setHeader(getTranslation("table-header.username", UI.getCurrent().getLocale(), null))
.setSortable(true)
.setFlexGrow(1);
this.userGrid.addColumn(User::getFirstName)
.setKey("firstname")
.setHeader(getTranslation("table-header.firstname", UI.getCurrent().getLocale(), null))
.setSortable(true)
.setFlexGrow(1);
this.userGrid.addColumn(User::getSurname)
.setKey("surname")
.setHeader(getTranslation("table-header.surname", UI.getCurrent().getLocale(), null))
.setSortable(true)
.setFlexGrow(1);
this.userGrid.addColumn(User::getEmail).setKey("email")
.setHeader(getTranslation("table-header.email", UI.getCurrent().getLocale(), null))
.setFlexGrow(2)
.setSortable(true);
this.userGrid.addColumn(User::getDepartment)
.setKey("department").setHeader(getTranslation("table-header.department", UI.getCurrent().getLocale(), null))
.setSortable(true)
.setFlexGrow(1);
this.userGrid.addColumn(TemplateRenderer.of(
"[[item.date]]
")
.withProperty("date",
user -> this.dateFormatter.getFormattedDate(user.getPreviousAccessTimestamp())))
.setKey("lastaccess").setHeader(getTranslation("table-header.last-access", UI.getCurrent().getLocale(), null))
.setSortable(true)
.setWidth("90px");
HeaderRow hr = userGrid.appendHeaderRow();
this.userGrid.addGridFiltering(hr, userFilter::setUsernameFilter, "username");
this.userGrid.addGridFiltering(hr, userFilter::setNameFilter, "firstname");
this.userGrid.addGridFiltering(hr, userFilter::setLastNameFilter, "surname");
this.userGrid.addGridFiltering(hr, userFilter::setEmailFilter, "email");
this.userGrid.addGridFiltering(hr, userFilter::setDepartmentFilter, "department");
this.userGrid.addItemDoubleClickListener((ComponentEventListener>) userItemDoubleClickEvent ->
{
UserManagementDialog dialog = new UserManagementDialog(userItemDoubleClickEvent.getItem(), userService
, this.securityService, this.systemEventService, this.systemEventLogger);
dialog.open();
});
add(this.userGrid);
}
private void updateUsers()
{
this.users = this.userService.getUsers();
this.userGrid.setItems(users);
}
@Override
public void beforeEnter(BeforeEnterEvent beforeEnterEvent)
{
if(!ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.USER_ADMINISTRATION_ADMIN, SecurityConstants.USER_ADMINISTRATION_WRITE, SecurityConstants.USER_ADMINISTRATION_READ,
SecurityConstants.ALL_AUTHORITY)) {
DashboardContextNavigator.navigateToLandingPage();
return;
}
updateUsers();
}
@Override
protected void onAttach(AttachEvent attachEvent)
{
this.newUserTooltip.attachToComponent(this.addNewUserButton);
}
}