Search in sources :

Example 1 with CLOSE_CIRCLE

use of com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE in project furms by unity-idm.

the class UsersView method loadPageContent.

private void loadPageContent() {
    String projectId = getCurrentResourceId();
    project = projectService.findById(projectId).orElseThrow(() -> new IllegalStateException("Project not found: " + getCurrentResourceId()));
    currentUserId = authzService.getCurrentUserId();
    InviteUserComponent inviteUser = new InviteUserComponent(() -> projectService.findAllAdmins(project.getCommunityId(), project.getId()).stream().filter(IS_ELIGIBLE_FOR_PROJECT_MEMBERSHIP).collect(Collectors.toList()), () -> projectService.findAllUsers(project.getCommunityId(), project.getId()));
    membershipLayout = new MembershipChangerComponent(getTranslation("view.project-admin.users.button.join"), getTranslation("view.project-admin.users.button.demit"), () -> projectService.isUser(project.getId()));
    userService.findById(currentUserId).ifPresent(user -> membershipLayout.setEnabled(IS_ELIGIBLE_FOR_PROJECT_MEMBERSHIP.test(user)));
    UserContextMenuFactory userContextMenuFactory = UserContextMenuFactory.builder().withCurrentUserId(currentUserId).allowRemovalOfLastUser().withConfirmRemovalMessageKey("view.project-admin.users.remove.confirm").withConfirmSelfRemovalMessageKey("view.project-admin.users.remove.yourself.confirm").withRemoveInvitationAction(invitationId -> {
        projectService.removeInvitation(projectId, invitationId);
        gridReload();
    }).withResendInvitationAction(invitationId -> {
        projectService.resendInvitation(projectId, invitationId);
        gridReload();
    }).withRemoveUserAction(userId -> {
        try {
            projectService.removeUser(project.getCommunityId(), project.getId(), userId);
        } catch (UserInstallationOnSiteIsNotTerminalException e) {
            showErrorNotification(getTranslation("user.currently.de-installing"));
        }
    }).withPostRemoveUserAction(userId -> {
        membershipLayout.loadAppropriateButton();
        inviteUser.reload();
    }).addCustomContextMenuItem((UserGridItem userGridItem) -> new MenuButton(getTranslation("view.project-admin.users.requested.accept"), CHECK_CIRCLE), userGridItem -> {
        try {
            projectApplicationsService.accept(projectId, userGridItem.getFenixUserId().get());
            showSuccessNotification(getTranslation("view.project-admin.users.application.accept"));
        } catch (ApplicationNotExistingException e) {
            showErrorNotification(getTranslation("application.already.not.existing"));
        }
        grid.reloadGrid();
    }, userGridItem -> UserUIStatus.ACCESS_REQUESTED.equals(userGridItem.getStatus())).addCustomContextMenuItem((UserGridItem userGridItem) -> new MenuButton(getTranslation("view.project-admin.users.requested.reject"), CLOSE_CIRCLE), userGridItem -> {
        try {
            projectApplicationsService.remove(projectId, userGridItem.getFenixUserId().get());
            showSuccessNotification(getTranslation("view.project-admin.users.application.reject"));
        } catch (ApplicationNotExistingException e) {
            showErrorNotification(getTranslation("application.already.not.existing"));
        }
        grid.reloadGrid();
    }, userGridItem -> UserUIStatus.ACCESS_REQUESTED.equals(userGridItem.getStatus())).build();
    UserGrid.Builder userGrid = UserGrid.defaultInit(userContextMenuFactory);
    grid = UsersGridComponent.defaultInit(() -> projectService.findAllUsers(project.getCommunityId(), project.getId()), () -> projectService.findAllUsersInvitations(projectId), () -> projectApplicationsService.findAllApplyingUsers(projectId), userGrid);
    membershipLayout.addJoinButtonListener(event -> {
        projectService.addUser(project.getCommunityId(), project.getId(), currentUserId);
        grid.reloadGrid();
        inviteUser.reload();
    });
    membershipLayout.addDemitButtonListener(event -> {
        projectService.removeUser(project.getCommunityId(), project.getId(), currentUserId);
        grid.reloadGrid();
        inviteUser.reload();
        membershipLayout.loadAppropriateButton();
    });
    inviteUser.addInviteAction(event -> doInviteAction(inviteUser, projectId));
    ViewHeaderLayout headerLayout = new ViewHeaderLayout(getTranslation("view.project-admin.users.header", project.getName()), membershipLayout);
    getContent().add(headerLayout, inviteUser, grid);
}
Also used : Project(io.imunity.furms.domain.projects.Project) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory) LoggerFactory(org.slf4j.LoggerFactory) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) MembershipChangerComponent(io.imunity.furms.ui.components.MembershipChangerComponent) DuplicatedInvitationError(io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError) UserAlreadyAppliedForMembershipException(io.imunity.furms.api.validation.exceptions.UserAlreadyAppliedForMembershipException) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) UserUIStatus(io.imunity.furms.ui.components.administrators.UserUIStatus) UserService(io.imunity.furms.api.users.UserService) PROJECT_BASE_LANDING_PAGE(io.imunity.furms.domain.constant.RoutesConst.PROJECT_BASE_LANDING_PAGE) UsersGridComponent(io.imunity.furms.ui.components.administrators.UsersGridComponent) ProjectAdminMenu(io.imunity.furms.ui.views.project.ProjectAdminMenu) PersistentId(io.imunity.furms.domain.users.PersistentId) Logger(org.slf4j.Logger) ApplicationNotExistingException(io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException) Predicate(java.util.function.Predicate) MethodHandles(java.lang.invoke.MethodHandles) ProjectApplicationsService(io.imunity.furms.api.applications.ProjectApplicationsService) FURMSUser(io.imunity.furms.domain.users.FURMSUser) Collectors(java.util.stream.Collectors) UserAlreadyHasRoleError(io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError) AuthzService(io.imunity.furms.api.authz.AuthzService) AfterNavigationEvent(com.vaadin.flow.router.AfterNavigationEvent) InviteUserComponent(io.imunity.furms.ui.components.InviteUserComponent) UserInstallationOnSiteIsNotTerminalException(io.imunity.furms.api.validation.exceptions.UserInstallationOnSiteIsNotTerminalException) ProjectService(io.imunity.furms.api.projects.ProjectService) CLOSE_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE) CHECK_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE) UserGridItem(io.imunity.furms.ui.components.administrators.UserGridItem) FurmsLandingViewComponent(io.imunity.furms.ui.components.FurmsLandingViewComponent) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) NotificationUtils.showSuccessNotification(io.imunity.furms.ui.utils.NotificationUtils.showSuccessNotification) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) ApplicationNotExistingException(io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException) MembershipChangerComponent(io.imunity.furms.ui.components.MembershipChangerComponent) MenuButton(io.imunity.furms.ui.components.MenuButton) UserInstallationOnSiteIsNotTerminalException(io.imunity.furms.api.validation.exceptions.UserInstallationOnSiteIsNotTerminalException) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory) UserGridItem(io.imunity.furms.ui.components.administrators.UserGridItem) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) InviteUserComponent(io.imunity.furms.ui.components.InviteUserComponent)

Example 2 with CLOSE_CIRCLE

use of com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE in project furms by unity-idm.

the class InvitationsView method createMainContextMenu.

private Component createMainContextMenu(InviteeService inviteeService, Map<InvitationId, Checkbox> checkboxes) {
    GridActionMenu contextMenu = new GridActionMenu();
    contextMenu.addItem(new MenuButton(getTranslation("view.user-settings.invitations.main.context-menu.confirm"), CHECK_CIRCLE), event -> {
        try {
            checkboxes.entrySet().stream().filter(x -> x.getValue().getValue()).forEach(x -> inviteeService.acceptBy(x.getKey()));
        } catch (InvitationNotExistingException e) {
            showErrorNotification(getTranslation("invitation.already.removed"));
        } catch (Exception e) {
            LOG.warn("Could not accept Invitations. ", e);
            showErrorNotification(getTranslation("base.error.message"));
        }
        loadGrid();
    });
    contextMenu.addItem(new MenuButton(getTranslation("view.user-settings.invitations.main.context-menu.reject"), CLOSE_CIRCLE), event -> {
        if (checkboxes.entrySet().stream().anyMatch(x -> x.getValue().getValue()))
            createMainConfirmDialog(checkboxes).open();
    });
    return contextMenu.getTarget();
}
Also used : UTCTimeUtils.convertToZoneTime(io.imunity.furms.utils.UTCTimeUtils.convertToZoneTime) Component(com.vaadin.flow.component.Component) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) LoggerFactory(org.slf4j.LoggerFactory) Label(com.vaadin.flow.component.html.Label) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) MenuButton(io.imunity.furms.ui.components.MenuButton) HashMap(java.util.HashMap) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Map(java.util.Map) UserSettingsMenu(io.imunity.furms.ui.views.user_settings.UserSettingsMenu) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) DateTimeFormatter(java.time.format.DateTimeFormatter) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) InvitationId(io.imunity.furms.domain.invitations.InvitationId) Optional(java.util.Optional) CLOSE_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE) CHECK_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE) Dialog(com.vaadin.flow.component.dialog.Dialog) InviteeService(io.imunity.furms.api.invitations.InviteeService) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) MenuButton(io.imunity.furms.ui.components.MenuButton) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException)

Aggregations

CHECK_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE)2 CLOSE_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE)2 Route (com.vaadin.flow.router.Route)2 MenuButton (io.imunity.furms.ui.components.MenuButton)2 PageTitle (io.imunity.furms.ui.components.PageTitle)2 ViewHeaderLayout (io.imunity.furms.ui.components.ViewHeaderLayout)2 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)2 MethodHandles (java.lang.invoke.MethodHandles)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (com.vaadin.flow.component.Component)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 Dialog (com.vaadin.flow.component.dialog.Dialog)1 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)1 Grid (com.vaadin.flow.component.grid.Grid)1 Label (com.vaadin.flow.component.html.Label)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 AfterNavigationEvent (com.vaadin.flow.router.AfterNavigationEvent)1 ProjectApplicationsService (io.imunity.furms.api.applications.ProjectApplicationsService)1