Skip to content

Commit

Permalink
added target user selection button to assignments list page (shopping…
Browse files Browse the repository at this point in the history
… cart)
  • Loading branch information
KaterynaHonchar committed May 29, 2017
1 parent e7f5a4d commit 18c2764
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 197 deletions.
Expand Up @@ -24,12 +24,7 @@
<select class="form-control input-sm col-md-2" wicket:id="viewTypeSelect"/>
</div>

<div class="col-md-2" wicket:id="targetUserContainer">
<a wicket:id="targetUserButton" class="btn btn-sm btn-default">
<span wicket:id="targetUserLabel"/>
<i wicket:id="deleteTargetUserButton" class="fa fa-times-circle fa-lg text-danger" style="margin-left: 10px;"/>
</a>
</div>
<div class="col-md-2" wicket:id="targetUserPanel" />

<form class="col-md-7 search-form" wicket:id="searchForm">
<div wicket:id="search"/>
Expand Down
Expand Up @@ -40,22 +40,18 @@
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.page.admin.orgs.OrgTreePanel;
import com.evolveum.midpoint.web.page.admin.users.component.AbstractRoleMemberPanel;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.web.page.self.PageAssignmentsList;
import com.evolveum.midpoint.web.page.self.dto.AssignmentViewType;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.session.OrgTreeStateStorage;
import com.evolveum.midpoint.web.session.RoleCatalogStorage;
import com.evolveum.midpoint.web.session.SessionStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.sun.tools.xjc.reader.xmlschema.bindinfo.BIConversion;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxChannel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
Expand Down Expand Up @@ -86,26 +82,20 @@ public class AssignmentCatalogPanel<F extends AbstractRoleType> extends BasePane
private static final String ID_VIEW_TYPE = "viewTypeSelect";
private static final String ID_SEARCH_FORM = "searchForm";
private static final String ID_SEARCH = "search";
private static final String ID_PANEL_CONTAINER = "catalogItemsPanelContainer";
private static final String ID_TARGET_USER_CONTAINER = "targetUserContainer";
private static final String ID_TARGET_USER_BUTTON = "targetUserButton";
private static final String ID_DELETE_TARGET_USER_BUTTON = "deleteTargetUserButton";
private static final String ID_TARGET_USER_LABEL = "targetUserLabel";
private static final String ID_TARGET_USER_PANEL = "targetUserPanel";

private static final String DOT_CLASS = AssignmentCatalogPanel.class.getName();
private static final Trace LOGGER = TraceManager.getTrace(AssignmentCatalogPanel.class);
private static final String OPERATION_LOAD_ASSIGNMENT_CONSTRAINTS = DOT_CLASS + "loadAssignmentConstraints";
private static final String OPERATION_LOAD_ASSIGNABLE_ROLES = DOT_CLASS + "loadAssignableRoles";

private static final int TARGET_USERS_TITLE_ROWS = 30;
private PageBase pageBase;
private IModel<String> selectedTreeItemOidModel;
private String rootOid;
private IModel<Search> searchModel;
private IModel<AssignmentViewType> viewModel;
private ObjectDataProvider<AssignmentEditorDto, AbstractRoleType> objectProvider;
private int itemsPerRow = 4;
private boolean showUserSelectionPopup = true;
private List<AssignmentEditorDto> listProviderData;
List<AssignmentViewType> viewTypeList = new ArrayList<>();

Expand Down Expand Up @@ -330,46 +320,11 @@ public Search load() {
}

private void initUserSelectionPanel(WebMarkupContainer headerPanel){
WebMarkupContainer targetUserContainer = new WebMarkupContainer(ID_TARGET_USER_CONTAINER);
targetUserContainer.setOutputMarkupId(true);
AjaxLink<String> targetUserButton = new AjaxLink<String>(ID_TARGET_USER_BUTTON) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (showUserSelectionPopup) {
initUserSelectionPopup(createStringResource("AssignmentCatalogPanel.selectTargetUser"), true, target);
}
showUserSelectionPopup = true;
}
};
targetUserButton.setOutputMarkupId(true);
targetUserButton.add(new AttributeAppender("title", getTargetUsersButtonTitle()));
targetUserContainer.add(targetUserButton);

Label label = new Label(ID_TARGET_USER_LABEL, getTargetUserLabelModel());
label.setRenderBodyOnly(true);
targetUserButton.add(label);

AjaxLink deleteButton = new AjaxLink(ID_DELETE_TARGET_USER_BUTTON) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showUserSelectionPopup = false;
getRoleCatalogStorage().setTargetUserList(null);
target.add(getTargetUserContainer());
}
};
deleteButton.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return getRoleCatalogStorage().getTargetUserList() != null &&
getRoleCatalogStorage().getTargetUserList().size() > 0;
}
});
targetUserButton.add(deleteButton);
headerPanel.add(targetUserContainer);
WebMarkupContainer targetUserPanel = new TargetUserSelectorComponent(ID_TARGET_USER_PANEL, "btn-sm", pageBase);
targetUserPanel.setOutputMarkupId(true);
headerPanel.add(targetUserPanel);
}

private void initViewSelector(WebMarkupContainer headerPanel){
DropDownChoice<AssignmentViewType> viewSelect = new DropDownChoice(ID_VIEW_TYPE, viewModel,
Model.ofList(viewTypeList != null && viewTypeList.size() > 0 ?
Expand All @@ -381,8 +336,8 @@ private void initViewSelector(WebMarkupContainer headerPanel){
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (AssignmentViewType.USER_TYPE.equals(viewSelect.getModelObject())){
initUserSelectionPopup(createStringResource("AssignmentCatalogPanel.selectAssignmentsUserOwner"),
false, target);
initUserViewSelectionPopup(createStringResource("AssignmentCatalogPanel.selectAssignmentsUserOwner"),
target);
} else {
AssignmentCatalogPanel.this.addOrReplaceLayout(target, getCatalogItemsPanelContainer());
target.add(getCatalogItemsPanelContainer());
Expand All @@ -395,40 +350,7 @@ protected void onUpdate(AjaxRequestTarget target) {

}

private IModel<String> getTargetUsersButtonTitle() {
return new LoadableModel<String>(true) {
public String load() {
StringBuilder sb = new StringBuilder();
if (getRoleCatalogStorage().isMultiUserRequest()) {
List<PrismObject<UserType>> sortedList = getRoleCatalogStorage().getTargetUserList();
Collections.sort(sortedList, new Comparator<PrismObject<UserType>>() {

@Override
public int compare(PrismObject<UserType> u1, PrismObject<UserType> u2) {
return String.CASE_INSENSITIVE_ORDER.compare(u1.getName().getOrig(), u2.getName().getOrig());
}
});
int columnsAmount = sortedList.size() / TARGET_USERS_TITLE_ROWS;
Iterator<PrismObject<UserType>> it = sortedList.iterator();
while (it.hasNext()){
for (int i=0; i <= columnsAmount; i++){
if (it.hasNext()){
PrismObject user = it.next();
sb.append(user.getName().getOrig());
if (it.hasNext()){
sb.append(",\t");
}
}
}
sb.append(System.lineSeparator());
}
}
return sb.toString();
}
};
}

private WebMarkupContainer getCatalogItemsPanelContainer(){
private WebMarkupContainer getCatalogItemsPanelContainer(){
return (WebMarkupContainer)get(ID_CATALOG_ITEMS_PANEL_CONTAINER);
}

Expand Down Expand Up @@ -621,25 +543,15 @@ private boolean isCatalogOidEmpty(){
(selectedTreeItemOidModel == null || StringUtils.isEmpty(oid));
}

private void initUserSelectionPopup(StringResourceModel title, boolean multiselect, AjaxRequestTarget target) {
private void initUserViewSelectionPopup(StringResourceModel title, AjaxRequestTarget target) {

List<QName> supportedTypes = new ArrayList<>();
supportedTypes.add(pageBase.getPrismContext().getSchemaRegistry()
.findObjectDefinitionByCompileTimeClass(UserType.class).getTypeName());
ObjectBrowserPanel<UserType> focusBrowser = new ObjectBrowserPanel<UserType>(pageBase.getMainPopupBodyId(),
UserType.class, supportedTypes, multiselect, pageBase, null, getSelectedObjects()) {
@Override
protected void addPerformed(AjaxRequestTarget target, QName type, List<UserType> selected) {
super.addPerformed(target, type, selected);
List<PrismObject<UserType>> userList = new ArrayList<>();
for (UserType user : selected){
userList.add(user.asPrismObject());
}
getRoleCatalogStorage().setTargetUserList(userList);
AssignmentCatalogPanel.this.addOrReplaceLayout(target, getCatalogItemsPanelContainer());
target.add(getHeaderPanel());
target.add(getCatalogItemsPanelContainer());
}
UserType.class, supportedTypes, false, pageBase, null, new ArrayList<>()) {

private static final long serialVersionUID = 1L;

@Override
protected void onSelectPerformed(AjaxRequestTarget target, UserType targetUser) {
Expand All @@ -656,48 +568,8 @@ public StringResourceModel getTitle() {
return title;
}

};
pageBase.showMainPopup(focusBrowser, target);
}

private List<UserType> getSelectedObjects(){
List<PrismObject<UserType>> selectedUsers = getRoleCatalogStorage().getTargetUserList();
List<UserType> users = new ArrayList<>();
if (selectedUsers != null) {
for (PrismObject<UserType> user : selectedUsers) {
users.add(user.asObjectable());
}
}
return users;
}

private WebMarkupContainer getTargetUserContainer(){
return (WebMarkupContainer)get(ID_HEADER_PANEL).get(ID_TARGET_USER_CONTAINER);
}
private IModel<String> getTargetUserLabelModel(){
return new IModel<String>() {
@Override
public String getObject() {
if (getRoleCatalogStorage().isSelfRequest()){
return createStringResource("AssignmentCatalogPanel.requestForMe").getString();
}
List<PrismObject<UserType>> targetUsersList = getRoleCatalogStorage().getTargetUserList();
if (targetUsersList.size() == 1){
return createStringResource("AssignmentCatalogPanel.requestFor").getString() +
" " + targetUsersList.get(0).getName().getOrig();
}
return createStringResource("AssignmentCatalogPanel.requestForMultiple", targetUsersList.size()).getString();
}

@Override
public void setObject(String s) {
}

@Override
public void detach() {

}
};
pageBase.showMainPopup(focusBrowser, target);
}

private boolean isAlreadyAssigned(PrismObject<AbstractRoleType> obj, AssignmentEditorDto assignmentDto){
Expand Down
Expand Up @@ -49,7 +49,6 @@ public class CatalogItemsPanel extends BasePanel implements IPageableItems {
private static final String ID_PAGING = "paging";
private static final String ID_COUNT = "count";
private static final String ID_FOOTER_CONTAINER = "footerContainer";
private static final String ID_SUBMIT_BUTTON = "submitButton";
private static final String ID_FOOTER = "footer";

private ObjectDataProvider<AssignmentEditorDto, AbstractRoleType> objectDataProvider;
Expand All @@ -63,10 +62,6 @@ public class CatalogItemsPanel extends BasePanel implements IPageableItems {
private long currentPage = 0;
private boolean isListProvider = false;

public CatalogItemsPanel(String id) {
super(id);
}

public CatalogItemsPanel(String id, final PageBase pageBase, int itemsPerRow,
ListDataProvider provider) {
super(id);
Expand Down Expand Up @@ -115,10 +110,6 @@ private void initLayout() {

}

protected void refreshCatalogItemsPanel() {

}

private void initItemListModel() {
List<AssignmentEditorDto> itemList = new ArrayList<>();
if (isListProvider){
Expand Down
@@ -0,0 +1,25 @@
<!--
~ Copyright (c) 2016 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<a wicket:id="targetUserButton">
<span wicket:id="targetUserLabel"/>
<i wicket:id="deleteTargetUserButton" class="fa fa-times-circle fa-lg text-danger" style="margin-left: 10px;"/>
</a>
</wicket:panel>
</html>

0 comments on commit 18c2764

Please sign in to comment.