Skip to content

Commit

Permalink
MID-7976 poi step improved default selection of tile when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Aug 17, 2022
1 parent 1f39f40 commit 00bd28a
Showing 1 changed file with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
Expand Down Expand Up @@ -115,7 +116,7 @@ private enum SelectionState {

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

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

private IModel<Map<ObjectReferenceType, List<ObjectReferenceType>>> selectedGroupOfUsers = Model.ofMap(new HashMap<>());

Expand Down Expand Up @@ -155,56 +156,58 @@ protected IModel<String> getSubTextModel() {
}

private void initModels() {

tiles = new LoadableModel<>(false) {

@Override
protected List<Tile<PersonOfInterest>> load() {
List<Tile<PersonOfInterest>> list = new ArrayList<>();

TargetSelectionType selection = getTargetSelectionConfiguration();
if (selection == null) {
for (TileType type : TileType.values()) {
Tile tile = createDefaultTile(type);
list.add(tile);
}

selectTileIfOnlyOne(list);

return list;
}
// todo check assignment authorizations

if (selection.isAllowRequestForMyself() == null || selection.isAllowRequestForMyself()) {
TargetSelectionType selection = getTargetSelectionConfiguration();
if (BooleanUtils.isNotFalse(selection.isAllowRequestForMyself())) {
list.add(createDefaultTile(TileType.MYSELF));
}

if (selection.isAllowRequestForOthers() != null && !selection.isAllowRequestForOthers()) {
selectTileIfOnlyOne(list);

return list;
}

List<GroupSelectionType> selections = selection.getGroup();
if (selections.isEmpty()) {
list.add(createDefaultTile(TileType.GROUP_OTHERS));
selectTileIfOnlyOne(list);
return list;
if (BooleanUtils.isNotFalse(selection.isAllowRequestForOthers())) {
List<GroupSelectionType> selections = selection.getGroup();
if (selections.isEmpty()) {
list.add(createDefaultTile(TileType.GROUP_OTHERS));
} else {
for (GroupSelectionType gs : selections) {
list.add(createTile(gs));
}
}
}

for (GroupSelectionType gs : selections) {
list.add(createTile(gs));
if (list.size() == 1) {
Tile<PersonOfInterest> tile = list.get(0);
switch (tile.getValue().type) {
case MYSELF:
tile.setSelected(true);
break;
case GROUP_OTHERS:
tile.setSelected(true);
}
}

selectTileIfOnlyOne(list);

return list;
}
};
}

private void selectTileIfOnlyOne(List<Tile<PersonOfInterest>> list) {
if (list != null && list.size() == 1) {
list.get(0).setSelected(true);
}
selectionState = new LoadableModel<>(false) {

@Override
protected SelectionState load() {
Tile<PersonOfInterest> selected = getSelectedTile();
if (selected != null && selected.getValue().type == TileType.GROUP_OTHERS) {
return SelectionState.USERS;
}

return SelectionState.TILES;
}
};
}

private Tile<PersonOfInterest> createTile(GroupSelectionType selection) {
Expand Down Expand Up @@ -417,6 +420,7 @@ private void myselfPerformed(AjaxRequestTarget target, Tile<PersonOfInterest> my
private void groupOthersPerformed(AjaxRequestTarget target, Tile<PersonOfInterest> groupOthers) {
Tile<PersonOfInterest> selected = getSelectedTile();
if (selected != null && selected.getValue().type == TileType.GROUP_OTHERS && selected != groupOthers) {
// we've selected different group of users as it was previously selected, so we clear our map of selected users
selectedGroupOfUsers.setObject(createPoiMembershipMap(null));
}

Expand Down Expand Up @@ -611,7 +615,7 @@ private boolean submitData() {

private TargetSelectionType getTargetSelectionConfiguration() {
AccessRequestType config = getAccessRequestConfiguration(page);
return config != null ? config.getTargetSelection() : null;
return config != null ? config.getTargetSelection() : new TargetSelectionType();
}

public static class ObjectReferenceProvider extends ChoiceProvider<ObjectReferenceType> {
Expand Down

0 comments on commit 00bd28a

Please sign in to comment.