Skip to content

Commit

Permalink
IQSS#6000. Introduce autocompletion for metadata fields using control…
Browse files Browse the repository at this point in the history
…led vocabulary.
  • Loading branch information
poikilotherm committed Jul 25, 2019
1 parent 221e7fb commit 10f6761
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetField.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ public List<ControlledVocabularyValue> getControlledVocabularyValues() {
public void setControlledVocabularyValues(List<ControlledVocabularyValue> controlledVocabularyValues) {
this.controlledVocabularyValues = controlledVocabularyValues;
}

/**
* Autocomplete backing method, creating a list of matching values
* @param query The users string typed into autocomplete search field
* @return List of matching vocabulary items (containing the query string in their l18n string)
*/
public List<ControlledVocabularyValue> completeVocabulary(String query) {
List<ControlledVocabularyValue> filtered = new ArrayList<>();
for (ControlledVocabularyValue item : this.getControlledVocabularyValues()) {
if (item.getLocaleStrValue().toLowerCase().contains(query.toLowerCase())) {
filtered.add(item);
}
}
return filtered;
}

// HELPER METHODS
public DatasetFieldValue getSingleValue() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/metadataFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@
</ui:fragment>
<!-- MOVED SELECT ONE TO dataFieldForEdit -->
<div jsf:rendered="#{subdsf.datasetFieldType.controlledVocabulary}">
<p:autoComplete value="#{subdsf.controlledVocabularyValues}" converter="controlledVocabularyValueConverter"
multiple="#{subdsf.datasetFieldType.allowMultiples}" forceSelection="true"
var="cvv" itemLabel="#{cvv.localeStrValue}" itemValue="#{cvv}"
completeMethod="#{subdsf.completeVocabulary}">
</p:autoComplete>


<p:selectOneMenu value="#{subdsf.singleControlledVocabularyValue}" converter="controlledVocabularyValueConverter" style="width: auto !important; max-width:100%; min-width:200px;"
rendered="#{!subdsf.datasetFieldType.allowMultiples}">
<f:selectItem itemLabel="#{bundle.select}" itemValue="" noSelectionOption="true"/>
Expand Down

0 comments on commit 10f6761

Please sign in to comment.