2019-09-23 10:17:03 +02:00
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2020-06-08 17:31:34 +02:00
|
|
|
import { FormGroup, FormArray, FormControl } from '@angular/forms';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type';
|
|
|
|
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
|
|
|
|
import { DatasetProfileInternalDmpEntitiesType } from '@app/core/common/enum/dataset-profile-internal-dmp-entities-type';
|
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { DatasetExternalAutocompleteCriteria } from '@app/core/query/dataset/daatset-external-autocomplete-criteria';
|
|
|
|
import { DatasetCriteria } from '@app/core/query/dataset/dataset-criteria';
|
|
|
|
import { DmpCriteria } from '@app/core/query/dmp/dmp-criteria';
|
|
|
|
import { RequestItem } from '@app/core/query/request-item';
|
|
|
|
import { ResearcherCriteria } from '@app/core/query/researcher/researcher-criteria';
|
|
|
|
import { DatasetExternalAutocompleteService } from '@app/core/services/dataset/dataset-external-autocomplete.service';
|
|
|
|
import { DatasetService } from '@app/core/services/dataset/dataset.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { ExternalSourcesService } from '@app/core/services/external-sources/external-sources.service';
|
|
|
|
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
|
|
|
|
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
|
|
|
|
import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2019-07-29 11:26:08 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { map, takeUntil } from 'rxjs/operators';
|
2020-06-04 17:37:30 +02:00
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { ExternalSourceItemModel } from '@app/core/model/external-sources/external-source-item';
|
|
|
|
import { ExternalDatasetCriteria } from '@app/core/query/external-dataset/external-dataset-criteria';
|
|
|
|
import { DataRepositoryCriteria } from '@app/core/query/data-repository/data-repository-criteria';
|
|
|
|
import { RegistryCriteria } from '@app/core/query/registry/registry-criteria';
|
|
|
|
import { ServiceCriteria } from '@app/core/query/service/service-criteria';
|
|
|
|
import { TagCriteria } from '@app/core/query/tag/tag-criteria';
|
2020-06-05 17:30:48 +02:00
|
|
|
import { isNullOrUndefined } from 'util';
|
|
|
|
import { ExternalTagEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
|
|
|
import { MatChipInputEvent } from '@angular/material';
|
|
|
|
import { ENTER, COMMA } from '@angular/cdk/keycodes';
|
2020-06-08 17:31:34 +02:00
|
|
|
import { DatasetIdModel } from '@app/core/model/dataset/dataset-id.model';
|
2020-06-25 12:00:29 +02:00
|
|
|
import { LocalFetchModel } from '@app/core/model/local-fetch/local-fetch.model';
|
|
|
|
import { CurrencyService } from '@app/core/services/currency/currency.service';
|
2021-03-22 14:47:45 +01:00
|
|
|
import { AutoCompleteSingleData } from '@app/core/model/dataset-profile-definition/field-data/field-data';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-form-field',
|
|
|
|
templateUrl: './form-field.component.html',
|
|
|
|
styleUrls: ['./form-field.component.scss']
|
|
|
|
})
|
|
|
|
export class FormFieldComponent extends BaseComponent implements OnInit {
|
2019-01-28 14:51:33 +01:00
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
// @Input() field: Field;
|
|
|
|
@Input() form: FormGroup;
|
2020-09-22 16:48:07 +02:00
|
|
|
@Input() datasetProfileId: any;
|
2019-02-04 14:41:54 +01:00
|
|
|
@Input() isChild: Boolean = false;
|
2021-03-22 14:47:45 +01:00
|
|
|
@Input() autocompleteOptions: AutoCompleteSingleData;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
// change: Subscription;
|
|
|
|
// trackByFn = (index, item) => item ? item['id'] : null;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
public singleAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
2019-03-26 16:09:02 +01:00
|
|
|
public multipleAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
2019-01-21 12:14:20 +01:00
|
|
|
datasetProfileFieldViewStyleEnum = DatasetProfileFieldViewStyle;
|
|
|
|
datasetProfileComboBoxTypeEnum = DatasetProfileComboBoxType;
|
2019-07-16 15:41:12 +02:00
|
|
|
datasetProfileInternalDmpEntitiesTypeEnum = DatasetProfileInternalDmpEntitiesType;
|
2020-06-05 17:30:48 +02:00
|
|
|
externalDatasetAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
dataRepositoriesAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
registriesAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
servicesAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
tagsAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
researchersAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
|
|
organisationsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
2020-06-25 12:00:29 +02:00
|
|
|
currencyAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
2020-06-05 17:30:48 +02:00
|
|
|
|
|
|
|
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
|
|
|
|
|
|
|
|
tags: ExternalTagEditorModel[] = [];
|
2019-01-21 12:14:20 +01:00
|
|
|
|
2020-06-08 17:31:34 +02:00
|
|
|
datasetIdInitialized: boolean = false;
|
|
|
|
|
2020-11-06 15:29:33 +01:00
|
|
|
validationIcon;
|
|
|
|
|
2020-06-08 17:31:34 +02:00
|
|
|
readonly datasetIdTypes: any[] = [
|
|
|
|
{ name: 'Handle', value: 'handle' },
|
|
|
|
{ name: 'DOI', value: 'doi' },
|
|
|
|
{ name: 'Ark', value: 'ark' },
|
|
|
|
{ name: 'Url', value: 'url' },
|
|
|
|
{ name: 'Other', value: 'other' }
|
|
|
|
];
|
|
|
|
|
2020-11-05 17:20:37 +01:00
|
|
|
|
|
|
|
readonly validationTypes: any[] = [
|
|
|
|
{ name: 'Zenodo', value: 'zenodo' }
|
|
|
|
];
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
constructor(
|
2019-01-21 12:14:20 +01:00
|
|
|
public visibilityRulesService: VisibilityRulesService,
|
2019-07-16 15:41:12 +02:00
|
|
|
private datasetExternalAutocompleteService: DatasetExternalAutocompleteService,
|
2019-07-29 11:26:08 +02:00
|
|
|
private externalSourcesService: ExternalSourcesService,
|
2019-07-30 12:35:06 +02:00
|
|
|
private language: TranslateService,
|
2019-07-30 13:31:41 +02:00
|
|
|
private datasetService: DatasetService,
|
2020-06-25 12:00:29 +02:00
|
|
|
private dmpService: DmpService,
|
|
|
|
private currencyService: CurrencyService
|
2019-01-18 18:03:45 +01:00
|
|
|
) { super(); }
|
|
|
|
|
|
|
|
ngOnInit() {
|
2019-02-04 14:41:54 +01:00
|
|
|
if (this.form.get('value').value) {
|
|
|
|
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, this.form.get('value').value);
|
|
|
|
}
|
2019-01-21 12:14:20 +01:00
|
|
|
|
2020-09-10 17:04:14 +02:00
|
|
|
if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.ComboBox && this.form.get('data').value.type === DatasetProfileComboBoxType.WordList) {
|
|
|
|
if (this.form.get('data').value.multiList) {
|
|
|
|
const originalValue = <string>this.form.get('value').value;
|
2020-09-22 16:34:12 +02:00
|
|
|
if (originalValue !== null && typeof originalValue === 'string') {
|
|
|
|
let values = (<string>this.form.get('value').value).slice(1, -1).split(', ');
|
|
|
|
if (!originalValue.startsWith('[') && !originalValue.endsWith(']')) {
|
|
|
|
values = undefined;
|
|
|
|
values = [originalValue];
|
|
|
|
}
|
|
|
|
this.form.patchValue({ 'value': values });
|
|
|
|
values.forEach(element => {
|
|
|
|
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, element);
|
|
|
|
});
|
2020-09-10 17:04:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
// Setup autocomplete configuration if needed
|
|
|
|
if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.ComboBox && this.form.get('data').value.type === DatasetProfileComboBoxType.Autocomplete) {
|
2019-03-26 16:09:02 +01:00
|
|
|
if (!(this.form.controls['data'].value.multiAutoComplete)) {
|
|
|
|
this.singleAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchFromAutocomplete.bind(this),
|
2019-09-11 10:18:53 +02:00
|
|
|
initialItems: () => this.searchFromAutocomplete(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => {try{return (item != null && item.length > 1) ? JSON.parse(item).label : item['label']}catch{return ''}},
|
|
|
|
titleFn: (item) => {try{return item['label'] }catch{return''}},
|
|
|
|
valueAssign: (item) => {try{return JSON.stringify(item)}catch{return''}},
|
|
|
|
subtitleFn: (item) => {try{return item['source'] ? this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source'] : this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-NO-SOURCE')}catch{return''}}
|
2019-03-26 16:09:02 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.multipleAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchFromAutocomplete.bind(this),
|
2019-09-11 10:18:53 +02:00
|
|
|
initialItems: () => this.searchFromAutocomplete(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) =>{try{return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label']}catch{return''}},
|
|
|
|
titleFn: (item) =>{ try{return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label']}catch{return''}},
|
|
|
|
valueAssign: (item) =>{ try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}},
|
|
|
|
subtitleFn: (item) => { try{return item['source'] ? this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-SUBTITLE') + item['source'] : this.language.instant('DATASET-WIZARD.EDITOR.FIELDS.EXTERNAL-AUTOCOMPLETE-NO-SOURCE')}catch{return''}}
|
2019-03-26 16:09:02 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
2019-01-28 14:47:31 +01:00
|
|
|
|
2020-06-05 17:30:48 +02:00
|
|
|
switch (this.form.get('viewStyle').value.renderStyle) {
|
|
|
|
case DatasetProfileFieldViewStyle.ExternalDatasets:
|
|
|
|
this.externalDatasetAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalDatasets.bind(this),
|
|
|
|
initialItems: () => this.searchDatasetExternalDatasets(''),//.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}
|
2020-06-05 17:30:48 +02:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case DatasetProfileFieldViewStyle.DataRepositories:
|
|
|
|
this.dataRepositoriesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalDataRepositories.bind(this),
|
|
|
|
initialItems: () => this.searchDatasetExternalDataRepositories(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}
|
2020-06-05 17:30:48 +02:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case DatasetProfileFieldViewStyle.Registries:
|
|
|
|
this.registriesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalRegistries.bind(this),
|
|
|
|
initialItems: () => this.searchDatasetExternalRegistries(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}
|
2020-06-05 17:30:48 +02:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case DatasetProfileFieldViewStyle.Services:
|
|
|
|
this.servicesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalServices.bind(this),
|
|
|
|
initialItems: () => this.searchDatasetExternalServices(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return ''}},
|
|
|
|
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
subtitleFn: (item) => { try{return item.source ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.source : item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}
|
2020-06-05 17:30:48 +02:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case DatasetProfileFieldViewStyle.Tags:
|
2020-09-11 13:27:53 +02:00
|
|
|
this.tagsAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterTags.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterTags('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return this.showTag(item)}catch{return''}},
|
|
|
|
titleFn: (item) => { try{return item['name']}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return this.addTag(item)}catch{return''}}
|
2020-09-11 13:27:53 +02:00
|
|
|
};
|
|
|
|
this.parseTags();
|
2020-06-05 17:30:48 +02:00
|
|
|
break;
|
|
|
|
case DatasetProfileFieldViewStyle.Researchers:
|
|
|
|
this.researchersAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterResearchers.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterResearchers('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
titleFn: (item) =>{ try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
subtitleFn: (item) => { try{return item['tag'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['tag'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'))}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}
|
2020-06-05 17:30:48 +02:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
case DatasetProfileFieldViewStyle.Organizations:
|
|
|
|
this.organisationsAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterOrganisations.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterOrganisations('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn:(item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
titleFn: (item) =>{ try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
subtitleFn: (item) =>{ try{return item['tag'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['tag'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE'))}catch{return''}},
|
|
|
|
valueAssign: (item) =>{ try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}
|
2020-06-05 17:30:48 +02:00
|
|
|
};
|
|
|
|
break;
|
2020-06-08 17:31:34 +02:00
|
|
|
case DatasetProfileFieldViewStyle.DatasetIdentifier:
|
|
|
|
const value = this.form.get('value').value;
|
|
|
|
this.form.removeControl('value');
|
|
|
|
this.form.addControl('value', new DatasetIdModel(value).buildForm());
|
|
|
|
this.datasetIdInitialized = true;
|
|
|
|
break;
|
2020-06-25 12:00:29 +02:00
|
|
|
case DatasetProfileFieldViewStyle.Currency:
|
2020-09-10 17:04:14 +02:00
|
|
|
this.currencyAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchCurrency.bind(this),
|
|
|
|
initialItems: () => this.searchCurrency(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}}
|
2020-09-10 17:04:14 +02:00
|
|
|
};
|
|
|
|
break;
|
2020-11-06 15:29:33 +01:00
|
|
|
case DatasetProfileFieldViewStyle.Validation:
|
|
|
|
const value1 = this.form.get('value').value;
|
|
|
|
this.form.removeControl('value');
|
|
|
|
this.form.addControl('value', new DatasetIdModel(value1).buildForm());
|
|
|
|
//this.datasetIdInitialized = true;
|
|
|
|
break;
|
2020-06-05 17:30:48 +02:00
|
|
|
}
|
|
|
|
|
2019-07-16 15:41:12 +02:00
|
|
|
if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.InternalDmpEntities) {
|
|
|
|
if (this.form.get('data').value.type === DatasetProfileInternalDmpEntitiesType.Researchers) {
|
2019-07-30 12:35:06 +02:00
|
|
|
this.makeAutocompleteConfiguration(this.searchResearchers.bind(this), "name", "tag");
|
|
|
|
}
|
|
|
|
else if (this.form.get('data').value.type === DatasetProfileInternalDmpEntitiesType.Datasets) {
|
|
|
|
this.makeAutocompleteConfiguration(this.searchDatasets.bind(this), "label");
|
2019-07-16 15:41:12 +02:00
|
|
|
}
|
2019-07-30 13:31:41 +02:00
|
|
|
else if (this.form.get('data').value.type === DatasetProfileInternalDmpEntitiesType.Dmps) {
|
|
|
|
this.makeAutocompleteConfiguration(this.searchDmps.bind(this), "label");
|
|
|
|
}
|
2019-07-16 15:41:12 +02:00
|
|
|
}
|
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
// this.form = this.visibilityRulesService.getFormGroup(this.field.id);
|
|
|
|
this.form.get('value').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(item => {
|
2020-09-22 16:34:12 +02:00
|
|
|
if (this.form.get('viewStyle').value.renderStyle === DatasetProfileFieldViewStyle.ComboBox && this.form.get('data').value.type === DatasetProfileComboBoxType.WordList && this.form.get('data').value.multiList) {
|
|
|
|
item.forEach(element => {
|
|
|
|
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, element);
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.visibilityRulesService.updateValueAndVisibility(this.form.get('id').value, item);
|
|
|
|
}
|
2019-01-28 14:47:31 +01:00
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
2019-03-26 16:09:02 +01:00
|
|
|
|
2019-12-17 12:08:01 +01:00
|
|
|
// _optionRemove(event) {
|
|
|
|
// const array = JSON.parse(this.form.get('value').value);
|
|
|
|
// if (array) {
|
|
|
|
// const index = array.map(x => x.id).indexOf(event.id);
|
|
|
|
// if (index >= 0) {
|
|
|
|
// array.splice(index, 1);
|
|
|
|
// }
|
|
|
|
// this.form.get('value').patchValue(JSON.stringify(array));
|
|
|
|
// }
|
|
|
|
// }
|
2019-03-26 16:09:02 +01:00
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
searchFromAutocomplete(query: string) {
|
|
|
|
const autocompleteRequestItem: RequestItem<DatasetExternalAutocompleteCriteria> = new RequestItem();
|
|
|
|
autocompleteRequestItem.criteria = new DatasetExternalAutocompleteCriteria();
|
2019-01-28 14:51:33 +01:00
|
|
|
|
2019-01-28 14:47:31 +01:00
|
|
|
autocompleteRequestItem.criteria.fieldID = this.form.get('id').value;
|
2020-09-22 16:48:07 +02:00
|
|
|
if (typeof this.datasetProfileId === 'string') {
|
|
|
|
autocompleteRequestItem.criteria.profileID = this.datasetProfileId;
|
2021-03-03 10:14:43 +01:00
|
|
|
} else if (this.datasetProfileId != null) {
|
2020-09-22 16:48:07 +02:00
|
|
|
autocompleteRequestItem.criteria.profileID = this.datasetProfileId.id;
|
2021-03-03 10:14:43 +01:00
|
|
|
} else if (this.autocompleteOptions != null) {
|
|
|
|
autocompleteRequestItem.criteria.autocompleteOptions = this.autocompleteOptions;
|
|
|
|
} else {
|
2021-03-03 11:10:11 +01:00
|
|
|
throw "Could not load autocomplete options.";
|
2020-09-22 16:48:07 +02:00
|
|
|
}
|
2019-01-31 11:29:35 +01:00
|
|
|
autocompleteRequestItem.criteria.like = query;
|
2021-03-22 14:47:45 +01:00
|
|
|
|
|
|
|
if(this.autocompleteOptions){
|
|
|
|
return this.datasetExternalAutocompleteService.queryApi(autocompleteRequestItem);
|
|
|
|
}
|
2019-01-21 12:14:20 +01:00
|
|
|
return this.datasetExternalAutocompleteService.queryAutocomplete(autocompleteRequestItem);
|
|
|
|
}
|
2019-07-16 15:41:12 +02:00
|
|
|
|
|
|
|
searchResearchers(query: string) {
|
|
|
|
const reasearcherAutocompleteRequestItem: RequestItem<ResearcherCriteria> = new RequestItem();
|
|
|
|
reasearcherAutocompleteRequestItem.criteria = new ResearcherCriteria;
|
|
|
|
reasearcherAutocompleteRequestItem.criteria.name = query;
|
|
|
|
return this.externalSourcesService.searchDMPResearchers(reasearcherAutocompleteRequestItem);
|
|
|
|
}
|
2019-07-30 12:35:06 +02:00
|
|
|
|
|
|
|
searchDatasets(query: string) {
|
|
|
|
let fields: Array<string> = new Array();
|
|
|
|
const datasetsAutocompleteRequestItem: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, 25, { fields: fields });
|
|
|
|
datasetsAutocompleteRequestItem.criteria = new DatasetCriteria();
|
|
|
|
datasetsAutocompleteRequestItem.criteria.like = query;
|
2019-09-23 10:17:03 +02:00
|
|
|
return this.datasetService.getPaged(datasetsAutocompleteRequestItem).pipe(map(item => item.data));
|
2019-07-30 12:35:06 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 13:31:41 +02:00
|
|
|
searchDmps(query: string) {
|
|
|
|
let fields: Array<string> = new Array();
|
|
|
|
const dmpsAutocompleteRequestItem: DataTableRequest<DmpCriteria> = new DataTableRequest(0, 25, { fields: fields });
|
|
|
|
dmpsAutocompleteRequestItem.criteria = new DmpCriteria();
|
|
|
|
dmpsAutocompleteRequestItem.criteria.like = query;
|
2019-09-23 10:17:03 +02:00
|
|
|
return this.dmpService.getPaged(dmpsAutocompleteRequestItem).pipe(map(item => item.data));
|
2019-07-30 13:31:41 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 12:35:06 +02:00
|
|
|
makeAutocompleteConfiguration(myfunc: Function, title: string, subtitle?: string): void {
|
|
|
|
if (!(this.form.controls['data'].value.multiAutoComplete)) {
|
|
|
|
this.singleAutoCompleteConfiguration = {
|
|
|
|
filterFn: myfunc.bind(this),
|
|
|
|
initialItems: (extraData) => myfunc(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return (item != null && item.length > 1) ? JSON.parse(item)[title] : item[title]}catch{return''}},
|
|
|
|
titleFn: (item) => { try{return item[title]}catch{return''}},
|
2019-07-30 12:35:06 +02:00
|
|
|
valueAssign: (item) => JSON.stringify(item),
|
2021-03-30 16:47:35 +02:00
|
|
|
subtitleFn: (item) => { try{return item[subtitle]}catch{return''}}
|
2019-07-30 12:35:06 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.multipleAutoCompleteConfiguration = {
|
|
|
|
filterFn: myfunc.bind(this),
|
|
|
|
initialItems: (extraData) => myfunc(''),
|
2021-03-30 16:47:35 +02:00
|
|
|
displayFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label']}catch{return''}},
|
|
|
|
titleFn: (item) => { try{return typeof (item) == 'string' ? JSON.parse(item)['label'] : item['label']}catch{return''}},
|
|
|
|
valueAssign: (item) => { try{return typeof (item) == 'string' ? item : JSON.stringify(item)}catch{return''}},
|
|
|
|
subtitleFn: (item) => { try{return item[subtitle]}catch{return''}}
|
2019-07-30 12:35:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 17:37:30 +02:00
|
|
|
|
2020-06-05 17:30:48 +02:00
|
|
|
searchDatasetExternalDatasets(query: string): Observable<ExternalSourceItemModel[]> {
|
2020-06-04 17:37:30 +02:00
|
|
|
const requestItem: RequestItem<ExternalDatasetCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new ExternalDatasetCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
2020-06-05 17:30:48 +02:00
|
|
|
requestItem.criteria.type = '';
|
2020-06-04 17:37:30 +02:00
|
|
|
return this.externalSourcesService.searchDatasetSExternalDatasetservice(requestItem);
|
|
|
|
}
|
|
|
|
|
2020-06-05 17:30:48 +02:00
|
|
|
searchDatasetExternalDataRepositories(query: string): Observable<ExternalSourceItemModel[]> {
|
2020-06-04 17:37:30 +02:00
|
|
|
const requestItem: RequestItem<DataRepositoryCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new DataRepositoryCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
2020-06-05 17:30:48 +02:00
|
|
|
requestItem.criteria.type = '';
|
2020-06-04 17:37:30 +02:00
|
|
|
return this.externalSourcesService.searchDatasetRepository(requestItem);
|
|
|
|
}
|
|
|
|
|
2020-06-05 17:30:48 +02:00
|
|
|
searchDatasetExternalRegistries(query: string): Observable<ExternalSourceItemModel[]> {
|
2020-06-04 17:37:30 +02:00
|
|
|
const requestItem: RequestItem<RegistryCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new RegistryCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
2020-06-05 17:30:48 +02:00
|
|
|
requestItem.criteria.type = '';
|
2020-06-04 17:37:30 +02:00
|
|
|
return this.externalSourcesService.searchDatasetRegistry(requestItem);
|
|
|
|
}
|
|
|
|
|
2020-06-05 17:30:48 +02:00
|
|
|
searchDatasetExternalServices(query: string): Observable<ExternalSourceItemModel[]> {
|
2020-06-04 17:37:30 +02:00
|
|
|
const requestItem: RequestItem<ServiceCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new ServiceCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
2020-06-05 17:30:48 +02:00
|
|
|
requestItem.criteria.type = '';
|
2020-06-04 17:37:30 +02:00
|
|
|
return this.externalSourcesService.searchDatasetService(requestItem);
|
|
|
|
}
|
|
|
|
|
2020-06-05 17:30:48 +02:00
|
|
|
searchDatasetTags(query: string): Observable<ExternalSourceItemModel[]> {
|
2020-06-04 17:37:30 +02:00
|
|
|
const requestItem: RequestItem<TagCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new TagCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
2020-06-05 17:30:48 +02:00
|
|
|
requestItem.criteria.type = '';
|
2020-06-04 17:37:30 +02:00
|
|
|
return this.externalSourcesService.searchDatasetTags(requestItem);
|
|
|
|
}
|
2020-06-05 17:30:48 +02:00
|
|
|
|
2020-09-11 13:27:53 +02:00
|
|
|
parseTags() {
|
|
|
|
let stringValue = this.form.get('value').value;
|
2020-09-15 12:21:22 +02:00
|
|
|
if (typeof stringValue === 'string') {
|
|
|
|
stringValue = (<string>stringValue).replace(new RegExp('{', 'g'), '{"').replace(new RegExp('=', 'g'), '":"').replace(new RegExp(',', 'g'), '",').replace(new RegExp(', ', 'g'), ', "').replace(new RegExp('}', 'g'), '"}');
|
|
|
|
stringValue = stringValue.replace(new RegExp('}"', 'g'), '}').replace(new RegExp('"{', 'g'), '{');
|
|
|
|
} else if (stringValue instanceof Array) {
|
|
|
|
const tempArray = new Array();
|
|
|
|
for (let stringTag of stringValue) {
|
|
|
|
tempArray.push(JSON.parse(stringTag));
|
|
|
|
}
|
|
|
|
stringValue = JSON.stringify(tempArray);
|
|
|
|
}
|
2020-09-11 13:27:53 +02:00
|
|
|
const tagArray = JSON.parse(stringValue);
|
|
|
|
this.form.patchValue({'value': tagArray});
|
2020-06-05 17:30:48 +02:00
|
|
|
}
|
|
|
|
|
2020-09-11 13:27:53 +02:00
|
|
|
filterTags(value: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
const requestItem: RequestItem<TagCriteria> = new RequestItem();
|
|
|
|
const criteria: TagCriteria = new TagCriteria();
|
|
|
|
criteria.like = value;
|
|
|
|
requestItem.criteria = criteria;
|
|
|
|
return this.externalSourcesService.searchDatasetTags(requestItem);
|
2020-06-05 17:30:48 +02:00
|
|
|
}
|
|
|
|
|
2020-09-11 13:27:53 +02:00
|
|
|
showTag(ev: any) {
|
|
|
|
if (typeof ev === 'string') {
|
|
|
|
return ev;
|
|
|
|
} else {
|
|
|
|
return ev.name;
|
|
|
|
}
|
2020-06-05 17:30:48 +02:00
|
|
|
}
|
|
|
|
|
2020-09-11 13:27:53 +02:00
|
|
|
addTag(ev: any) {
|
|
|
|
let item: ExternalTagEditorModel;
|
|
|
|
//this.filteredTags = this.formGroup.get('tags').value;
|
|
|
|
if (typeof ev === 'string') {
|
|
|
|
item = new ExternalTagEditorModel('', ev);
|
|
|
|
} else {
|
|
|
|
item = ev;
|
|
|
|
}
|
|
|
|
if (item.name !== '' ) {
|
|
|
|
return item;
|
2020-06-05 17:30:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
return this.externalSourcesService.searchDMPOrganizations(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
filterResearchers(value: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
return this.externalSourcesService.searchDMPResearchers({ criteria: { name: value, like: null } });
|
|
|
|
}
|
2020-06-08 17:31:34 +02:00
|
|
|
|
|
|
|
getDatasetIdControl(name: string): FormControl {
|
|
|
|
return this.form.get('value').get(name) as FormControl;
|
|
|
|
}
|
2020-06-25 12:00:29 +02:00
|
|
|
|
|
|
|
searchCurrency(query: string): Observable<LocalFetchModel[]> {
|
|
|
|
return this.currencyService.get(query);
|
|
|
|
}
|
2020-11-05 17:20:37 +01:00
|
|
|
|
|
|
|
validateId() {
|
|
|
|
const identifier = this.getDatasetIdControl('identifier').value;
|
|
|
|
const type = this.getDatasetIdControl('type').value;
|
2020-11-06 15:29:33 +01:00
|
|
|
this.validationIcon= 'loading';
|
2020-11-05 17:20:37 +01:00
|
|
|
this.externalSourcesService.validateIdentifier(identifier, type).pipe(takeUntil(this._destroyed)).subscribe(result => {
|
2020-11-06 15:29:33 +01:00
|
|
|
this.validationIcon = result === true ? 'done' : 'clear';
|
2020-11-05 17:20:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|