Skip to content

Commit

Permalink
more filtering options (IsRangeFilter, showFilterIncrementButtons, au…
Browse files Browse the repository at this point in the history
…toFilter value)

#705
  • Loading branch information
teosarca committed Nov 27, 2017
1 parent 02a4f8d commit 6f3e06e
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static final Builder builder()
private final PanelLayoutType parametersLayoutType;
private final Map<String, DocumentFilterParamDescriptor> parametersByName;
private final List<DocumentFilterParam> internalParameters;
private final boolean autoFilter;

private final Map<String, Object> debugProperties;

Expand All @@ -80,6 +81,7 @@ private DocumentFilterDescriptor(final Builder builder)
parametersLayoutType = builder.getParametersLayoutType();
parametersByName = builder.buildParameters();
internalParameters = ImmutableList.copyOf(builder.internalParameters);
autoFilter = parametersByName.values().stream().anyMatch(DocumentFilterParamDescriptor::isAutoFilter);

debugProperties = builder.debugProperties == null ? ImmutableMap.of() : ImmutableMap.copyOf(builder.debugProperties);
}
Expand Down Expand Up @@ -139,6 +141,11 @@ public Map<String, Object> getDebugProperties()
{
return debugProperties;
}

public boolean isAutoFilter()
{
return autoFilter;
}

//
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import de.metas.i18n.IMsgBL;
import de.metas.i18n.ITranslatableString;
import de.metas.ui.web.document.filter.DocumentFilterParam.Operator;
import de.metas.ui.web.window.descriptor.DocumentFieldDefaultFilterDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
Expand Down Expand Up @@ -103,7 +104,7 @@ private ImmutableDocumentFilterDescriptorsProvider createFiltersProvider_Default

final List<DocumentFieldDescriptor> filteringFields = fields.stream()
.filter(DocumentFieldDescriptor::isDefaultFilterField)
.sorted(Ordering.natural().onResultOf(field -> field.getDefaultFilterFieldSeqNo()))
.sorted(Ordering.natural().onResultOf(field -> field.getDefaultFilterInfo().getSeqNo()))
.collect(ImmutableList.toImmutableList());

for (final DocumentFieldDescriptor field : filteringFields)
Expand Down Expand Up @@ -131,6 +132,7 @@ private final DocumentFilterParamDescriptor.Builder createFilterParam(final Docu
final ITranslatableString displayName = field.getCaption();
final String fieldName = field.getFieldName();
final DocumentFieldWidgetType widgetType = field.getWidgetType();
final DocumentFieldDefaultFilterDescriptor filteringInfo = field.getDefaultFilterInfo();

final LookupDescriptor lookupDescriptor = field.getLookupDescriptor(LookupDescriptorProvider.LookupScope.DocumentFilter);

Expand All @@ -139,7 +141,7 @@ private final DocumentFilterParamDescriptor.Builder createFilterParam(final Docu
{
operator = Operator.LIKE_I;
}
else if (widgetType.isRangeFilteringSupported())
else if (filteringInfo.isRangeFilter())
{
operator = Operator.BETWEEN;
}
Expand All @@ -154,7 +156,9 @@ else if (widgetType.isRangeFilteringSupported())
.setWidgetType(widgetType)
.setOperator(operator)
.setLookupDescriptor(lookupDescriptor)
.setMandatory(false);
.setMandatory(false)
.setShowIncrementDecrementButtons(filteringInfo.isShowFilterIncrementButtons())
.setAutoFilterInitialValue(filteringInfo.getAutoFilterInitialValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.adempiere.util.Check;

import com.google.common.base.MoreObjects;

import de.metas.i18n.ITranslatableString;
import de.metas.i18n.ImmutableTranslatableString;
import de.metas.ui.web.document.filter.DocumentFilterParam.Operator;
Expand All @@ -13,6 +11,7 @@
import de.metas.ui.web.window.descriptor.factory.standard.DescriptorsFactoryHelper;
import de.metas.ui.web.window.model.lookup.LookupDataSource;
import de.metas.ui.web.window.model.lookup.LookupDataSourceFactory;
import lombok.Value;

/*
* #%L
Expand All @@ -36,6 +35,7 @@
* #L%
*/

@Value
public final class DocumentFilterParamDescriptor
{
public static final Builder builder()
Expand All @@ -49,19 +49,20 @@ public static final Builder builder()
private final DocumentFieldWidgetType widgetType;
private final Class<?> valueClass;
private final ITranslatableString displayName;
private final boolean showIncrementDecrementButtons;

private final Operator operator;
private final Object defaultValue;
private final Object defaultValueTo;

private final boolean mandatory;
private final LookupDescriptor lookupDescriptor;

private final boolean mandatory;
public static final String AUTOFILTER_INITIALVALUE_DATE_NOW = new String("NOW");
private final Object autoFilterInitialValue;

private DocumentFilterParamDescriptor(final Builder builder)
{
super();

joinAnd = builder.joinAnd;

parameterName = builder.parameterName;
Expand All @@ -77,6 +78,8 @@ private DocumentFilterParamDescriptor(final Builder builder)
displayName = builder.getDisplayName();
Check.assumeNotNull(displayName, "Parameter displayNameTrls is not null");

showIncrementDecrementButtons = builder.showIncrementDecrementButtons;

operator = builder.operator;

defaultValue = builder.defaultValue;
Expand All @@ -85,75 +88,20 @@ private DocumentFilterParamDescriptor(final Builder builder)
lookupDescriptor = builder.lookupDescriptor;

mandatory = builder.mandatory;
}

@Override
public String toString()
{
return MoreObjects.toStringHelper(this)
.omitNullValues()
.add("join", joinAnd ? "AND" : "OR")
.add("parameterName", parameterName)
.add("fieldName", fieldName)
.add("widgetType", widgetType)
.add("operator", operator)
.add("defaultValue", defaultValue)
.add("defaultValueTo", defaultValueTo)
.add("lookupDescriptor", lookupDescriptor)
.add("required", mandatory)
.toString();
}

public boolean isJoinAnd()
{
return joinAnd;
}

public String getParameterName()
{
return parameterName;
}

public String getFieldName()
{
return fieldName;
}

public DocumentFieldWidgetType getWidgetType()
{
return widgetType;
}

public Class<?> getValueClass()
{
return valueClass;
autoFilterInitialValue = builder.autoFilterInitialValue;
}

public String getDisplayName(final String adLanguage)
{
return displayName.translate(adLanguage);
}

public Operator getOperator()
{
return operator;
}

public boolean isRange()
{
return operator != null && operator.isRangeOperator();
}

public Object getDefaultValue()
{
return defaultValue;
}

public Object getDefaultValueTo()
{
return defaultValueTo;
}

public LookupDataSource getLookupDataSource()
{
return LookupDataSourceFactory.instance.getLookupDataSource(lookupDescriptor);
Expand All @@ -168,16 +116,22 @@ private final LookupDataSource getLookupDataSourceOrNull()
return LookupDataSourceFactory.instance.getLookupDataSource(lookupDescriptor);
}

public boolean isMandatory()
public Object convertValueFromJson(final Object jsonValue)
{
return mandatory;
return DocumentFieldDescriptor.convertToValueClass(getFieldName(), jsonValue, getWidgetType(), getValueClass(), getLookupDataSourceOrNull());
}

public Object convertValueFromJson(final Object jsonValue)
public boolean isAutoFilter()
{
return DocumentFieldDescriptor.convertToValueClass(getFieldName(), jsonValue, getWidgetType(), getValueClass(), getLookupDataSourceOrNull());
return autoFilterInitialValue != null;
}

public boolean isAutoFilterInitialValueIsDateNow()
{
return widgetType.isDateOrTime() && AUTOFILTER_INITIALVALUE_DATE_NOW.equals(autoFilterInitialValue);
}


public static final class Builder
{
private boolean joinAnd = true;
Expand All @@ -190,10 +144,12 @@ public static final class Builder
private Object defaultValueTo;
private LookupDescriptor lookupDescriptor;
private boolean mandatory = false;
private boolean showIncrementDecrementButtons;

private Object autoFilterInitialValue;

private Builder()
{
super();
}

/* package */DocumentFilterParamDescriptor build()
Expand Down Expand Up @@ -282,6 +238,18 @@ public Builder setMandatory(final boolean mandatory)
this.mandatory = mandatory;
return this;
}

public Builder setShowIncrementDecrementButtons(final boolean showIncrementDecrementButtons)
{
this.showIncrementDecrementButtons = showIncrementDecrementButtons;
return this;
}

public Builder setAutoFilterInitialValue(Object autoFilterInitialValue)
{
this.autoFilterInitialValue = autoFilterInitialValue;
return this;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ private static final JSONDocumentFilterParamDescriptor of(final DocumentFilterPa
@JsonProperty("type")
private final JSONLayoutType type;

@JsonProperty("showIncrementDecrementButtons")
@JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean showIncrementDecrementButtons;

private JSONDocumentFilterParamDescriptor(final DocumentFilterParamDescriptor param, final JSONOptions jsonOpts)
{
parameterName = param.getParameterName();
Expand All @@ -112,6 +116,8 @@ private JSONDocumentFilterParamDescriptor(final DocumentFilterParamDescriptor pa
readonly = false;

type = toJSONLayoutType(widgetType);

showIncrementDecrementButtons = param.isShowIncrementDecrementButtons() ? Boolean.TRUE : null;
}

private static final JSONLayoutType toJSONLayoutType(final JSONLayoutWidgetType widgetType)
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/de/metas/ui/web/view/CreateViewRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static final Builder filterViewBuilder(
.setStickyFilters(view.getStickyFilters())
.setFiltersFromJSON(jsonFilters)
// .setFilterOnlyIds(filterOnlyIds) // N/A on this level.
.setUseAutoFilters(false)
.addActions(view.getActions())
.addAdditionalRelatedProcessDescriptors(view.getAdditionalRelatedProcessDescriptors());
}
Expand All @@ -108,6 +109,7 @@ public static final Builder deleteStickyFilterBuilder(
.setStickyFilters(stickyFilters)
.setFilters(view.getFilters())
// .setFilterOnlyIds(filterOnlyIds) // N/A on this level.
.setUseAutoFilters(false)
.addActions(view.getActions())
.addAdditionalRelatedProcessDescriptors(view.getAdditionalRelatedProcessDescriptors());
}
Expand Down Expand Up @@ -143,6 +145,8 @@ public static final Builder deleteStickyFilterBuilder(
*/
@Deprecated
Set<Integer> filterOnlyIds;

boolean useAutoFilters;

ViewActionDescriptorsList actions;
ImmutableList<RelatedProcessDescriptor> additionalRelatedProcessDescriptors;
Expand All @@ -159,6 +163,7 @@ private CreateViewRequest(final Builder builder)
filterOnlyIds = builder.getFilterOnlyIds();
filters = builder.getFilters();
stickyFilters = builder.getStickyFilters();
useAutoFilters = builder.isUseAutoFilters();

actions = builder.getActions();
additionalRelatedProcessDescriptors = ImmutableList.copyOf(builder.getAdditionalRelatedProcessDescriptors());
Expand Down Expand Up @@ -229,6 +234,7 @@ public static final class Builder

private List<DocumentFilter> stickyFilters;
private DocumentFiltersList filters;
private boolean useAutoFilters;

private ViewActionDescriptorsList actions = ViewActionDescriptorsList.EMPTY;
private final List<RelatedProcessDescriptor> additionalRelatedProcessDescriptors = new ArrayList<>();
Expand Down Expand Up @@ -358,6 +364,17 @@ private Set<Integer> getFilterOnlyIds()
return filterOnlyIds == null ? ImmutableSet.of() : ImmutableSet.copyOf(filterOnlyIds);
}

public Builder setUseAutoFilters(boolean useAutoFilters)
{
this.useAutoFilters = useAutoFilters;
return this;
}

private boolean isUseAutoFilters()
{
return useAutoFilters;
}

public Builder addActionsFromUtilityClass(final Class<?> utilityClass)
{
final ViewActionDescriptorsList actionsToAdd = ViewActionDescriptorsFactory.instance.getFromClass(utilityClass);
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/de/metas/ui/web/view/DefaultView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.metas.ui.web.view;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -519,7 +520,7 @@ public static final class Builder
private final IViewDataRepository viewDataRepository;

private LinkedHashMap<String, DocumentFilter> _stickyFiltersById;
private List<DocumentFilter> _filters;
private LinkedHashMap<String, DocumentFilter> _filtersById = new LinkedHashMap<>();

private Builder(@NonNull final IViewDataRepository viewDataRepository)
{
Expand Down Expand Up @@ -632,7 +633,8 @@ private ImmutableList<DocumentFilter> getStickyFilters()

public Builder setFilters(final List<DocumentFilter> filters)
{
_filters = filters;
_filtersById.clear();
filters.forEach(filter -> _filtersById.put(filter.getFilterId(), filter));
return this;
}

Expand All @@ -644,7 +646,18 @@ public Builder setFiltersFromJSON(final List<JSONDocumentFilter> jsonFilters)

private ImmutableList<DocumentFilter> getFilters()
{
return _filters == null ? ImmutableList.of() : ImmutableList.copyOf(_filters);
return _filtersById.isEmpty() ? ImmutableList.of() : ImmutableList.copyOf(_filtersById.values());
}

public boolean hasFilters()
{
return !_filtersById.isEmpty();
}

public Builder addFiltersIfAbsent(final Collection<DocumentFilter> filters)
{
filters.forEach(filter -> _filtersById.putIfAbsent(filter.getFilterId(), filter));
return this;
}
}
}
Loading

0 comments on commit 6f3e06e

Please sign in to comment.