CCM NG/ccm-core: Some work for the Vaadin prototype
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4825 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
4a29a3446a
commit
9b44b4006e
|
|
@ -45,6 +45,8 @@ import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.security.Group;
|
import org.libreccm.security.Group;
|
||||||
import org.libreccm.security.GroupManager;
|
import org.libreccm.security.GroupManager;
|
||||||
import org.libreccm.security.GroupRepository;
|
import org.libreccm.security.GroupRepository;
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
import org.libreccm.security.RoleRepository;
|
||||||
import org.libreccm.security.User;
|
import org.libreccm.security.User;
|
||||||
import org.libreccm.security.UserRepository;
|
import org.libreccm.security.UserRepository;
|
||||||
|
|
||||||
|
|
@ -64,6 +66,9 @@ public class GroupDetails extends Window {
|
||||||
private static final String COL_EMAIL = "email";
|
private static final String COL_EMAIL = "email";
|
||||||
private static final String COL_REMOVE = "remove";
|
private static final String COL_REMOVE = "remove";
|
||||||
|
|
||||||
|
private static final String COL_ROLE_NAME = "role_name";
|
||||||
|
private static final String COL_ROLE_REMOVE = "remove";
|
||||||
|
|
||||||
private final UsersGroupsRoles usersGroupsRoles;
|
private final UsersGroupsRoles usersGroupsRoles;
|
||||||
private final Group group;
|
private final Group group;
|
||||||
private final GroupRepository groupRepo;
|
private final GroupRepository groupRepo;
|
||||||
|
|
@ -152,7 +157,8 @@ public class GroupDetails extends Window {
|
||||||
dataHasChanged = false;
|
dataHasChanged = false;
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final GroupMembersController controller = cdiUtil
|
|
||||||
|
final GroupMembersController membersController = cdiUtil
|
||||||
.findBean(GroupMembersController.class);
|
.findBean(GroupMembersController.class);
|
||||||
|
|
||||||
final Grid<User> membersGrid = new Grid<>();
|
final Grid<User> membersGrid = new Grid<>();
|
||||||
|
|
@ -172,7 +178,7 @@ public class GroupDetails extends Window {
|
||||||
membersGrid.addColumn(user -> bundle.getString(
|
membersGrid.addColumn(user -> bundle.getString(
|
||||||
"ui.groups.members.remove"),
|
"ui.groups.members.remove"),
|
||||||
new ButtonRenderer<>(event -> {
|
new ButtonRenderer<>(event -> {
|
||||||
controller
|
membersController
|
||||||
.removeMemberFromGroup(event.getItem(),
|
.removeMemberFromGroup(event.getItem(),
|
||||||
group);
|
group);
|
||||||
membersGrid.getDataProvider().refreshAll();
|
membersGrid.getDataProvider().refreshAll();
|
||||||
|
|
@ -195,7 +201,8 @@ public class GroupDetails extends Window {
|
||||||
userRepo.findByGroup(group),
|
userRepo.findByGroup(group),
|
||||||
(selectedUsers -> {
|
(selectedUsers -> {
|
||||||
selectedUsers.forEach(user -> {
|
selectedUsers.forEach(user -> {
|
||||||
controller.addMembersToGroup(selectedUsers, group);
|
membersController
|
||||||
|
.addMembersToGroup(selectedUsers, group);
|
||||||
membersGrid.getDataProvider().refreshAll();
|
membersGrid.getDataProvider().refreshAll();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
@ -217,6 +224,35 @@ public class GroupDetails extends Window {
|
||||||
dataProvider.setGroup(group);
|
dataProvider.setGroup(group);
|
||||||
membersGrid.setDataProvider(dataProvider);
|
membersGrid.setDataProvider(dataProvider);
|
||||||
|
|
||||||
|
final GroupRolesController rolesController = cdiUtil
|
||||||
|
.findBean(GroupRolesController.class);
|
||||||
|
final Grid<Role> rolesGrid = new Grid<>();
|
||||||
|
rolesGrid
|
||||||
|
.addColumn(Role::getName)
|
||||||
|
.setId(COL_ROLE_NAME)
|
||||||
|
.setCaption("Role Name");
|
||||||
|
rolesGrid
|
||||||
|
.addColumn(role -> bundle
|
||||||
|
.getString("ui.groups.roles.remove"),
|
||||||
|
new ButtonRenderer<>(event -> {
|
||||||
|
rolesController
|
||||||
|
.removeRoleFromGroup(event.getItem(), group);
|
||||||
|
rolesGrid.getDataProvider().refreshAll();
|
||||||
|
}))
|
||||||
|
.setId(COL_ROLE_REMOVE);
|
||||||
|
|
||||||
|
rolesGrid.setWidth("100%");
|
||||||
|
|
||||||
|
final RoleRepository roleRepository = cdiUtil
|
||||||
|
.findBean(RoleRepository.class);
|
||||||
|
|
||||||
|
final HeaderRow rolesGridHeader = rolesGrid.prependHeaderRow();
|
||||||
|
final Button addRoleButton = new Button("Add role");
|
||||||
|
addRoleButton.setIcon(VaadinIcons.PLUS);
|
||||||
|
addRoleButton.setStyleName(ValoTheme.BUTTON_TINY);
|
||||||
|
addRoleButton.addClickListener(event -> {
|
||||||
|
|
||||||
|
});
|
||||||
//ToDo Add roles grid
|
//ToDo Add roles grid
|
||||||
|
|
||||||
final TabSheet tabs = new TabSheet();
|
final TabSheet tabs = new TabSheet();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.admin.ui.usersgroupsroles;
|
||||||
|
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface RoleSelectionAction {
|
||||||
|
|
||||||
|
void action(Set<Role> selectedRoles);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.admin.ui.usersgroupsroles;
|
||||||
|
|
||||||
|
import com.arsdigita.ui.admin.AdminUiConstants;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.CDIUI;
|
||||||
|
import com.vaadin.icons.VaadinIcons;
|
||||||
|
import com.vaadin.ui.Button;
|
||||||
|
import com.vaadin.ui.Grid;
|
||||||
|
import com.vaadin.ui.HorizontalLayout;
|
||||||
|
import com.vaadin.ui.UI;
|
||||||
|
import com.vaadin.ui.Window;
|
||||||
|
import com.vaadin.ui.components.grid.HeaderCell;
|
||||||
|
import com.vaadin.ui.components.grid.HeaderRow;
|
||||||
|
import com.vaadin.ui.themes.ValoTheme;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
import org.libreccm.security.RoleRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class RoleSelector extends Window {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -1437536052155383270L;
|
||||||
|
|
||||||
|
private static final String COL_NAME = "rolename";
|
||||||
|
|
||||||
|
private final RoleRepository roleRepo;
|
||||||
|
|
||||||
|
private final RoleSelectionAction roleSelectionAction;
|
||||||
|
|
||||||
|
public RoleSelector(final String caption,
|
||||||
|
final String actionLabel,
|
||||||
|
final UsersGroupsRoles usersGroupsRoles,
|
||||||
|
final List<Role> excludedRoles,
|
||||||
|
final RoleSelectionAction action) {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
roleRepo = cdiUtil.findBean(RoleRepository.class);
|
||||||
|
this.roleSelectionAction = action;
|
||||||
|
|
||||||
|
addWidgets(caption, actionLabel, excludedRoles, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addWidgets(final String caption,
|
||||||
|
final String actionLabel,
|
||||||
|
final List<Role> excludedRoles,
|
||||||
|
final RoleSelectionAction action) {
|
||||||
|
|
||||||
|
setCaption(caption);
|
||||||
|
|
||||||
|
final ResourceBundle bundle = ResourceBundle
|
||||||
|
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
|
||||||
|
UI.getCurrent().getLocale());
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
|
||||||
|
final Grid<Role> rolesGrid = new Grid<>();
|
||||||
|
rolesGrid
|
||||||
|
.addColumn(Role::getName)
|
||||||
|
.setId(COL_NAME)
|
||||||
|
.setCaption("Role");
|
||||||
|
|
||||||
|
rolesGrid.setSelectionMode(Grid.SelectionMode.MULTI);
|
||||||
|
rolesGrid.setWidth("100%");
|
||||||
|
|
||||||
|
final Button actionButton = new Button(actionLabel);
|
||||||
|
actionButton.addClickListener(event -> {
|
||||||
|
action.action(rolesGrid.getSelectedItems());
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
|
||||||
|
actionButton.setIcon(VaadinIcons.PLUS_CIRCLE_O);
|
||||||
|
actionButton.setStyleName(ValoTheme.BUTTON_TINY);
|
||||||
|
|
||||||
|
final Button clearButton = new Button("Clear selection");
|
||||||
|
clearButton.addClickListener(event -> {
|
||||||
|
rolesGrid.getSelectionModel().deselectAll();
|
||||||
|
});
|
||||||
|
clearButton.setIcon(VaadinIcons.BACKSPACE);
|
||||||
|
clearButton.setStyleName(ValoTheme.BUTTON_TINY);
|
||||||
|
|
||||||
|
final HeaderRow actions = rolesGrid.prependHeaderRow();
|
||||||
|
final HeaderCell actionsCell = actions.join(COL_NAME);
|
||||||
|
actionsCell.setComponent(new HorizontalLayout(actionButton,
|
||||||
|
clearButton));
|
||||||
|
|
||||||
|
final RoleSelectorDataProvider dataProvider = cdiUtil
|
||||||
|
.findBean(RoleSelectorDataProvider.class);
|
||||||
|
|
||||||
|
dataProvider.setExcludedRoles(excludedRoles);
|
||||||
|
|
||||||
|
rolesGrid.setDataProvider(dataProvider);
|
||||||
|
|
||||||
|
setContent(rolesGrid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.admin.ui.usersgroupsroles;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.ViewScoped;
|
||||||
|
import com.vaadin.data.provider.AbstractDataProvider;
|
||||||
|
import com.vaadin.data.provider.Query;
|
||||||
|
import org.libreccm.security.Role;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@ViewScoped
|
||||||
|
public class RoleSelectorDataProvider extends AbstractDataProvider<Role, String> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3915041291561733758L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
private String roleNameFilter;
|
||||||
|
|
||||||
|
private List<Role> excludedRoles;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInMemory() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
@Override
|
||||||
|
public int size(final Query<Role, String> query) {
|
||||||
|
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
final CriteriaQuery<Long> criteriaQuery = builder
|
||||||
|
.createQuery(Long.class);
|
||||||
|
final Root<Role> from = criteriaQuery.from(Role.class);
|
||||||
|
|
||||||
|
criteriaQuery
|
||||||
|
.select(builder.count(from))
|
||||||
|
.distinct(true);
|
||||||
|
|
||||||
|
if (roleNameFilter != null && !roleNameFilter.trim().isEmpty()) {
|
||||||
|
criteriaQuery
|
||||||
|
.where(builder.like(builder.lower(from.get("name")),
|
||||||
|
String.format("%s%%", roleNameFilter)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludedRoles != null && !excludedRoles.isEmpty()) {
|
||||||
|
criteriaQuery.where(builder.not(from.in(excludedRoles)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return entityManager
|
||||||
|
.createQuery(criteriaQuery)
|
||||||
|
.getSingleResult()
|
||||||
|
.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
@Override
|
||||||
|
public Stream<Role> fetch(final Query<Role, String> query) {
|
||||||
|
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
|
||||||
|
final CriteriaQuery<Role> criteriaQuery = builder
|
||||||
|
.createQuery(Role.class);
|
||||||
|
final Root<Role> from = criteriaQuery.from(Role.class);
|
||||||
|
|
||||||
|
criteriaQuery.distinct(true);
|
||||||
|
|
||||||
|
if (roleNameFilter != null && !roleNameFilter.trim().isEmpty()) {
|
||||||
|
criteriaQuery
|
||||||
|
.where(builder.like(builder.lower(from.get("name")),
|
||||||
|
String.format("%s%%", roleNameFilter)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludedRoles != null && !excludedRoles.isEmpty()) {
|
||||||
|
criteriaQuery.where(builder.not(from.in(excludedRoles)));
|
||||||
|
}
|
||||||
|
|
||||||
|
criteriaQuery.orderBy(builder.asc(from.get("name")));
|
||||||
|
|
||||||
|
return entityManager
|
||||||
|
.createQuery(criteriaQuery)
|
||||||
|
.setMaxResults(query.getLimit())
|
||||||
|
.setFirstResult(query.getOffset())
|
||||||
|
.getResultList()
|
||||||
|
.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleNameFilter(final String roleNameFilter) {
|
||||||
|
this.roleNameFilter = roleNameFilter;
|
||||||
|
refreshAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExcludedRoles(final List<Role> excluededRoles) {
|
||||||
|
this.excludedRoles = new ArrayList<>(excluededRoles);
|
||||||
|
refreshAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue