Skip to content

Commit

Permalink
preconfigured search filters fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed Sep 9, 2022
1 parent dff17cf commit cef2c98
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 409 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import java.util.Iterator;
import java.util.List;

import com.evolveum.midpoint.web.component.input.CheckPanel;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -35,6 +38,8 @@
import com.evolveum.midpoint.web.util.InfoTooltipBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;

import org.apache.wicket.model.PropertyModel;

public abstract class AbstractSearchItemPanel<S extends AbstractSearchItemWrapper> extends BasePanel<S> {

private static final long serialVersionUID = 1L;
Expand All @@ -44,6 +49,8 @@ public abstract class AbstractSearchItemPanel<S extends AbstractSearchItemWrappe
private static final String ID_SEARCH_ITEM_LABEL = "searchItemLabel";
private static final String ID_HELP = "help";
private static final String ID_REMOVE_BUTTON = "removeButton";
private static final String ID_CHECK_DISABLE_FIELD = "checkDisable";


public AbstractSearchItemPanel(String id, IModel<S> model) {
super(id, model);
Expand Down Expand Up @@ -106,9 +113,25 @@ public boolean isVisible() {
}
});
}
searchItemField.add(new VisibleBehaviour(this::isSearchItemFieldVisible));
searchItemField.setOutputMarkupId(true);
searchItemContainer.add(searchItemField);

CheckPanel checkPanel = new CheckPanel(ID_CHECK_DISABLE_FIELD, new PropertyModel<>(getModel(), AbstractSearchItemWrapper.F_APPLY_FILTER));
(checkPanel).getBaseFormComponent().add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
searchPerformed(ajaxRequestTarget);
}
});
checkPanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
checkPanel.add(new VisibleBehaviour(this::isCheckPanelVisible));

checkPanel.setOutputMarkupId(true);
searchItemContainer.add(checkPanel);

AjaxSubmitButton removeButton = new AjaxSubmitButton(ID_REMOVE_BUTTON) {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -140,6 +163,15 @@ protected boolean canRemoveSearchItem() {
return getModelObject().canRemoveSearchItem();
}

private boolean isSearchItemFieldVisible() {
return getModelObject().isVisible() && noFilterOrHasParameters();
}

private boolean noFilterOrHasParameters() {
return getModelObject().getPredefinedFilter() == null ||
StringUtils.isNotEmpty(getModelObject().getParameterName());
}

protected IModel<String> createLabelModel() {
return StringUtils.isNotEmpty(getModelObject().getName()) ? createStringResource(getModelObject().getName()) : Model.of("");
}
Expand All @@ -149,6 +181,8 @@ private IModel<String> createTitleModel() {
}

protected void searchPerformed(AjaxRequestTarget target){
SearchPanel panel = findParent(SearchPanel.class);
panel.searchPerformed(target);
}

private void deletePerformed(AjaxRequestTarget target) {
Expand Down Expand Up @@ -208,4 +242,7 @@ protected IModel<List<DisplayableValue<?>>> createEnumChoices(Class<? extends En

}

private boolean isCheckPanelVisible() {
return getModelObject().getPredefinedFilter() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.web.component.util.SelectableRow;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SearchBoxModeType;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

import java.io.Serializable;
import java.util.Objects;
Expand All @@ -26,12 +28,15 @@ public abstract class AbstractSearchItemWrapper<T extends Serializable> implemen
public static final String F_NAME = "name";
public static final String F_HELP = "help";
public static final String F_TITLE = "title";
public static final String F_APPLY_FILTER = "applyFilter";

private DisplayableValue<T> value;
private boolean applyFilter;
private boolean selected;
private boolean visible;
private boolean canConfigure = true;
private SearchFilterType predefinedFilter;
private ExpressionType filterExpression;

String parameterName;
Class<T> parameterValueType;
Expand Down Expand Up @@ -96,7 +101,7 @@ public void setValue(DisplayableValue<T> value) {
}

public boolean isApplyFilter(SearchBoxModeType searchBoxMode) {
return isVisible();
return applyFilter && isVisible();
}

public void setApplyFilter(boolean applyFilter) {
Expand All @@ -113,6 +118,22 @@ public void setSelected(boolean selected) {
this.selected = selected;
}

public SearchFilterType getPredefinedFilter() {
return predefinedFilter;
}

public void setPredefinedFilter(SearchFilterType predefinedFilter) {
this.predefinedFilter = predefinedFilter;
}

public ExpressionType getFilterExpression() {
return filterExpression;
}

public void setFilterExpression(ExpressionType filterExpression) {
this.filterExpression = filterExpression;
}

@Override
public boolean equals(Object o) {
return false;
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit cef2c98

Please sign in to comment.