Adds subtitle to external dropdown on Dataset Description editor. (Issue #139)

This commit is contained in:
gkolokythas 2019-07-29 12:26:08 +03:00
parent d1c04289ce
commit 65ba88f544
5 changed files with 50 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import eu.eudat.logic.managers.DatasetProfileManager;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.components.commons.datafield.AutoCompleteData;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem;
import eu.eudat.models.data.helpers.responses.ResponseItem;
@ -68,7 +69,7 @@ public class DatasetProfileController extends BaseController {
eu.eudat.data.entities.DatasetProfile datasetProfile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(lookupItem.getCriteria().getProfileID()));
eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field modelfield = this.datasetProfileManager.queryForField(datasetProfile.getDefinition(), lookupItem.getCriteria().getFieldID());
AutoCompleteData data = (AutoCompleteData) modelfield.getData();
List<Tuple<String, String>> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
List<ExternalAutocompleteFieldModel> items = this.datasetProfileManager.getAutocomplete(data, lookupItem.getCriteria().getLike());
return ResponseEntity.status(HttpStatus.OK).body(items);
}

View File

@ -18,6 +18,7 @@ import eu.eudat.models.data.components.commons.datafield.AutoCompleteData;
import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem;
import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel;
import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field;
import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.security.Principal;
@ -98,8 +99,8 @@ public class DatasetProfileManager {
return field;
}
public List<Tuple<String, String>> getAutocomplete(AutoCompleteData data, String like) {
List<Tuple<String, String>> result = new LinkedList<>();
public List<ExternalAutocompleteFieldModel> getAutocomplete(AutoCompleteData data, String like) {
List<ExternalAutocompleteFieldModel> result = new LinkedList<>();
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.valueOf("application/vnd.api+json; charset=utf-8")));
@ -110,7 +111,8 @@ public class DatasetProfileManager {
DocumentContext jsonContext = JsonPath.parse(response.getBody());
List<Map<String, String>> jsonItems = jsonContext.read(data.getOptionsRoot() + "['" + data.getAutoCompleteOptions().getLabel() + "','" + data.getAutoCompleteOptions().getValue() + "']");
jsonItems.forEach(item -> result.add(new Tuple<>(item.get(data.getAutoCompleteOptions().getValue()), item.get(data.getAutoCompleteOptions().getLabel()))));
jsonItems.forEach(item -> result.add(new ExternalAutocompleteFieldModel(item.get(data.getAutoCompleteOptions().getValue()), item.get(data.getAutoCompleteOptions().getLabel()), data.getUrl())));
return result;
}

View File

@ -0,0 +1,34 @@
package eu.eudat.models.data.externaldataset;
public class ExternalAutocompleteFieldModel {
private String id;
private String label;
private String source;
public ExternalAutocompleteFieldModel(String id, String label, String source) {
this.id = id;
this.label = label;
this.source = source;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
}

View File

@ -13,6 +13,7 @@ import { MultipleAutoCompleteConfiguration } from '../../../../../library/auto-c
import { DatasetProfileInternalDmpEntitiesType } from '../../../../../core/common/enum/dataset-profile-internal-dmp-entities-type';
import { ResearcherCriteria } from '../../../../../core/query/researcher/researcher-criteria';
import { ExternalSourcesService } from '../../../../../core/services/external-sources/external-sources.service';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'app-form-field',
@ -38,7 +39,8 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
constructor(
public visibilityRulesService: VisibilityRulesService,
private datasetExternalAutocompleteService: DatasetExternalAutocompleteService,
private externalSourcesService: ExternalSourcesService
private externalSourcesService: ExternalSourcesService,
public language: TranslateService,
) { super(); }
ngOnInit() {
@ -54,7 +56,8 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
initialItems: (extraData) => this.searchFromAutocomplete(''),
displayFn: (item) => (item != null && item.length > 1) ? JSON.parse(item).label : item['label'],
titleFn: (item) => item['label'],
valueAssign: (item) => JSON.stringify(item)
valueAssign: (item) => JSON.stringify(item),
subtitleFn: (item) => this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source']
};
}
else {
@ -63,7 +66,8 @@ export class FormFieldComponent extends BaseComponent implements OnInit {
initialItems: (extraData) => this.searchFromAutocomplete(''),
displayFn: (item) => item['label'],
titleFn: (item) => item['label'],
valueAssign: this._transformValue
valueAssign: this._transformValue,
subtitleFn: (item) => this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source']
}
}
}

View File

@ -337,7 +337,8 @@
},
"EDITOR": {
"FIELDS": {
"EXTERNAL-DATASET-TYPE": "Type"
"EXTERNAL-DATASET-TYPE": "Type",
"EXTERNAL-AUTOCOMPLETE-SUBTITLE": "External url: "
}
},
"FIRST-STEP": {