2020-07-29 17:04:19 +02:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { OnInit, Component, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
|
|
|
import { ExternalSourcesService } from '@app/core/services/external-sources/external-sources.service';
|
|
|
|
import { MatDialog, MatSnackBar, MatChipInputEvent } from '@angular/material';
|
|
|
|
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { ExternalSourcesConfigurationService } from '@app/core/services/external-sources/external-sources-configuration.service';
|
|
|
|
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { FormService } from '@common/forms/form-service';
|
|
|
|
import { LockService } from '@app/core/services/lock/lock.service';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
|
|
import { DatasetStatus } from '@app/core/common/enum/dataset-status';
|
|
|
|
import { FormGroup, FormControl, FormArray } from '@angular/forms';
|
|
|
|
import { DatasetDescriptionFormEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
|
|
|
|
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
|
|
|
|
import { LockModel } from '@app/core/model/lock/lock.model';
|
|
|
|
import { takeUntil, map, catchError } from 'rxjs/operators';
|
|
|
|
import { RequestItem } from '@app/core/query/request-item';
|
|
|
|
import { isNullOrUndefined } from 'util';
|
|
|
|
import { interval, Observable, of as observableOf } from 'rxjs';
|
|
|
|
import { Guid } from '@common/types/guid';
|
|
|
|
import { Location } from '@angular/common';
|
|
|
|
import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria';
|
|
|
|
import { DmpListingModel } from '@app/core/model/dmp/dmp-listing';
|
|
|
|
import { DatasetWizardEditorModel, ExternalTagEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
|
|
|
import { ENTER, COMMA } from '@angular/cdk/keycodes';
|
2020-07-31 16:39:57 +02:00
|
|
|
import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants';
|
|
|
|
import { GuidedTourService } from '@app/library/guided-tour/guided-tour.service';
|
2020-09-04 18:27:41 +02:00
|
|
|
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
|
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { AvailableProfilesComponent } from '../available-profiles/available-profiles.component';
|
2020-07-29 17:04:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'dataset-editor-details',
|
|
|
|
templateUrl: './dataset-editor-details.component.html',
|
|
|
|
styleUrls: ['./dataset-editor-details.component.scss']
|
|
|
|
})
|
|
|
|
export class DatasetEditorDetailsComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
viewOnly = false;
|
|
|
|
editMode = false;
|
|
|
|
// publicMode = false;
|
|
|
|
|
|
|
|
// DatasetStatus = DatasetStatus;
|
|
|
|
// dmpAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
|
|
|
|
datasetWizardModel: DatasetWizardEditorModel;
|
|
|
|
// isNew = true;
|
|
|
|
// isCopy = false;
|
|
|
|
// formGroup: FormGroup = null;
|
|
|
|
datasetProfileDefinitionModel: DatasetDescriptionFormEditorModel;
|
|
|
|
|
2020-09-08 09:36:18 +02:00
|
|
|
// availableProfiles: DatasetProfileModel[] = [];
|
2020-07-29 17:04:19 +02:00
|
|
|
// itemId: string;
|
|
|
|
// publicId: string;
|
|
|
|
// profileUpdateId: string;
|
|
|
|
// downloadDocumentId: string;
|
|
|
|
// isLinear = false;
|
|
|
|
lock: LockModel;
|
|
|
|
lockStatus: Boolean;
|
2020-10-23 16:59:59 +02:00
|
|
|
dmpText: string = null;
|
2020-07-29 17:04:19 +02:00
|
|
|
|
|
|
|
@Input() formGroup: FormGroup;
|
|
|
|
@Input() dmpId: string;
|
|
|
|
@Input() datasetId: string;
|
2020-09-08 09:36:18 +02:00
|
|
|
@Input() availableProfiles: DatasetProfileModel[];
|
2020-07-29 17:04:19 +02:00
|
|
|
@Output() formChanged: EventEmitter<any> = new EventEmitter();
|
|
|
|
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
|
|
|
|
|
2020-09-04 18:27:41 +02:00
|
|
|
profilesAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
|
|
|
2020-07-29 17:04:19 +02:00
|
|
|
constructor(
|
|
|
|
private datasetWizardService: DatasetWizardService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public snackBar: MatSnackBar,
|
|
|
|
public router: Router,
|
|
|
|
private language: TranslateService,
|
|
|
|
private configurationService: ConfigurationService,
|
|
|
|
private externalSourcesService: ExternalSourcesService,
|
|
|
|
private dialog: MatDialog,
|
|
|
|
public dmpService: DmpService,
|
|
|
|
public externalSourcesConfigurationService: ExternalSourcesConfigurationService,
|
|
|
|
private uiNotificationService: UiNotificationService,
|
|
|
|
private formService: FormService,
|
|
|
|
private lockService: LockService,
|
|
|
|
private location: Location,
|
2020-07-31 16:39:57 +02:00
|
|
|
private authService: AuthService,
|
|
|
|
private guidedTourService: GuidedTourService
|
2020-07-29 17:04:19 +02:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-09-03 11:52:35 +02:00
|
|
|
|
2020-08-06 12:50:28 +02:00
|
|
|
if (this.formGroup.get('status').value === 1) {
|
|
|
|
this.formGroup.disable();
|
|
|
|
}
|
2020-08-24 14:46:55 +02:00
|
|
|
|
2020-08-25 09:45:42 +02:00
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel();
|
2020-08-24 14:46:55 +02:00
|
|
|
|
2020-09-04 18:27:41 +02:00
|
|
|
this.profilesAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.filterProfiles.bind(this),
|
|
|
|
initialItems: (excludedItems: any[]) => this.filterProfiles('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))),
|
|
|
|
displayFn: (item) => item['label'],
|
|
|
|
titleFn: (item) => item['label'],
|
2020-10-20 12:23:22 +02:00
|
|
|
subtitleFn: (item) => item['description'],
|
|
|
|
popupItemActionIcon: 'visibility'
|
2020-09-04 18:27:41 +02:00
|
|
|
};
|
2020-07-29 17:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 17:27:13 +02:00
|
|
|
public dashboardTourDmp: GuidedTour = {
|
2020-07-31 16:39:57 +02:00
|
|
|
tourId: 'only-dmp-tour',
|
|
|
|
useOrb: true,
|
|
|
|
steps: [
|
2020-08-06 12:50:28 +02:00
|
|
|
{
|
2020-07-31 16:39:57 +02:00
|
|
|
title: this.dmpText,
|
|
|
|
content: 'Step 1',
|
2020-08-04 17:27:13 +02:00
|
|
|
orientation: Orientation.Bottom,
|
|
|
|
highlightPadding: 3,
|
|
|
|
isStepUnique: true,
|
|
|
|
customTopOffset: 8
|
2020-07-31 16:39:57 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2020-08-04 17:27:13 +02:00
|
|
|
getDmpText(): string {
|
|
|
|
return this.language.instant('DMP-LISTING.TEXT-INFO') + '\n\n' +
|
2020-08-31 01:43:11 +02:00
|
|
|
this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' +
|
|
|
|
this.language.instant('DMP-LISTING.LINK-ZENODO') + ' ' +
|
|
|
|
this.language.instant('DMP-LISTING.GET-IDEA');
|
2020-07-31 16:39:57 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 17:27:13 +02:00
|
|
|
setDashboardTourDmp(label: string): void {
|
|
|
|
this.dashboardTourDmp.steps[0].title = this.getDmpText();
|
|
|
|
this.dashboardTourDmp.steps[0].selector = '.dmp-tour-' + label;
|
2020-07-31 16:39:57 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 17:27:13 +02:00
|
|
|
public restartTour(label: string): void {
|
|
|
|
this.setDashboardTourDmp(label);
|
|
|
|
this.guidedTourService.startTour(this.dashboardTourDmp);
|
2020-08-06 12:50:28 +02:00
|
|
|
|
2020-07-31 16:39:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 17:04:19 +02:00
|
|
|
registerFormListeners() {
|
2020-09-24 19:28:03 +02:00
|
|
|
// this.formGroup.get('dmp').valueChanges
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(x => {
|
|
|
|
// this.dmpValueChanged(x);
|
|
|
|
// });
|
2020-08-31 01:43:11 +02:00
|
|
|
|
2020-09-08 09:36:18 +02:00
|
|
|
// if (this.isNewDataset) {
|
2020-09-24 19:28:03 +02:00
|
|
|
// this.formGroup.get('profile').valueChanges
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(x => {
|
|
|
|
// if (!isNullOrUndefined(x)) {
|
|
|
|
// this.datasetProfileValueChanged(x.id);
|
|
|
|
// }
|
|
|
|
// });
|
2020-09-08 09:36:18 +02:00
|
|
|
// }
|
2020-07-29 17:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dmpValueChanged(dmp: DmpListingModel) {
|
|
|
|
if (dmp) {
|
|
|
|
this.formGroup.get('profile').enable();
|
|
|
|
this.loadDatasetProfiles();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.availableProfiles = [];
|
|
|
|
this.formGroup.get('profile').reset();
|
|
|
|
this.formGroup.get('profile').disable();
|
|
|
|
this.formGroup.removeControl('datasetProfileDefinition');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 09:45:42 +02:00
|
|
|
datasetProfileValueChanged(profileId: string) {
|
|
|
|
if (profileId && profileId.length > 0) {
|
2020-07-29 17:04:19 +02:00
|
|
|
this.formGroup.removeControl('datasetProfileDefinition');
|
2020-08-25 09:45:42 +02:00
|
|
|
this.getDefinition(profileId);
|
2020-07-29 17:04:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onChanges(): void {
|
|
|
|
this.formGroup.valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(val => {
|
2020-09-24 19:28:03 +02:00
|
|
|
// this.formChanged.emit(val);
|
2020-07-29 17:04:19 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-31 18:08:32 +02:00
|
|
|
onFormChanged(event) {
|
2020-09-24 19:28:03 +02:00
|
|
|
// this.formChanged.emit(event);
|
2020-08-31 18:08:32 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 09:45:42 +02:00
|
|
|
getDefinition(profileId: string) {
|
2020-07-29 17:04:19 +02:00
|
|
|
// if (this.formGroup.invalid) { setTimeout(() => this.stepper.selectedIndex = 0); return; }
|
2020-08-25 09:45:42 +02:00
|
|
|
this.datasetWizardService.getDefinition(profileId)
|
2020-07-29 17:04:19 +02:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(item => {
|
|
|
|
this.datasetWizardModel.datasetProfileDefinition = new DatasetDescriptionFormEditorModel().fromModel(item);
|
|
|
|
this.datasetProfileDefinitionModel = this.datasetWizardModel.datasetProfileDefinition;
|
|
|
|
this.formGroup.addControl('datasetProfileDefinition', this.datasetProfileDefinitionModel.buildForm());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadDatasetProfiles() {
|
|
|
|
const datasetProfileRequestItem: RequestItem<DatasetProfileCriteria> = new RequestItem();
|
|
|
|
datasetProfileRequestItem.criteria = new DatasetProfileCriteria();
|
2020-09-04 18:27:41 +02:00
|
|
|
datasetProfileRequestItem.criteria.id = this.dmpId;
|
2020-07-29 17:04:19 +02:00
|
|
|
if (datasetProfileRequestItem.criteria.id) {
|
|
|
|
this.datasetWizardService.getAvailableProfiles(datasetProfileRequestItem)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(items => {
|
|
|
|
this.availableProfiles = items;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
needsUpdate() {
|
|
|
|
if (this.datasetWizardModel.isProfileLatestVersion || (this.datasetWizardModel.status === DatasetStatus.Finalized)
|
|
|
|
|| (this.datasetWizardModel.isProfileLatestVersion == undefined && this.datasetWizardModel.status == undefined)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private pumpLock() {
|
|
|
|
this.lock.touchedAt = new Date();
|
|
|
|
this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => {
|
|
|
|
if (!isNullOrUndefined(result)) {
|
|
|
|
this.lock.id = Guid.parse(result);
|
|
|
|
} else {
|
|
|
|
this.location.back();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
removeTag(tag: any) {
|
|
|
|
(<FormArray>this.formGroup.get('tags')).removeAt(((<FormArray>this.formGroup.get('tags')).value as any[]).indexOf(tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
addTag(ev: MatChipInputEvent) {
|
|
|
|
if (ev.value !== '' && isNullOrUndefined(((<FormArray>this.formGroup.get('tags')).value as ExternalTagEditorModel[]).find(tag => tag.name === ev.value))) {
|
|
|
|
(<FormArray>this.formGroup.get('tags')).push(new ExternalTagEditorModel('', ev.value).buildForm());
|
|
|
|
}
|
|
|
|
ev.input.value = '';
|
|
|
|
}
|
2020-09-04 16:00:34 +02:00
|
|
|
|
|
|
|
getProfileId(): string {
|
|
|
|
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
|
|
|
|
return this.formGroup.get('profile').value.id;
|
|
|
|
} else {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hasProfileId(): boolean {
|
|
|
|
return !isNullOrUndefined(this.getProfileId());
|
|
|
|
}
|
2020-09-04 18:27:41 +02:00
|
|
|
|
|
|
|
filterProfiles(value: string): Observable<DatasetProfileModel[]> {
|
|
|
|
const request = new DataTableRequest<DatasetProfileCriteria>(null, null, { fields: ['+label'] });
|
|
|
|
const criteria = new DatasetProfileCriteria();
|
|
|
|
criteria.like = value;
|
|
|
|
request.criteria = criteria;
|
|
|
|
return this.dmpService.searchDMPProfiles(request);
|
|
|
|
}
|
2020-09-07 10:02:21 +02:00
|
|
|
|
2020-09-04 18:27:41 +02:00
|
|
|
allAvailableProfiles(event: MouseEvent) {
|
|
|
|
event.stopPropagation();
|
|
|
|
const dialogRef = this.dialog.open(AvailableProfilesComponent, {
|
|
|
|
data: {
|
|
|
|
profiles: this.formGroup.get('profiles')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-07 10:02:21 +02:00
|
|
|
|
|
|
|
public compareWith(object1: any, object2: any) {
|
|
|
|
return object1 && object2 && object1.id === object2.id;
|
|
|
|
}
|
2020-07-29 17:04:19 +02:00
|
|
|
}
|