2019-09-23 13:06:58 +02:00
|
|
|
import { of as observableOf, Observable } from 'rxjs';
|
|
|
|
import { map, catchError, takeUntil } from 'rxjs/operators';
|
2019-06-03 11:01:42 +02:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
|
import { MatStepper } from '@angular/material/stepper';
|
2019-06-03 11:01:42 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import * as FileSaver from 'file-saver';
|
|
|
|
import { ValidationErrorModel } from '../../../common/forms/validation/error-model/validation-error-model';
|
|
|
|
import { BaseComponent } from '../../../core/common/base/base.component';
|
|
|
|
import { DatasetStatus } from '../../../core/common/enum/dataset-status';
|
2019-06-03 11:01:42 +02:00
|
|
|
import { DataTableRequest } from '../../../core/model/data-table/data-table-request';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { DatasetProfileModel } from '../../../core/model/dataset/dataset-profile';
|
|
|
|
import { DmpModel } from '../../../core/model/dmp/dmp';
|
|
|
|
import { DmpListingModel } from '../../../core/model/dmp/dmp-listing';
|
|
|
|
import { DatasetProfileCriteria } from '../../../core/query/dataset-profile/dataset-profile-criteria';
|
|
|
|
import { DmpCriteria } from '../../../core/query/dmp/dmp-criteria';
|
|
|
|
import { RequestItem } from '../../../core/query/request-item';
|
|
|
|
import { DatasetWizardService } from '../../../core/services/dataset-wizard/dataset-wizard.service';
|
|
|
|
import { DmpService } from '../../../core/services/dmp/dmp.service';
|
|
|
|
import { ExternalSourcesConfigurationService } from '../../../core/services/external-sources/external-sources-configuration.service';
|
|
|
|
import { ExternalSourcesService } from '../../../core/services/external-sources/external-sources.service';
|
2019-06-03 11:01:42 +02:00
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '../../../core/services/notification/ui-notification-service';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { SingleAutoCompleteConfiguration } from '../../../library/auto-complete/single/single-auto-complete-configuration';
|
2019-06-03 11:01:42 +02:00
|
|
|
import { ConfirmationDialogComponent } from '../../../library/confirmation-dialog/confirmation-dialog.component';
|
|
|
|
import { ExportMethodDialogComponent } from '../../../library/export-method-dialog/export-method-dialog.component';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { DatasetDescriptionFormEditorModel } from '../../misc/dataset-description-form/dataset-description-form.model';
|
2019-03-28 15:53:17 +01:00
|
|
|
import { DatasetCopyDialogueComponent } from './dataset-copy-dialogue/dataset-copy-dialogue.component';
|
2019-06-03 11:01:42 +02:00
|
|
|
import { DatasetWizardEditorModel } from './dataset-wizard-editor.model';
|
2019-06-27 17:13:33 +02:00
|
|
|
import { DmpStatus } from '../../../core/common/enum/dmp-status';
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dataset-wizard-component',
|
|
|
|
templateUrl: 'dataset-wizard.component.html',
|
|
|
|
styleUrls: ['./dataset-wizard.component.scss']
|
|
|
|
})
|
2019-01-28 14:47:31 +01:00
|
|
|
export class DatasetWizardComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
|
|
|
viewOnly = false;
|
2019-09-23 10:17:03 +02:00
|
|
|
@ViewChild('stepper', { static: false }) stepper: MatStepper;
|
2019-01-18 18:03:45 +01:00
|
|
|
editMode = false;
|
2019-04-01 12:42:46 +02:00
|
|
|
publicMode = false;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
DatasetStatus = DatasetStatus;
|
|
|
|
dmpAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
|
|
|
|
|
|
|
datasetWizardModel: DatasetWizardEditorModel;
|
|
|
|
isNew = true;
|
2019-03-28 15:53:17 +01:00
|
|
|
isCopy = false;
|
2019-06-03 11:01:42 +02:00
|
|
|
formGroup: FormGroup = null;
|
2019-01-18 18:03:45 +01:00
|
|
|
datasetProfileDefinitionModel: DatasetDescriptionFormEditorModel;
|
|
|
|
|
|
|
|
availableProfiles: DatasetProfileModel[] = [];
|
|
|
|
itemId: string;
|
2019-04-02 09:53:38 +02:00
|
|
|
publicId: string;
|
2019-04-22 11:11:21 +02:00
|
|
|
profileUpdateId: string;
|
2019-04-02 09:53:38 +02:00
|
|
|
downloadDocumentId: string;
|
2019-01-18 18:03:45 +01:00
|
|
|
isLinear = false;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private datasetWizardService: DatasetWizardService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public snackBar: MatSnackBar,
|
|
|
|
public router: Router,
|
|
|
|
public language: TranslateService,
|
|
|
|
public externalSourcesService: ExternalSourcesService,
|
|
|
|
public dmpService: DmpService,
|
|
|
|
public dialog: MatDialog,
|
2019-01-24 11:46:29 +01:00
|
|
|
public externalSourcesConfigurationService: ExternalSourcesConfigurationService,
|
2019-01-24 16:30:23 +01:00
|
|
|
private uiNotificationService: UiNotificationService
|
2019-01-18 18:03:45 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route
|
|
|
|
.data
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(v => this.viewOnly = v['public']);
|
|
|
|
|
|
|
|
const dmpRequestItem: RequestItem<DmpCriteria> = new RequestItem();
|
|
|
|
dmpRequestItem.criteria = new DmpCriteria();
|
|
|
|
|
|
|
|
this.dmpAutoCompleteConfiguration = {
|
|
|
|
filterFn: this.searchDmp.bind(this),
|
|
|
|
initialItems: (extraData) => this.searchDmp(''),
|
2019-09-23 13:06:58 +02:00
|
|
|
displayFn: (item) => (item['status'] ? this.language.instant('TYPES.DATASET-STATUS.FINALISED').toUpperCase() : this.language.instant('TYPES.DATASET-STATUS.DRAFT').toUpperCase()) + ': ' + item['label'],
|
|
|
|
titleFn: (item) => item['label'],
|
|
|
|
iconFn: (item) => item['status'] ? 'lock' : 'lock_open'
|
2019-01-18 18:03:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const params = this.route.snapshot.params;
|
2019-03-28 15:53:17 +01:00
|
|
|
const queryParams = this.route.snapshot.queryParams;
|
2019-01-18 18:03:45 +01:00
|
|
|
this.itemId = params['id'];
|
|
|
|
const dmpId = params['dmpId'];
|
2019-03-28 15:53:17 +01:00
|
|
|
const newDmpId = queryParams['newDmpId'];
|
2019-04-02 09:53:38 +02:00
|
|
|
this.publicId = params['publicId'];
|
2019-04-22 11:11:21 +02:00
|
|
|
this.profileUpdateId = params['updateId'];
|
2019-04-02 09:53:38 +02:00
|
|
|
|
|
|
|
this.itemId ? this.downloadDocumentId = this.itemId : this.downloadDocumentId = this.publicId
|
|
|
|
|
2019-03-28 15:53:17 +01:00
|
|
|
if (this.itemId != null && newDmpId == null) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.isNew = false;
|
|
|
|
this.datasetWizardService.getSingle(this.itemId)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
2019-04-22 11:11:21 +02:00
|
|
|
this.needsUpdate();
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-01-18 18:03:45 +01:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.datasetWizardModel.label,
|
|
|
|
url: '/datasets/edit/' + this.datasetWizardModel.id,
|
2019-01-18 18:03:45 +01:00
|
|
|
notFoundResolver: [
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS').toUpperCase(),
|
|
|
|
url: '/datasets'
|
2019-01-18 18:03:45 +01:00
|
|
|
},
|
|
|
|
]
|
|
|
|
}]);
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
2019-06-25 11:16:37 +02:00
|
|
|
if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
2019-02-11 13:04:45 +01:00
|
|
|
// if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
2019-09-13 12:58:36 +02:00
|
|
|
this.loadDatasetProfiles();
|
|
|
|
this.registerFormListeners();
|
|
|
|
// this.availableProfiles = this.datasetWizardModel.dmp.profiles;
|
2019-06-27 17:13:33 +02:00
|
|
|
|
2019-07-26 10:37:26 +02:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.DATAESET-NOT-FOUND'), SnackBarNotificationLevel.Error);
|
|
|
|
this.router.navigate(['/plans']);
|
2019-09-23 10:17:03 +02:00
|
|
|
return observableOf(null);
|
2019-01-18 18:03:45 +01:00
|
|
|
});
|
|
|
|
} else if (dmpId != null) {
|
|
|
|
this.isNew = true;
|
2019-09-23 10:17:03 +02:00
|
|
|
this.dmpService.getSingle(dmpId).pipe(map(data => data as DmpModel))
|
2019-01-18 18:03:45 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel();
|
|
|
|
setTimeout(() => {
|
|
|
|
this.datasetWizardModel.dmp = data;
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
2019-07-02 17:28:43 +02:00
|
|
|
this.formGroup.get('dmp').disable();
|
2019-06-27 17:13:33 +02:00
|
|
|
|
2019-09-13 12:35:45 +02:00
|
|
|
this.loadDatasetProfiles();
|
|
|
|
this.registerFormListeners();
|
2019-09-13 12:58:36 +02:00
|
|
|
// this.availableProfiles = data.profiles;
|
2019-06-27 17:13:33 +02:00
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-01-18 18:03:45 +01:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS'),
|
2019-01-18 18:03:45 +01:00
|
|
|
url: '/datasets',
|
|
|
|
notFoundResolver: [
|
2019-10-04 09:53:35 +02:00
|
|
|
// {
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.datasetWizardModel.dmp.grant.label,
|
|
|
|
// url: '/grants/edit/' + this.datasetWizardModel.dmp.grant.id
|
|
|
|
// },
|
2019-01-18 18:03:45 +01:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.datasetWizardModel.dmp.label,
|
|
|
|
url: '/plans/edit/' + this.datasetWizardModel.dmp.id,
|
|
|
|
}]
|
|
|
|
}]);
|
|
|
|
});
|
|
|
|
});
|
2019-03-28 15:53:17 +01:00
|
|
|
} else if (newDmpId != null) {
|
|
|
|
this.isNew = false;
|
|
|
|
this.isCopy = true;
|
|
|
|
this.datasetWizardService.getSingle(this.itemId)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.formGroup.get('id').setValue(null);
|
2019-09-23 10:17:03 +02:00
|
|
|
this.dmpService.getSingle(newDmpId).pipe(map(data => data as DmpModel))
|
2019-03-28 15:53:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.datasetWizardModel.dmp = data;
|
|
|
|
this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp);
|
|
|
|
|
2019-09-13 12:35:45 +02:00
|
|
|
this.loadDatasetProfiles();
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-03-28 15:53:17 +01:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS'),
|
2019-03-28 15:53:17 +01:00
|
|
|
url: '/datasets',
|
|
|
|
notFoundResolver: [
|
2019-10-04 09:53:35 +02:00
|
|
|
// {
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.datasetWizardModel.dmp.grant.label,
|
|
|
|
// url: '/grants/edit/' + this.datasetWizardModel.dmp.grant.id
|
|
|
|
// },
|
2019-03-28 15:53:17 +01:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.datasetWizardModel.dmp.label,
|
|
|
|
url: '/plans/edit/' + this.datasetWizardModel.dmp.id,
|
2019-06-07 17:21:09 +02:00
|
|
|
}
|
|
|
|
]
|
2019-03-28 15:53:17 +01:00
|
|
|
}]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
2019-06-25 11:16:37 +02:00
|
|
|
if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
2019-03-28 15:53:17 +01:00
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
|
|
|
// if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
2019-09-13 12:35:45 +02:00
|
|
|
this.loadDatasetProfiles();
|
2019-09-13 12:58:36 +02:00
|
|
|
// this.availableProfiles = data.dmp.profiles;
|
2019-03-28 15:53:17 +01:00
|
|
|
});
|
2019-06-07 17:21:09 +02:00
|
|
|
} else if (this.publicId != null) { // For Finalized -> Public Datasets
|
|
|
|
this.isNew = false;
|
2019-04-02 09:53:38 +02:00
|
|
|
this.datasetWizardService.getSinglePublic(this.publicId)
|
2019-09-23 10:17:03 +02:00
|
|
|
.pipe(takeUntil(this._destroyed)).pipe(
|
2019-09-23 11:11:00 +02:00
|
|
|
catchError((error: any) => {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message, SnackBarNotificationLevel.Error);
|
|
|
|
this.router.navigate(['/explore']);
|
|
|
|
return observableOf(null);
|
|
|
|
}))
|
2019-04-01 12:42:46 +02:00
|
|
|
.subscribe(data => {
|
|
|
|
if (data) {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
2019-06-25 11:16:37 +02:00
|
|
|
if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
2019-04-01 12:42:46 +02:00
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
|
|
|
this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp);
|
|
|
|
this.loadDatasetProfiles();
|
2019-06-07 17:21:09 +02:00
|
|
|
const breadcrumbs = [];
|
2019-06-21 15:48:22 +02:00
|
|
|
breadcrumbs.push({ parentComponentName: null, label: this.language.instant('NAV-BAR.PUBLIC DATASETS'), url: '/explore' });
|
|
|
|
breadcrumbs.push({ parentComponentName: null, label: this.datasetWizardModel.label, url: '/datasets/publicEdit/' + this.datasetWizardModel.id });
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf(breadcrumbs);
|
2019-04-01 12:42:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.publicMode = true;
|
2019-04-22 11:11:21 +02:00
|
|
|
} else if (this.profileUpdateId != null) {
|
|
|
|
this.datasetWizardService.updateDatasetProfile(this.profileUpdateId)
|
2019-04-25 17:20:16 +02:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
2019-04-22 11:11:21 +02:00
|
|
|
.subscribe(data => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
|
|
|
this.needsUpdate();
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-04-22 11:11:21 +02:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS'),
|
2019-04-22 11:11:21 +02:00
|
|
|
url: '/datasets',
|
|
|
|
notFoundResolver: [
|
2019-10-04 09:53:35 +02:00
|
|
|
// {
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.datasetWizardModel.dmp.grant.label,
|
|
|
|
// url: '/grants/edit/' + this.datasetWizardModel.dmp.grant.id
|
|
|
|
// },
|
2019-04-22 11:11:21 +02:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.datasetWizardModel.dmp.label,
|
|
|
|
url: '/plans/edit/' + this.datasetWizardModel.dmp.id,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}]);
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
2019-06-25 11:16:37 +02:00
|
|
|
if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
2019-04-22 11:11:21 +02:00
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
|
|
|
// if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
|
|
|
this.loadDatasetProfiles();
|
|
|
|
});
|
|
|
|
} else {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel();
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
2019-06-25 11:16:37 +02:00
|
|
|
if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
2019-02-11 13:04:45 +01:00
|
|
|
//if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
2019-06-27 17:13:33 +02:00
|
|
|
this.registerFormListeners();
|
2019-06-03 11:01:42 +02:00
|
|
|
this.dmpValueChanged(null);
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-06-07 13:03:10 +02:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.language.instant('DATASET-LISTING.ACTIONS.CREATE-NEW').toUpperCase(),
|
|
|
|
url: '/datasets/new/'
|
|
|
|
}]);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
2019-06-03 11:01:42 +02:00
|
|
|
|
|
|
|
// this.route.params
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe((params: Params) => {
|
|
|
|
// const itemId = params['id'];
|
|
|
|
// if (itemId != null) { setTimeout(() => this.stepper.selectedIndex = 2); }
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
2019-06-27 17:13:33 +02:00
|
|
|
registerFormListeners() {
|
|
|
|
this.formGroup.get('dmp').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.dmpValueChanged(x);
|
|
|
|
});
|
|
|
|
this.formGroup.get('profile').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.datasetProfileValueChanged(x);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-03 11:01:42 +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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
datasetProfileValueChanged(profiledId: string) {
|
|
|
|
if (profiledId && profiledId.length > 0) {
|
|
|
|
this.formGroup.removeControl('datasetProfileDefinition');
|
|
|
|
this.getDefinition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
searchDmp(query: string): Observable<DmpListingModel[]> {
|
2019-01-29 17:25:40 +01:00
|
|
|
const fields: Array<string> = new Array<string>();
|
|
|
|
fields.push('asc');
|
|
|
|
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, null, { fields: fields });
|
|
|
|
dmpDataTableRequest.criteria = new DmpCriteria();
|
|
|
|
dmpDataTableRequest.criteria.like = query;
|
2019-09-23 10:17:03 +02:00
|
|
|
return this.dmpService.getPaged(dmpDataTableRequest, "autocomplete").pipe(map(x => x.data));
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
loadDatasetProfiles() {
|
|
|
|
const datasetProfileRequestItem: RequestItem<DatasetProfileCriteria> = new RequestItem();
|
|
|
|
datasetProfileRequestItem.criteria = new DatasetProfileCriteria();
|
|
|
|
datasetProfileRequestItem.criteria.id = this.formGroup.get('dmp').value.id;
|
|
|
|
if (datasetProfileRequestItem.criteria.id) {
|
|
|
|
this.datasetWizardService.getAvailableProfiles(datasetProfileRequestItem)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(items => {
|
|
|
|
this.availableProfiles = items;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public cancel(): void {
|
2019-06-03 11:01:42 +02:00
|
|
|
this.router.navigate(['/datasets']);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getDefinition() {
|
2019-06-03 11:01:42 +02:00
|
|
|
// if (this.formGroup.invalid) { setTimeout(() => this.stepper.selectedIndex = 0); return; }
|
|
|
|
this.datasetWizardService.getDefinition(this.formGroup.get('profile').value)
|
|
|
|
.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());
|
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
formSubmit(): void {
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
this.onSubmit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public isFormValid() {
|
|
|
|
return this.formGroup.valid;
|
|
|
|
}
|
|
|
|
|
2019-07-02 17:28:43 +02:00
|
|
|
public isSemiFormValid(formGroup: FormGroup): boolean {
|
|
|
|
var isValid: boolean = true;
|
2019-07-26 10:37:26 +02:00
|
|
|
Object.keys(formGroup.controls).forEach(controlName => {
|
2019-07-02 17:28:43 +02:00
|
|
|
if (controlName != 'datasetProfileDefinition' && formGroup.get(controlName).invalid) {
|
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return isValid;
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
onSubmit(): void {
|
|
|
|
this.datasetWizardService.createDataset(this.formGroup.value)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-09-23 11:11:00 +02:00
|
|
|
complete => {
|
|
|
|
this.datasetWizardService.getSingle(complete.id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
result => {
|
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(result);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
this.onCallbackSuccess();
|
|
|
|
},
|
|
|
|
error => this.onCallbackError(error)
|
2019-01-18 18:03:45 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
submit() {
|
2019-08-21 12:20:05 +02:00
|
|
|
this.datasetWizardService.createDataset(this.formGroup.getRawValue())
|
2019-01-18 18:03:45 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
2019-04-25 17:20:16 +02:00
|
|
|
this.router.navigate(['datasets'], { queryParams: { dmpId: this.formGroup.get('dmp').value.id } });
|
2019-01-18 18:03:45 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
|
2019-09-23 13:06:58 +02:00
|
|
|
hasReversableStatus(): boolean {
|
2019-09-24 17:32:23 +02:00
|
|
|
if (this.formGroup.get('dmp').value) {
|
|
|
|
return (this.formGroup.get('dmp').value.status == DmpStatus.Draft && this.formGroup.get('status').value == DatasetStatus.Finalized);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-23 13:06:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasNotReversableStatus(): boolean {
|
2019-09-24 17:32:23 +02:00
|
|
|
if (this.formGroup.get('dmp').value) {
|
|
|
|
return (this.formGroup.get('dmp').value.status == DmpStatus.Finalized && this.formGroup.get('status').value == DatasetStatus.Finalized);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-23 13:06:58 +02:00
|
|
|
}
|
|
|
|
|
2019-06-27 17:13:33 +02:00
|
|
|
reverse() {
|
2019-09-23 13:06:58 +02:00
|
|
|
this.viewOnly = false;
|
2019-06-27 17:13:33 +02:00
|
|
|
this.datasetWizardModel.status = DatasetStatus.Draft;
|
|
|
|
setTimeout(x => { this.formGroup = null; });
|
|
|
|
setTimeout(x => {
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.registerFormListeners();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
saveFinalize() {
|
2019-06-26 11:24:06 +02:00
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-06-26 11:24:06 +02:00
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.FINALIZE-ITEM'),
|
|
|
|
confirmButton: this.language.instant('QUICKWIZARD.SAVE-DIALOG.ACTIONS.AFFIRMATIVE'),
|
|
|
|
cancelButton: this.language.instant('QUICKWIZARD.SAVE-DIALOG.ACTIONS.NEGATIVE'),
|
|
|
|
isDeleteConfirmation: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
this.formGroup.get('status').setValue(DatasetStatus.Finalized);
|
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackSuccess(): void {
|
2019-01-24 11:46:29 +01:00
|
|
|
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(error: any) {
|
|
|
|
this.setErrorModel(error.error);
|
|
|
|
}
|
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
public setErrorModel(validationErrorModel: ValidationErrorModel) {
|
|
|
|
Object.keys(validationErrorModel).forEach(item => {
|
|
|
|
(<any>this.datasetWizardModel.validationErrorModel)[item] = (<any>validationErrorModel)[item];
|
2019-01-18 18:03:45 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadPDF(): void {
|
2019-04-02 09:53:38 +02:00
|
|
|
this.datasetWizardService.downloadPDF(this.downloadDocumentId)
|
2019-01-18 18:03:45 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/pdf' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-26 15:45:27 +01:00
|
|
|
downloadDOCX(): void {
|
2019-04-02 09:53:38 +02:00
|
|
|
this.datasetWizardService.downloadDOCX(this.downloadDocumentId)
|
2019-03-28 15:53:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
2019-03-26 15:45:27 +01:00
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/msword' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
downloadXML(): void {
|
2019-04-02 09:53:38 +02:00
|
|
|
this.datasetWizardService.downloadXML(this.downloadDocumentId)
|
2019-01-18 18:03:45 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/xml' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-25 11:44:22 +02:00
|
|
|
// advancedClicked() {
|
|
|
|
// const dialogRef = this.dialog.open(ExportMethodDialogComponent, {
|
|
|
|
// maxWidth: '500px',
|
|
|
|
// data: {
|
|
|
|
// message: "Download as:",
|
|
|
|
// XMLButton: "XML",
|
|
|
|
// documentButton: "Document",
|
|
|
|
// pdfButton: "PDF"
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
// if (result == "pdf") {
|
|
|
|
// this.downloadPDF();
|
|
|
|
// } else if (result == "xml") {
|
|
|
|
// this.downloadXML();
|
|
|
|
// } else if (result == "doc") {
|
|
|
|
// this.downloadDOCX();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
2019-06-03 11:01:42 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
getFilenameFromContentDispositionHeader(header: string): string {
|
|
|
|
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
|
|
|
|
|
|
|
|
const matches = header.match(regex);
|
|
|
|
let filename: string;
|
|
|
|
for (let i = 0; i < matches.length; i++) {
|
|
|
|
const match = matches[i];
|
|
|
|
if (match.includes('filename="')) {
|
|
|
|
filename = match.substring(10, match.length - 1);
|
|
|
|
break;
|
|
|
|
} else if (match.includes('filename=')) {
|
|
|
|
filename = match.substring(9);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
public redirectToGrant() {
|
|
|
|
this.router.navigate(['grants/edit/' + this.datasetWizardModel.dmp.grant.id]);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public redirectToDmp() {
|
|
|
|
this.router.navigate(['plans/edit/' + this.datasetWizardModel.dmp.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public enableForm() {
|
|
|
|
if (this.formGroup.get('status').value !== DatasetStatus.Finalized) {
|
|
|
|
this.editMode = true;
|
|
|
|
this.viewOnly = false;
|
|
|
|
this.formGroup.enable();
|
|
|
|
} else {
|
|
|
|
this.datasetWizardService.unlock(this.formGroup.get('id').value)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.editMode = true;
|
|
|
|
this.viewOnly = false;
|
|
|
|
this.datasetWizardModel.status = DatasetStatus.Draft;
|
|
|
|
this.formGroup.get('status').patchValue(DatasetStatus.Draft);
|
|
|
|
this.formGroup.enable();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public disableForm() {
|
|
|
|
this.editMode = false;
|
2019-02-12 13:19:03 +01:00
|
|
|
//this.viewOnly = true;
|
2019-01-18 18:03:45 +01:00
|
|
|
this.formGroup.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
isActiveStep(index: number) {
|
|
|
|
return this.stepper.selectedIndex === index;
|
|
|
|
}
|
|
|
|
|
|
|
|
openConfirm(dmpLabel, id): void {
|
2019-01-29 08:56:46 +01:00
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
2019-06-03 11:01:42 +02:00
|
|
|
maxWidth: '300px',
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-01-29 08:56:46 +01:00
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
2019-06-27 17:13:33 +02:00
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'),
|
2019-06-26 11:24:06 +02:00
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
2019-06-27 17:13:33 +02:00
|
|
|
isDeleteConfirmation: true
|
2019-01-29 08:56:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this.datasetWizardService.delete(id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-09-23 11:11:00 +02:00
|
|
|
complete => { this.onCallbackSuccess(); this.router.navigateByUrl('/datasets') },
|
|
|
|
error => this.onCallbackError(error)
|
2019-01-29 08:56:46 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
2019-03-28 15:53:17 +01:00
|
|
|
|
|
|
|
openDmpSearchDialogue() {
|
|
|
|
const formControl = new FormControl();
|
|
|
|
const dialogRef = this.dialog.open(DatasetCopyDialogueComponent, {
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-03-28 15:53:17 +01:00
|
|
|
data: {
|
|
|
|
formControl: formControl,
|
|
|
|
datasetId: this.formGroup.value.id,
|
|
|
|
datasetProfileId: this.formGroup.value.profile,
|
|
|
|
datasetProfileExist: false,
|
2019-04-16 15:47:02 +02:00
|
|
|
confirmButton: this.language.instant('DATASET-WIZARD.DIALOGUE.COPY'),
|
|
|
|
cancelButton: this.language.instant('DATASET-WIZARD.DIALOGUE.CANCEL')
|
2019-03-28 15:53:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
if (result && result.datasetProfileExist) {
|
|
|
|
const newDmpId = result.formControl.value.id
|
|
|
|
this.router.navigate(['/datasets/copy/' + result.datasetId], { queryParams: { newDmpId: newDmpId } });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-04-22 11:11:21 +02:00
|
|
|
|
|
|
|
needsUpdate() {
|
2019-06-25 11:16:37 +02:00
|
|
|
if (this.datasetWizardModel.isProfileLatestVersion || (this.datasetWizardModel.status === DatasetStatus.Finalized)
|
2019-04-25 17:17:29 +02:00
|
|
|
|| (this.datasetWizardModel.isProfileLatestVersion == undefined && this.datasetWizardModel.status == undefined)) {
|
2019-04-22 11:11:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
openUpdateDatasetProfileDialogue() {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-04-22 11:11:21 +02:00
|
|
|
data: {
|
|
|
|
message: this.language.instant('DATASET-EDITOR.VERSION-DIALOG.QUESTION'),
|
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
2019-06-26 11:24:06 +02:00
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: false
|
2019-04-22 11:11:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this.profileUpdateId = this.itemId;
|
2019-07-26 10:37:26 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.SUCCESS-UPDATE-DATASET-PROFILE'), SnackBarNotificationLevel.Success);
|
2019-04-22 11:11:21 +02:00
|
|
|
this.router.navigate(['/datasets/profileupdate/' + this.profileUpdateId]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|