Skip to content

Commit

Permalink
adding small improvements for selection resource template panel of ne…
Browse files Browse the repository at this point in the history
…w resource wizard
  • Loading branch information
skublik committed Jul 14, 2022
1 parent 143e6fb commit 534cd37
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

package com.evolveum.midpoint.gui.impl.component.tile;

import org.jetbrains.annotations.NotNull;

import java.io.Serializable;

/**
* Created by Viliam Repan (lazyman).
*/
public class Tile<T extends Serializable> implements Serializable {
public class Tile<T extends Serializable> implements Comparable<Tile>, Serializable {

private String icon;

Expand Down Expand Up @@ -66,4 +68,9 @@ public T getValue() {
public void setValue(T value) {
this.value = value;
}

@Override
public int compareTo(@NotNull Tile o) {
return this.title.compareTo(o.getTitle());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
</div>
<span class="mt-4 text-gray font-weight-bold text-center" wicket:id="title"/>
<span class="mt-4 text-secondary text-center" wicket:id="description"/>
<div class="mt-auto">
<span class="mt-4 text-center badge badge-light text-primary" wicket:id="tag"/>
</div>
</wicket:panel>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ public class ResourceTilePanel<O> extends BasePanel<TemplateTile<O>> {
private static final String ID_TITLE = "title";
private static final String ID_DESCRIPTION = "description";

private static final String ID_TAG = "tag";

public ResourceTilePanel(String id, IModel<TemplateTile<O>> model) {
super(id, model);

initLayout();
}

private void initLayout() {
add(AttributeAppender.append("class", "selectable-tile flex-grow-1 d-flex flex-column align-items-center bg-white rounded p-3 pb-5 pt-4 h-100"));
add(AttributeAppender.append(
"class",
"card mb-0 col-12 catalog-tile-panel d-flex flex-column align-items-center bg-white p-3 pb-5 pt-4 h-100 mb-0"));
setOutputMarkupId(true);

WebMarkupContainer icon = new WebMarkupContainer(ID_ICON);
Expand All @@ -48,13 +52,19 @@ private void initLayout() {
return title != null ? getString(title, null, title) : null;
}));

Label description = new Label(ID_DESCRIPTION, () -> {
String title = getModelObject().getDescription();
return title != null ? getString(title, null, title) : null;
Label descriptionPanel = new Label(ID_DESCRIPTION, () -> {
String description = getModelObject().getDescription();
return description != null ? getString(description, null, description) : null;
});
description.add(new VisibleBehaviour(() -> getModelObject().getDescription() != null));
descriptionPanel.add(new VisibleBehaviour(() -> getModelObject().getDescription() != null));
add(descriptionPanel);

add(description);
Label tagPanel = new Label(ID_TAG, () -> {
String tag = getModelObject().getTag();
return tag != null ? getString(tag, null, tag) : null;
});
tagPanel.add(new VisibleBehaviour(() -> getModelObject().getTag() != null));
add(tagPanel);

add(new AjaxEventBehavior("click") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import com.evolveum.midpoint.gui.impl.component.tile.Tile;

import org.jetbrains.annotations.NotNull;

/**
* @author lskublik
*/
Expand All @@ -18,6 +20,8 @@ public class TemplateTile<O> extends Tile {

private String description;

private String tag;

public TemplateTile(String icon, String title, O templateObject) {
super(icon, title);
this.templateObject = templateObject;
Expand All @@ -35,4 +39,22 @@ public TemplateTile description(String description) {
this.description = description;
return this;
}

public String getTag() {
return tag;
}

public TemplateTile tag(String tag) {
this.tag = tag;
return this;
}

@Override
public int compareTo(@NotNull Tile o) {
int comparison = this.getTitle().compareTo(o.getTitle());
if (comparison == 0 && o instanceof TemplateTile) {
return this.getTag().compareTo(((TemplateTile)o).getTag());
}
return comparison;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ <h3 class="m-0 pt-1">
</h3>
</div>
<div class="d-flex mt-3">
<div wicket:id="type" style="width: 300px;"/>
<div class="my-auto d-flex ml-auto" wicket:id="search"/>
</div>
</div>

<div class="row justify-content-start mt-3 text-break mb-5 pl-3 pt-3" wicket:id="tileContainer">
<div class="d-flex flex-wrap justify-content-start text-break mt-3 mb-5 mr-n3 pt-3" wicket:id="tileContainer">
<div wicket:id="tiles" class="col-xs-6 col-sm-6 col-md-4 col-lg-3 col-xl-5i col-xxl-2 pr-3 pb-3 p-0">
<div class="catalog-tile-panel col-12 selectable-tile" wicket:id="tile"/>
<div wicket:id="tile"/>
</div>
</div>
</wicket:panel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
import com.evolveum.midpoint.gui.impl.component.search.SearchPanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.ResourceTilePanel;
import com.evolveum.midpoint.gui.impl.page.admin.resource.component.TemplateTile;
import com.evolveum.midpoint.gui.impl.util.GuiDisplayNameUtil;
import com.evolveum.midpoint.prism.CloneStrategy;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;
import com.evolveum.midpoint.web.session.PageStorage;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand All @@ -38,12 +37,13 @@
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class CreateResourceTemplatePanel extends BasePanel<PrismObject<ResourceType>> {
Expand All @@ -53,11 +53,30 @@ public abstract class CreateResourceTemplatePanel extends BasePanel<PrismObject<
private static final String ID_TILE = "tile";
private static final String ID_SEARCH = "search";
private static final String ID_BACK = "back";
private static final String ID_TYPE_FIELD = "type";
private static final String CREATE_RESOURCE_TEMPLATE_STORAGE_KEY = "resourceTemplateStorage";

private enum TemplateType {
ALL(AssignmentHolderType.class),
TEMPLATE(ResourceType.class),
CONNECTOR(ConnectorType.class);

private final Class<AssignmentHolderType> type;

private TemplateType(Class<? extends AssignmentHolderType> type) {
this.type = (Class<AssignmentHolderType>) type;
}

public Class<AssignmentHolderType> getType() {
return type;
}
}

private LoadableDetachableModel<Search<AssignmentHolderType>> searchModel;
private LoadableDetachableModel<List<TemplateTile<ResourceTemplate>>> tilesModel;

private Model<TemplateType> templateType = Model.of(TemplateType.ALL);

public CreateResourceTemplatePanel(String id) {
super(id);
}
Expand All @@ -83,7 +102,8 @@ private void initSearchModel() {
protected Search<AssignmentHolderType> load() {
PageStorage storage = getStorage();
if (storage.getSearch() == null) {
Search<AssignmentHolderType> search = SearchFactory.createSearch(AssignmentHolderType.class, getPageBase());
Search<AssignmentHolderType> search
= SearchFactory.createSearch(templateType.getObject().getType(), getPageBase());
storage.setSearch(search);
return search;
}
Expand All @@ -96,6 +116,20 @@ protected Search<AssignmentHolderType> load() {
private void initLayout() {
setOutputMarkupId(true);

DropDownChoicePanel<TemplateType> type
= WebComponentUtil.createEnumPanel(TemplateType.class, ID_TYPE_FIELD, templateType, this, false);
type.getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
super.onUpdate(target);
searchModel.detach();
tilesModel.detach();
target.add(CreateResourceTemplatePanel.this.get(ID_SEARCH));
target.add(getTilesContainer());
}
});
add(type);

AjaxLink back = new AjaxLink<>(ID_BACK) {

@Override
Expand Down Expand Up @@ -123,6 +157,7 @@ protected void onClick(AjaxRequestTarget target) {
}
};
tilesContainer.add(tiles);

}

private SearchPanel<AssignmentHolderType> initSearch() {
Expand Down Expand Up @@ -162,24 +197,15 @@ private void onTemplateChosePerformed(TemplateTile<ResourceTemplate> tile, AjaxR
if (resourceTemplate != null) {
if (QNameUtil.match(ConnectorType.COMPLEX_TYPE, resourceTemplate.type)) {
obj.asObjectable().beginConnectorRef()
.oid(resourceTemplate.oid)
.type(ConnectorType.COMPLEX_TYPE);
.oid(resourceTemplate.oid)
.type(ConnectorType.COMPLEX_TYPE);
} else if (QNameUtil.match(ResourceType.COMPLEX_TYPE, resourceTemplate.type)) {
Task task = getPageBase().createSimpleTask("load resource template");
OperationResult result = task.getResult();
// @Nullable PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(
// ResourceType.class,
// resourceTemplate.oid,
// getPageBase(),
// task,
// result);
// if (resource != null) {
obj.asObjectable().beginSuper().beginResourceRef()
.oid(resourceTemplate.oid)
.type(ResourceType.COMPLEX_TYPE);
// obj = resource.cloneComplex(CloneStrategy.REUSE);
getPageBase().getModelInteractionService().expandConfigurationObject(obj, task, result);
// }
getPageBase().getModelInteractionService().expandConfigurationObject(obj, task, result);

result.computeStatus();
if (!result.isSuccess()) {
Expand All @@ -206,70 +232,79 @@ protected List<TemplateTile<ResourceTemplate>> load() {

Task loadResourceTemplateTask = getPageBase().createSimpleTask("load resource templates");

@NotNull List<PrismObject<ConnectorType>> connectors =
WebModelServiceUtils.searchObjects(
ConnectorType.class,
searchModel.getObject().createObjectQuery(getPageBase()),
loadResourceTemplateTask.getResult(),
getPageBase());

if (CollectionUtils.isNotEmpty(connectors)) {
connectors.forEach(connector -> {
@NotNull ConnectorType connectorObject = connector.asObjectable();
String title;
if (connectorObject.getDisplayName() == null || connectorObject.getDisplayName().isEmpty()) {
title = connectorObject.getName().getOrig();
} else {
title = connectorObject.getDisplayName().getOrig();
}
tiles.add(
new TemplateTile(
GuiStyleConstants.CLASS_OBJECT_CONNECTOR_ICON,
title,
new ResourceTemplate(connector.getOid(), ConnectorType.COMPLEX_TYPE))
.description(getDescriptionForConnectorType(connectorObject)));
});
if (TemplateType.ALL.equals(templateType.getObject())
|| TemplateType.CONNECTOR.equals(templateType.getObject())) {
@NotNull List<PrismObject<ConnectorType>> connectors =
WebModelServiceUtils.searchObjects(
ConnectorType.class,
searchModel.getObject().createObjectQuery(getPageBase()),
loadResourceTemplateTask.getResult(),
getPageBase());

if (CollectionUtils.isNotEmpty(connectors)) {
connectors.forEach(connector -> {
@NotNull ConnectorType connectorObject = connector.asObjectable();
String title;
if (connectorObject.getDisplayName() == null || connectorObject.getDisplayName().isEmpty()) {
title = connectorObject.getName().getOrig();
} else {
title = connectorObject.getDisplayName().getOrig();
}
tiles.add(
new TemplateTile(
GuiStyleConstants.CLASS_OBJECT_CONNECTOR_ICON,
title,
new ResourceTemplate(connector.getOid(), ConnectorType.COMPLEX_TYPE))
.description(getDescriptionForConnectorType(connectorObject))
.tag(connectorObject.getConnectorVersion()));
});
}
}

@NotNull List<PrismObject<ResourceType>> resources =
WebModelServiceUtils.searchObjects(
ResourceType.class,
searchModel.getObject().createObjectQuery(
if (TemplateType.ALL.equals(templateType.getObject())
|| TemplateType.TEMPLATE.equals(templateType.getObject())) {
@NotNull List<PrismObject<ResourceType>> resources =
WebModelServiceUtils.searchObjects(
ResourceType.class,
searchModel.getObject().createObjectQuery(
// null,
getPageBase() //,
getPageBase() //,
// PrismContext.get()
// .queryFor(ResourceType.class)
// .item(ResourceType.F_TEMPLATE) //TODO uncomment after adding to repo
// .eq(true).build()
),
loadResourceTemplateTask.getResult(),
getPageBase());

resources.removeIf(resource -> !Boolean.TRUE.equals(resource.asObjectable().isTemplate())); //TODO remove after adding to repo

if (CollectionUtils.isNotEmpty(resources)) {
resources.forEach(resource -> {
String title = WebComponentUtil.getDisplayNameOrName(resource);

DisplayType display =
GuiDisplayTypeUtil.getDisplayTypeForObject(resource, loadResourceTemplateTask.getResult(), getPageBase());
tiles.add(
new TemplateTile(
WebComponentUtil.getIconCssClass(display),
title,
new ResourceTemplate(resource.getOid(), ResourceType.COMPLEX_TYPE))
.description(resource.asObjectable().getDescription()));
});
),
loadResourceTemplateTask.getResult(),
getPageBase());

resources.removeIf(resource -> !Boolean.TRUE.equals(resource.asObjectable().isTemplate())); //TODO remove after adding to repo

if (CollectionUtils.isNotEmpty(resources)) {
resources.forEach(resource -> {
String title = WebComponentUtil.getDisplayNameOrName(resource);

DisplayType display =
GuiDisplayTypeUtil.getDisplayTypeForObject(resource, loadResourceTemplateTask.getResult(), getPageBase());
tiles.add(
new TemplateTile(
WebComponentUtil.getIconCssClass(display),
title,
new ResourceTemplate(resource.getOid(), ResourceType.COMPLEX_TYPE))
.description(resource.asObjectable().getDescription())
.tag(getPageBase().createStringResource("CreateResourceTemplatePanel.template").getString()));
});
}
}

Collections.sort(tiles);
return tiles;
}
};
}

private String getDescriptionForConnectorType(@NotNull ConnectorType connectorObject) {
if (connectorObject.getDescription() == null) {
return connectorObject.getName() + " version: " + connectorObject.getConnectorVersion();
return connectorObject.getName().getOrig();
}
return connectorObject.getDescription();
}
Expand Down

0 comments on commit 534cd37

Please sign in to comment.