Skip to content

Commit

Permalink
MID-7963 relation step, tiles created, so far wrong icons and titles
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 9, 2022
1 parent abb07eb commit 4e5beb7
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
</wicket:fragment>

<wicket:fragment wicket:id="selectionFragment">
<!-- https://select2.org/-->

<div class="card w-100">
<div class="card-header">
<h3 class="card-title">
Expand All @@ -31,7 +29,7 @@ <h3 class="card-title">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-append">
<a class="btn btn-default" type="button">
<a class="btn btn-default" type="button" wicket:id="selectManually">
<i class="fa-solid fa-arrow-pointer mr-1"></i>
<wicket:message key="PersonOfInterestPanel.selectManually"/>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

import java.util.ArrayList;
import java.util.List;

import com.evolveum.midpoint.web.component.util.EnableBehaviour;
import javax.xml.namespace.QName;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel;
import com.evolveum.midpoint.gui.api.component.wizard.BasicWizardPanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.security.api.SecurityUtil;
Expand All @@ -41,9 +42,6 @@ private enum PersonOfInterest {

GROUP_OTHERS("fas fa-user-friends");

// disabled for now
// TEAM("fas fa-users");

private String icon;

PersonOfInterest(String icon) {
Expand All @@ -67,10 +65,14 @@ private enum SelectionState {
private static final String ID_LIST = "list";
private static final String ID_TILE = "tile";

private static final String ID_SELECT_MANUALLY = "selectManually";

private IModel<List<Tile<PersonOfInterest>>> tiles;

private IModel<SelectionState> selectionState = Model.of(SelectionState.TILES);

private IModel<List<ObjectReferenceType>> selectedGroupOfUsers = Model.ofList(new ArrayList<>());

public PersonOfInterestPanel(IModel<RequestAccess> model) {
super(model);

Expand Down Expand Up @@ -118,7 +120,16 @@ protected List<Tile<PersonOfInterest>> load() {

@Override
public VisibleEnableBehaviour getNextBehaviour() {
return new EnableBehaviour(() -> tiles.getObject().stream().filter(t -> t.isSelected()).count() > 0);
return new VisibleBehaviour(() -> {
Tile<PersonOfInterest> myself = getTileBy(PersonOfInterest.MYSELF);
Tile<PersonOfInterest> others = getTileBy(PersonOfInterest.GROUP_OTHERS);

return myself.isSelected() || (others.isSelected() && selectedGroupOfUsers.getObject().size() > 0);
});
}

private Tile<PersonOfInterest> getTileBy(PersonOfInterest type) {
return tiles.getObject().stream().filter(t -> t.getValue() == type).findFirst().orElseGet(null);
}

private void initLayout() {
Expand All @@ -144,10 +155,10 @@ protected void onClick(AjaxRequestTarget target) {
Tile<PersonOfInterest> tile = item.getModelObject();
switch (tile.getValue()) {
case MYSELF:
myselfPerformed(target);
myselfPerformed(target, tile);
break;
case GROUP_OTHERS:
groupOthersPerformed(target);
groupOthersPerformed(target, tile);
break;
}
}
Expand All @@ -163,6 +174,15 @@ protected void onClick(AjaxRequestTarget target) {
private Fragment initSelectionFragment() {
Fragment fragment = new Fragment(ID_FRAGMENTS, ID_SELECTION_FRAGMENT, this);

AjaxLink selectManually = new AjaxLink<>(ID_SELECT_MANUALLY) {

@Override
public void onClick(AjaxRequestTarget target) {
selectManuallyPerformed(target);
}
};
fragment.add(selectManually);

return fragment;
}

Expand All @@ -182,22 +202,60 @@ protected void onBeforeRender() {
addOrReplace(fragment);
}

private void myselfPerformed(AjaxRequestTarget target) {
ObjectReferenceType myself = new ObjectReferenceType()
.oid(SecurityUtil.getPrincipalOidIfAuthenticated())
.type(UserType.COMPLEX_TYPE);
getModelObject().getPersonOfInterest().add(myself);
private void myselfPerformed(AjaxRequestTarget target, Tile<PersonOfInterest> myself) {
boolean wasSelected = myself.isSelected();

getWizard().next();
tiles.getObject().forEach(t -> t.setSelected(false));
myself.setSelected(!wasSelected);

target.add(getWizard().getPanel());
target.add(this);
}

private void groupOthersPerformed(AjaxRequestTarget target) {
selectionState.setObject(SelectionState.USERS);
private void groupOthersPerformed(AjaxRequestTarget target, Tile<PersonOfInterest> groupOthers) {
tiles.getObject().forEach(t -> t.setSelected(false));

if (!groupOthers.isSelected()) {
selectionState.setObject(SelectionState.USERS);
}

groupOthers.toggle();

target.add(this);
}

private void selectManuallyPerformed(AjaxRequestTarget target) {
ObjectBrowserPanel<UserType> panel = new ObjectBrowserPanel<>(
getPageBase().getMainPopupBodyId(), UserType.class,
List.of(UserType.COMPLEX_TYPE), true, getPageBase()) {
private static final long serialVersionUID = 1L;

@Override
protected void onSelectPerformed(AjaxRequestTarget target, UserType user) {
addUsersPerformed(target, List.of(user));
}

@Override
protected void addPerformed(AjaxRequestTarget target, QName type, List<UserType> selected) {
addUsersPerformed(target, selected);
}
};
getPageBase().showMainPopup(panel, target);
}

private void addUsersPerformed(AjaxRequestTarget target, List<UserType> users) {
List<ObjectReferenceType> refs = new ArrayList<>();
for (UserType user : users) {
refs.add(new ObjectReferenceType()
.oid(user.getOid())
.type(UserType.COMPLEX_TYPE));
}

selectedGroupOfUsers.setObject(refs);

getPageBase().hideMainPopup(target);
target.add(getWizard().getPanel());
}

@Override
protected void onBackPerformed(AjaxRequestTarget target) {
if (selectionState.getObject() == SelectionState.TILES) {
Expand All @@ -209,10 +267,19 @@ protected void onBackPerformed(AjaxRequestTarget target) {
target.add(this);
}


@Override
protected void onNextPerformed(AjaxRequestTarget target) {
// todo save state
Tile<PersonOfInterest> myself = getTileBy(PersonOfInterest.MYSELF);
if (myself.isSelected()) {
ObjectReferenceType ref = new ObjectReferenceType()
.oid(SecurityUtil.getPrincipalOidIfAuthenticated())
.type(UserType.COMPLEX_TYPE);
getModelObject().getPersonOfInterest().add(ref);
} else {
getModelObject().getPersonOfInterest().addAll(selectedGroupOfUsers.getObject());
}

getWizard().next();
target.add(getWizard().getPanel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@
import java.util.List;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.model.LoadableModel;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.LoadableDetachableModel;

import com.evolveum.midpoint.gui.api.component.wizard.BasicWizardPanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.SecurityUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.web.component.util.EnableBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AreaCategoryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;

/**
Expand All @@ -52,7 +57,23 @@ public RelationPanel(IModel<RequestAccess> model) {
}

private void initModels() {
relations = Model.ofList(new ArrayList<>());
relations = new LoadableModel<>(false) {

@Override
protected List<Tile<QName>> load() {
List<Tile<QName>> tiles = new ArrayList<>();

List<QName> list = getAvailableRelationsList();
for (QName name : list) {
Tile<QName> tile = new Tile("fas fa-users", name.getLocalPart());
tile.setValue(name);

tiles.add(tile);
}

return tiles;
}
};
}

@Override
Expand Down Expand Up @@ -83,7 +104,13 @@ protected void populateItem(ListItem<Tile<QName>> item) {

@Override
protected void onClick(AjaxRequestTarget target) {
Tile<QName> tile = item.getModelObject();
boolean wasSelected = tile.isSelected();

relations.getObject().forEach(t -> t.setSelected(false));
tile.setSelected(!wasSelected);

target.add(getWizard().getPanel());
}
};
item.add(tp);
Expand All @@ -93,16 +120,22 @@ protected void onClick(AjaxRequestTarget target) {
}

private List<QName> getAvailableRelationsList() {
List<QName> availableRelations = WebComponentUtil.getCategoryRelationChoices(AreaCategoryType.SELF_SERVICE, getPageBase());
// todo fix focus parameter
FocusType focus = null;
try {
focus = SecurityUtil.getPrincipal().getFocus();
} catch (SecurityViolationException ex) {
ex.printStackTrace();
}
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ASSIGNABLE_RELATIONS_LIST);
OperationResult result = task.getResult();
List<QName> assignableRelationsList = WebComponentUtil.getAssignableRelationsList(
null,//getTargetUser().asPrismObject(),
RoleType.class,
WebComponentUtil.AssignmentOrder.ASSIGNMENT, result, task, getPageBase());
focus.asPrismObject(), RoleType.class, WebComponentUtil.AssignmentOrder.ASSIGNMENT, result, task, getPageBase());

if (CollectionUtils.isEmpty(assignableRelationsList)) {
return availableRelations;
return WebComponentUtil.getCategoryRelationChoices(AreaCategoryType.SELF_SERVICE, getPageBase());
}

return assignableRelationsList;
}

Expand All @@ -113,7 +146,11 @@ public VisibleEnableBehaviour getNextBehaviour() {

@Override
protected void onNextPerformed(AjaxRequestTarget target) {
// todo save state
Tile<QName> selected = relations.getObject().stream().filter(t -> t.isSelected()).findFirst().orElse(null);

getModelObject().setRelation(selected.getValue());

getWizard().next();
target.add(getWizard().getPanel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public void setShoppingCartAssignments(List<AssignmentType> shoppingCartAssignme
this.shoppingCartAssignments = shoppingCartAssignments;
}

public QName getRelation() {
return relation;
}

public void setRelation(QName relation) {
this.relation = relation;
}

public void computeConflicts() {
// MidPointApplication mp = MidPointApplication.get();
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public IModel<List<Badge>> getTitleBadges() {
return () -> {
String text;

int count = 0;
int count = getModelObject().getPersonOfInterest().size();
if (isRequestingForMyself()) {
text = count > 1 ? getString("RoleCatalogPanel.badgeMyselfAndOthers", count - 1) : getString("RoleCatalogPanel.badgeMyself");
} else {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 4e5beb7

Please sign in to comment.