Skip to content

Commit

Permalink
Merge pull request kitodo#5810 from markusweigelt/filter-select
Browse files Browse the repository at this point in the history
Filtering of single and multiple select fields
  • Loading branch information
solth authored Dec 7, 2023
2 parents 2523d03 + 4df4798 commit 71e2e14
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ default boolean isComplex() {
*/
boolean isEditable();

/**
* Returns whether values under this key can be filtered in this view.
*
* @return whether values can be filtered
*/
boolean isFilterable();

/**
* Returns whether the value corresponds to the value range. The value range
* can be determined in various ways. Integers or dates must parse, it may
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ public boolean isEditable() {
return settings.isEditable(declaration.getId());
}

@Override
public boolean isFilterable() {
InputType inputType = getInputType();
if (InputType.MULTIPLE_SELECTION.equals(inputType) || InputType.ONE_LINE_SINGLE_SELECTION.equals(inputType)) {
return settings.isFilterable(declaration.getId());
}
return false;
}

/**
* Checks if a URI is in the configured namespace, if one has been
* specified. Typically, a namespace is used as a URL prefix. For namespaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ boolean isEditable(String keyId) {
}
}

/**
* Whether the key is filterable.
*
* @param keyId
* key for which the query is
* @return whether the key is filterable
*/
boolean isFilterable(String keyId) {
if (currentSettings.containsKey(keyId)) {
return currentSettings.get(keyId).isFilterable();
}
return false;
}


/**
* Whether the key is excluded.
*
Expand Down Expand Up @@ -176,6 +191,7 @@ private List<Setting> merge(Collection<Setting> currentSettings, Collection<Sett
other.getAlwaysShowing() != null ? other.getAlwaysShowing() : current.getAlwaysShowing());
merged.setEditable(other.getEditable() != null ? other.getEditable() : current.getEditable());
merged.setExcluded(other.getExcluded() != null ? other.getExcluded() : current.getExcluded());
merged.setFilterable(other.getFilterable() != null ? other.getFilterable() : current.getFilterable());
merged.setMultiline(other.getMultiline() != null ? other.getMultiline() : current.getMultiline());
merged.setReimport(other.getReimport() != null ? other.getReimport() : current.getReimport());
merged.setSettings(merge(current.getSettings(), other.getSettings()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public class Setting {
@XmlAttribute
private Boolean editable;

/**
* This will present an input filter for the list of options in select fields if set to true. When entering text,
* the filter will display only those options that contain the entered text. This attribute exclusively works with
* keys that have an option list; for other keys, no action will occur.
*/
@XmlAttribute
private Boolean filterable;

/**
* This will hide a field, even if a value has been entered for this field.
* Normally, there are rules in the ruleset that say which fields are
Expand Down Expand Up @@ -121,6 +129,18 @@ public Boolean getExcluded() {
return excluded;
}

/**
* Returns the value “filterable” if one is set. This getter returns
* {@code null} if the attribute was not entered. This is needed, for
* example, when merging attributes. If only the simple value (with default,
* if no value was specified) is needed, use {@link #isFilterable()}.
*
* @return the value “filterable”, if set, else {@code null}
*/
public Boolean getFilterable() {
return filterable;
}

/**
* Returns the key whose representation is influenced.
*
Expand Down Expand Up @@ -182,6 +202,16 @@ public boolean isEditable() {
return editable != null ? editable : true;
}

/**
* Returns the “filterable” value or otherwise the default value if the
* attribute is not set.
*
* @return the “filterable” value or its default value
*/
public boolean isFilterable() {
return filterable != null ? filterable : false;
}

/**
* Returns the “excluded” value or otherwise the default value if the
* attribute is not set.
Expand Down Expand Up @@ -224,6 +254,17 @@ public void setEditable(Boolean editable) {
this.editable = editable;
}

/**
* This sets the “filterable” value. If you set the value to {@code null}, no
* attribute is written.
*
* @param filterable
* “filterable” value to set
*/
public void setFilterable(Boolean filterable) {
this.filterable = filterable;
}

/**
* This sets the “excluded” value. If you set the value to {@code null}, no
* attribute is written.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.BiConsumer;

import javax.faces.model.SelectItem;
Expand Down Expand Up @@ -111,6 +112,15 @@ public String getInput() {
}
}

/**
* Returns if the field may be filterable.
*
* @return whether the field is filterable
*/
public boolean isFilterable() {
return Objects.isNull(settings) || settings.isFilterable();
}

/**
* Returns the select item objects required to display the list.
*
Expand Down
23 changes: 23 additions & 0 deletions Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css
Original file line number Diff line number Diff line change
Expand Up @@ -2964,11 +2964,34 @@ Column content
max-width: 100%;
}

#editForm\:processFromTemplateTabView\:metadataTable .ui-selectlistbox-filter-container .ui-selectlistbox-filter,
#metadataAccordion\:metadata\:metadataTable_data .ui-inputfield.ui-selectmanymenu.read-only,
#metadataAccordion\:metadata\:metadataTable_data .ui-selectlistbox-filter-container .ui-selectlistbox-filter,
#metadataAccordion\:metadata\:metadataTable_data .ui-selectoneradio.read-only {
max-width: unset;
}

#editForm\:processFromTemplateTabView\:metadataTable .ui-selectlistbox-filter-container .ui-icon-search,
#metadataAccordion\:metadata\:metadataTable_data .ui-selectlistbox-filter-container .ui-icon-search {
top: 8px;
right: 6px;
text-indent: unset;
background: none;
}

#editForm\:processFromTemplateTabView\:metadataTable .ui-selectlistbox-filter-container .ui-icon-search::after,
#metadataAccordion\:metadata\:metadataTable_data .ui-selectlistbox-filter-container .ui-icon-search::after {
font-family: FontAwesome;
content: "\f002";
text-indent: unset;
color: var(--blue);
}

#editForm\:processFromTemplateTabView\:metadataTable .ui-selectlistbox-filter-container .ui-selectlistbox-filter,
#metadataAccordion\:metadata\:metadataTable_data .ui-selectlistbox-filter-container .ui-selectlistbox-filter {
padding-right: 26px;
}

#metadataAccordion\:metadata\:metadataTable_data .ui-selectoneradio {
display: inline-table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@
styleClass="#{not item.editable or readOnly ? 'read-only disabled' : ''}"
disabled="#{not item.editable or readOnly}"
required="#{item.required and (not empty param['editForm:save'] or not empty param['editForm:saveContinue'])}"
showCheckbox="true">
showCheckbox="true"
filter="#{item.filterable}"
filterMatchMode="contains">
<f:selectItems value="#{item.items}"/>
<p:ajax event="change"
oncomplete="preserveMetadata(); #{item.leading ? (request.requestURI.contains('metadataEditor') ? 'updateTitleMetadataWithTable();' : 'updateProcessMetadata();') : (request.requestURI.contains('metadataEditor') ? 'updateTitleMetadata();' : '')}"/>
Expand All @@ -139,7 +141,9 @@
autoWidth="false"
disabled="#{not item.editable or readOnly}"
required="#{item.required and (not empty param['editForm:save'] or not empty param['editForm:saveContinue'])}"
styleClass="#{readOnly ? 'read-only' : ''}">
styleClass="#{readOnly ? 'read-only' : ''}"
filter="#{item.filterable}"
filterMatchMode="contains">
<f:selectItem itemValue="#{null}"
itemDisabled="#{item.required}"
itemLabel="#{msgs.notSelected}"
Expand Down

0 comments on commit 71e2e14

Please sign in to comment.