2019-01-18 18:03:45 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { FormArray, FormGroup } from '@angular/forms';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { BaseComponent } from '../../../../core/common/base/base.component';
|
|
|
|
import { ExternalSourceItemModel } from '../../../../core/model/external-sources/external-source-item';
|
|
|
|
import { ExternalSourcesConfiguration } from '../../../../core/model/external-sources/external-sources-configuration';
|
|
|
|
import { DataRepositoryCriteria } from '../../../../core/query/data-repository/data-repository-criteria';
|
|
|
|
import { ExternalDatasetCriteria } from '../../../../core/query/external-dataset/external-dataset-criteria';
|
|
|
|
import { RegistryCriteria } from '../../../../core/query/registry/registry-criteria';
|
|
|
|
import { ServiceCriteria } from '../../../../core/query/service/service-criteria';
|
|
|
|
import { TagCriteria } from '../../../../core/query/tag/tag-criteria';
|
|
|
|
import { ExternalSourcesConfigurationService } from '../../../../core/services/external-sources/external-sources-configuration.service';
|
|
|
|
import { ExternalSourcesService } from '../../../../core/services/external-sources/external-sources.service';
|
|
|
|
import { SingleAutoCompleteConfiguration } from '../../../../library/auto-complete/single/single-auto-complete-configuration';
|
|
|
|
import { RequestItem } from '../../../../core/query/request-item';
|
2019-09-16 10:09:41 +02:00
|
|
|
import { ExternalDataRepositoryEditorModel, ExternalDatasetEditorModel, ExternalRegistryEditorModel, ExternalServiceEditorModel, ExternalTagEditorModel } from '../dataset-wizard-editor.model';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { DatasetExternalDataRepositoryDialogEditorComponent } from './editors/data-repository/dataset-external-data-repository-dialog-editor.component';
|
|
|
|
import { DatasetExternalDatasetDialogEditorComponent } from './editors/external-dataset/dataset-external-dataset-dialog-editor.component';
|
|
|
|
import { DatasetExternalRegistryDialogEditorComponent } from './editors/registry/dataset-external-registry-dialog-editor.component';
|
|
|
|
import { DatasetExternalServiceDialogEditorComponent } from './editors/service/dataset-external-service-dialog-editor.component';
|
2019-08-30 17:06:12 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dataset-external-references-editor-component',
|
|
|
|
templateUrl: 'dataset-external-references-editor.component.html',
|
|
|
|
styleUrls: ['./dataset-external-references-editor.component.scss']
|
|
|
|
})
|
|
|
|
export class DatasetExternalReferencesEditorComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
@Input() formGroup: FormGroup = null;
|
2019-02-11 14:44:03 +01:00
|
|
|
@Input() viewOnly = false;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
externalDatasetAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
registriesAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
dataRepositoriesAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
servicesAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
tagsAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
|
|
|
|
externalSourcesConfiguration: ExternalSourcesConfiguration;
|
|
|
|
|
|
|
|
// new AutoCompleteConfiguration(this.externalSourcesService.searchDatasetRepository.bind(this.externalSourcesService),
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private dialog: MatDialog,
|
|
|
|
private router: Router,
|
2019-08-30 17:06:12 +02:00
|
|
|
private language: TranslateService,
|
2019-01-18 18:03:45 +01:00
|
|
|
private externalSourcesService: ExternalSourcesService,
|
|
|
|
private externalSourcesConfigurationService: ExternalSourcesConfigurationService
|
|
|
|
) { super(); }
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
this.externalSourcesConfigurationService.getExternalSourcesConfiguration()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
this.externalSourcesConfiguration = result;
|
|
|
|
this.externalSourcesConfiguration.dataRepositories.push({ key: '', label: 'All' });
|
|
|
|
this.externalSourcesConfiguration.externalDatasets.push({ key: '', label: 'All' });
|
|
|
|
this.externalSourcesConfiguration.registries.push({ key: '', label: 'All' });
|
|
|
|
this.externalSourcesConfiguration.services.push({ key: '', label: 'All' });
|
|
|
|
this.externalSourcesConfiguration.tags.push({ key: '', label: 'All' });
|
|
|
|
});
|
|
|
|
|
2019-09-16 10:09:41 +02:00
|
|
|
this.dataRepositoriesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalDataRepositories.bind(this),
|
2019-09-19 17:05:20 +02:00
|
|
|
removeAfterSelection: true,
|
2019-09-16 10:09:41 +02:00
|
|
|
initialItems: (type) => this.searchDatasetExternalDataRepositories('', type),
|
|
|
|
displayFn: (item) => item ? item.name : null,
|
|
|
|
titleFn: (item) => item ? item.name : null,
|
|
|
|
subtitleFn: (item) => item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')
|
|
|
|
};
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
this.externalDatasetAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalDatasets.bind(this),
|
2019-09-19 17:05:20 +02:00
|
|
|
removeAfterSelection: true,
|
2019-01-18 18:03:45 +01:00
|
|
|
initialItems: (type) => this.searchDatasetExternalDatasets('', type),//.filter(resultItem => excludedItems.map(x => x.id).indexOf(resultItem.id) === -1),
|
|
|
|
displayFn: (item) => item ? item.label : null,
|
|
|
|
titleFn: (item) => item ? item.label : null,
|
2019-09-04 09:37:44 +02:00
|
|
|
subtitleFn: (item) => item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')
|
2019-01-18 18:03:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.registriesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalRegistries.bind(this),
|
2019-09-19 17:05:20 +02:00
|
|
|
removeAfterSelection: true,
|
2019-01-18 18:03:45 +01:00
|
|
|
initialItems: (type) => this.searchDatasetExternalRegistries('', type),
|
2019-09-16 17:26:18 +02:00
|
|
|
displayFn: (item) => item ? item.label : null,
|
|
|
|
titleFn: (item) => item ? item.label: null,
|
2019-09-04 09:37:44 +02:00
|
|
|
subtitleFn: (item) => item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')
|
2019-01-18 18:03:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.servicesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetExternalServices.bind(this),
|
2019-09-19 17:05:20 +02:00
|
|
|
removeAfterSelection: true,
|
2019-01-18 18:03:45 +01:00
|
|
|
initialItems: (type) => this.searchDatasetExternalServices('', type),
|
2019-09-16 17:26:18 +02:00
|
|
|
displayFn: (item) => item ? item.label : null,
|
|
|
|
titleFn: (item) => item ? item.label : null,
|
2019-09-04 09:37:44 +02:00
|
|
|
subtitleFn: (item) => item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')
|
2019-01-18 18:03:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
this.tagsAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDatasetTags.bind(this),
|
2019-09-19 17:05:20 +02:00
|
|
|
removeAfterSelection: true,
|
2019-01-18 18:03:45 +01:00
|
|
|
initialItems: (type) => this.searchDatasetTags('', type),
|
|
|
|
displayFn: (item) => item ? item.name : null,
|
2019-09-16 10:09:41 +02:00
|
|
|
titleFn: (item) => item ? item.name : null,
|
2019-09-13 15:45:02 +02:00
|
|
|
subtitleFn: (item) => item.tag ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item.tag : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')
|
2019-01-18 18:03:45 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public cancel(): void {
|
|
|
|
this.router.navigate(['/datasets']);
|
|
|
|
}
|
|
|
|
|
|
|
|
externalDatasetsOnItemChange(event) {
|
|
|
|
const externalDatasetModel = new ExternalDatasetEditorModel(event.id, event.abbreviation, event.label, event.reference);
|
|
|
|
(<FormArray>this.formGroup.get('externalDatasets')).push(externalDatasetModel.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
registriesOnItemChange(event) {
|
2019-09-16 17:26:18 +02:00
|
|
|
const registryModel = new ExternalRegistryEditorModel(event.abbreviation, event.definition, event.id, event.label, event.reference, event.uri);
|
2019-01-18 18:03:45 +01:00
|
|
|
(<FormArray>this.formGroup.get('registries')).push(registryModel.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
servicesOnItemChange(event) {
|
2019-09-16 17:26:18 +02:00
|
|
|
const serviceModel = new ExternalServiceEditorModel(event.abbreviation, event.definition, event.id, event.label, event.reference, event.uri);
|
2019-01-18 18:03:45 +01:00
|
|
|
(<FormArray>this.formGroup.get('services')).push(serviceModel.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
tagsOnItemChange(event) {
|
2019-09-16 10:09:41 +02:00
|
|
|
const tagModel = new ExternalTagEditorModel(event.id, event.name);
|
|
|
|
(<FormArray>this.formGroup.get('tags')).push(tagModel.buildForm());
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dataRepositoriesOnItemChange(event) {
|
|
|
|
const dataRepositoryModel = new ExternalDataRepositoryEditorModel(event.id, event.name, event.abbreviation, event.uri, event.pid);
|
|
|
|
(<FormArray>this.formGroup.get('dataRepositories')).push(dataRepositoryModel.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
addDataRepository() {
|
|
|
|
const dialogRef = this.dialog.open(DatasetExternalDataRepositoryDialogEditorComponent, {
|
|
|
|
data: {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
if (!result) { return; }
|
|
|
|
const dataRepositoryModel = new ExternalDataRepositoryEditorModel(result.id, result.label, result.pid, result.uri, result.reference);
|
|
|
|
(<FormArray>this.formGroup.get('dataRepositories')).push(dataRepositoryModel.buildForm());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addRegistry() {
|
|
|
|
const dialogRef = this.dialog.open(DatasetExternalRegistryDialogEditorComponent, {
|
|
|
|
data: {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
if (!result) { return; }
|
2019-09-16 17:26:18 +02:00
|
|
|
const registryModel = new ExternalRegistryEditorModel(result.abbreviation, result.definition, result.id, result.label, result.reference, result.uri);
|
2019-01-18 18:03:45 +01:00
|
|
|
(<FormArray>this.formGroup.get('registries')).push(registryModel.buildForm());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addExternalDataset() {
|
|
|
|
const dialogRef = this.dialog.open(DatasetExternalDatasetDialogEditorComponent, {
|
|
|
|
data: {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
if (!result) { return; }
|
|
|
|
const externalDatasetModel = new ExternalDatasetEditorModel(result.id, result.abbreviation, result.label, result.reference);
|
|
|
|
(<FormArray>this.formGroup.get('externalDatasets')).push(externalDatasetModel.buildForm());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addService() {
|
|
|
|
const dialogRef = this.dialog.open(DatasetExternalServiceDialogEditorComponent, {
|
|
|
|
data: {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
if (!result) { return; }
|
2019-09-16 17:26:18 +02:00
|
|
|
const serviceModel = new ExternalServiceEditorModel(result.abbreviation, result.definition, result.id, result.label, result.reference, result.uri);
|
2019-01-18 18:03:45 +01:00
|
|
|
(<FormArray>this.formGroup.get('services')).push(serviceModel.buildForm());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
searchDatasetExternalDatasets(query: string, type: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
const requestItem: RequestItem<ExternalDatasetCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new ExternalDatasetCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
|
|
|
requestItem.criteria.type = type;
|
|
|
|
return this.externalSourcesService.searchDatasetSExternalDatasetservice(requestItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
searchDatasetExternalDataRepositories(query: string, type: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
const requestItem: RequestItem<DataRepositoryCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new DataRepositoryCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
|
|
|
requestItem.criteria.type = type;
|
|
|
|
return this.externalSourcesService.searchDatasetRepository(requestItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
searchDatasetExternalRegistries(query: string, type: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
const requestItem: RequestItem<RegistryCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new RegistryCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
|
|
|
requestItem.criteria.type = type;
|
|
|
|
return this.externalSourcesService.searchDatasetRegistry(requestItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
searchDatasetExternalServices(query: string, type: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
const requestItem: RequestItem<ServiceCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new ServiceCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
|
|
|
requestItem.criteria.type = type;
|
|
|
|
return this.externalSourcesService.searchDatasetService(requestItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
searchDatasetTags(query: string, type: string): Observable<ExternalSourceItemModel[]> {
|
|
|
|
const requestItem: RequestItem<TagCriteria> = new RequestItem();
|
|
|
|
requestItem.criteria = new TagCriteria();
|
|
|
|
requestItem.criteria.like = query;
|
|
|
|
requestItem.criteria.type = type;
|
2019-09-13 15:45:02 +02:00
|
|
|
return this.externalSourcesService.searchDatasetTags(requestItem);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
}
|