use of io.imunity.furms.ui.components.MembershipChangerComponent in project furms by unity-idm.
the class SitesAdminsView method init.
private void init(String siteId) {
InviteUserComponent inviteUser = new InviteUserComponent(userService::getAllUsers, () -> siteService.findAllAdministrators(siteId));
MembershipChangerComponent membershipLayout = new MembershipChangerComponent(getTranslation("view.fenix-admin.sites.button.join"), getTranslation("view.fenix-admin.sites.button.demit"), () -> siteService.isCurrentUserAdminOf(siteId));
membershipLayout.addJoinButtonListener(event -> {
siteService.addAdmin(siteId, currentUserId);
gridReload();
inviteUser.reload();
});
membershipLayout.addDemitButtonListener(event -> {
if (siteService.findAllAdministrators(siteId).size() > 1) {
handleExceptions(() -> siteService.removeSiteUser(siteId, currentUserId));
gridReload();
} else {
showErrorNotification(getTranslation("component.administrators.error.validation.remove"));
}
inviteUser.reload();
membershipLayout.loadAppropriateButton();
});
inviteUser.addInviteAction(event -> doInviteAction(siteId, inviteUser, membershipLayout));
UserContextMenuFactory userContextMenuFactory = UserContextMenuFactory.builder().withCurrentUserId(currentUserId).withRemoveUserAction(userId -> siteService.removeSiteUser(siteId, userId)).withPostRemoveUserAction(userId -> {
membershipLayout.loadAppropriateButton();
inviteUser.reload();
}).withRemoveInvitationAction(invitationId -> {
siteService.removeInvitation(siteId, invitationId);
gridReload();
}).withResendInvitationAction(invitationId -> {
siteService.resendInvitation(siteId, invitationId);
gridReload();
}).build();
UserGrid.Builder userGrid = UserGrid.defaultInit(userContextMenuFactory);
grid = UsersGridComponent.defaultInit(() -> siteService.findAllAdministrators(siteId), () -> siteService.findSiteAdminInvitations(siteId), userGrid);
Site site = handleExceptions(() -> siteService.findById(siteId)).flatMap(identity()).orElseThrow(IllegalStateException::new);
ViewHeaderLayout viewHeaderLayout = new ViewHeaderLayout(getTranslation("view.sites.administrators.title", site.getName()), membershipLayout);
getContent().add(viewHeaderLayout, inviteUser, grid);
}
use of io.imunity.furms.ui.components.MembershipChangerComponent in project furms by unity-idm.
the class ProjectView method loadPage1Content.
private void loadPage1Content(Project project) {
InviteUserComponent inviteUser = new InviteUserComponent(() -> communityService.findAllUsers(project.getCommunityId()), () -> projectService.findAllAdmins(project.getCommunityId(), project.getId()));
MembershipChangerComponent membershipLayout = new MembershipChangerComponent(getTranslation("view.community-admin.project.button.join"), getTranslation("view.community-admin.project.button.demit"), () -> projectService.isAdmin(project.getId()));
UserContextMenuFactory userContextMenuFactory = UserContextMenuFactory.builder().withCurrentUserId(currentUserId).redirectOnCurrentUserRemoval().withRemoveUserAction(userId -> projectService.removeAdmin(project.getCommunityId(), project.getId(), userId)).withRemoveInvitationAction(invitationId -> {
projectService.removeInvitation(project.getId(), invitationId);
gridReload();
}).withResendInvitationAction(invitationId -> {
projectService.resendInvitation(project.getId(), invitationId);
gridReload();
}).withPostRemoveUserAction(userId -> {
membershipLayout.loadAppropriateButton();
inviteUser.reload();
}).build();
UserGrid.Builder userGrid = UserGrid.defaultInit(userContextMenuFactory);
grid = UsersGridComponent.defaultInit(() -> projectService.findAllAdmins(project.getCommunityId(), project.getId()), () -> projectService.findAllAdminsInvitations(project.getId()), userGrid);
membershipLayout.addJoinButtonListener(event -> {
projectService.addAdmin(project.getCommunityId(), project.getId(), currentUserId);
gridReload();
inviteUser.reload();
});
membershipLayout.addDemitButtonListener(event -> {
if (projectService.findAllAdmins(project.getCommunityId(), project.getId()).size() > 1) {
handleExceptions(() -> projectService.removeAdmin(project.getCommunityId(), project.getId(), currentUserId));
gridReload();
} else {
showErrorNotification(getTranslation("component.administrators.error.validation.remove"));
}
inviteUser.reload();
membershipLayout.loadAppropriateButton();
});
ViewHeaderLayout headerLayout = new ViewHeaderLayout(getTranslation("view.community-admin.project.page.header", project.getName()), membershipLayout);
inviteUser.addInviteAction(event -> doInviteAction(project, inviteUser, membershipLayout));
page1.add(headerLayout, inviteUser, grid);
}
use of io.imunity.furms.ui.components.MembershipChangerComponent 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);
}
Aggregations