2019-09-23 10:17:03 +02:00
|
|
|
|
2020-07-17 16:46:53 +02:00
|
|
|
import { Component, OnInit, SimpleChanges } from '@angular/core';
|
2020-08-31 18:08:32 +02:00
|
|
|
import { FormGroup, AbstractControl, FormControl, FormArray, FormBuilder } from '@angular/forms';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DmpStatus } from '@app/core/common/enum/dmp-status';
|
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
2020-07-20 17:24:29 +02:00
|
|
|
import { DmpProfileDefinition, DmpProfile } from '@app/core/model/dmp-profile/dmp-profile';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DmpProfileListing } from '@app/core/model/dmp-profile/dmp-profile-listing';
|
|
|
|
import { DmpModel } from '@app/core/model/dmp/dmp';
|
|
|
|
import { UserModel } from '@app/core/model/user/user';
|
|
|
|
import { UserInfoListingModel } from '@app/core/model/user/user-info-listing';
|
|
|
|
import { BaseCriteria } from '@app/core/query/base-criteria';
|
|
|
|
import { DmpProfileCriteria } from '@app/core/query/dmp/dmp-profile-criteria';
|
|
|
|
import { GrantCriteria } from '@app/core/query/grant/grant-criteria';
|
|
|
|
import { RequestItem } from '@app/core/query/request-item';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
|
|
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
2019-12-19 14:48:24 +01:00
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DmpEditorModel } from '@app/ui/dmp/editor/dmp-editor.model';
|
|
|
|
import { DmpFinalizeDialogComponent, DmpFinalizeDialogInput } from '@app/ui/dmp/editor/dmp-finalize-dialog/dmp-finalize-dialog.component';
|
|
|
|
import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model';
|
|
|
|
import { GrantTabModel } from '@app/ui/dmp/editor/grant-tab/grant-tab-model';
|
|
|
|
import { ProjectFormModel } from '@app/ui/dmp/editor/grant-tab/project-form-model';
|
|
|
|
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { FormService } from '@common/forms/form-service';
|
|
|
|
import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component';
|
|
|
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
2018-10-05 17:00:54 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-11-27 18:33:17 +01:00
|
|
|
import * as FileSaver from 'file-saver';
|
2020-02-11 17:27:54 +01:00
|
|
|
import { Observable, of as observableOf, interval } from 'rxjs';
|
2020-10-06 10:21:15 +02:00
|
|
|
import { delay, map, takeUntil } from 'rxjs/operators';
|
2020-04-27 15:21:03 +02:00
|
|
|
import { Principal } from "@app/core/model/auth/principal";
|
2019-12-19 14:48:24 +01:00
|
|
|
import { Role } from "@app/core/common/enum/role";
|
2020-02-11 17:27:54 +01:00
|
|
|
import { LockService } from '@app/core/services/lock/lock.service';
|
|
|
|
import { LockModel } from '@app/core/model/lock/lock.model';
|
|
|
|
import { Guid } from '@common/types/guid';
|
2020-03-26 17:44:12 +01:00
|
|
|
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
2020-06-03 11:13:31 +02:00
|
|
|
import { ExtraPropertiesFormModel } from './general-tab/extra-properties-form.model';
|
2020-08-04 13:35:02 +02:00
|
|
|
import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
2020-08-06 12:20:28 +02:00
|
|
|
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
|
|
|
|
import { DmpListingModel } from '@app/core/model/dmp/dmp-listing';
|
|
|
|
import { DmpCriteria } from '@app/core/query/dmp/dmp-criteria';
|
2020-08-24 14:46:55 +02:00
|
|
|
import { DatasetDescriptionFormEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
|
2020-08-25 17:34:28 +02:00
|
|
|
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
|
2020-09-03 11:52:35 +02:00
|
|
|
import { CloneDialogComponent } from '../clone/clone-dialog/clone-dialog.component';
|
2020-09-04 18:27:41 +02:00
|
|
|
import { DatasetWizardModel } from '@app/core/model/dataset/dataset-wizard';
|
2020-09-08 15:54:01 +02:00
|
|
|
import { DatasetService } from '@app/core/services/dataset/dataset.service';
|
2020-10-05 10:34:08 +02:00
|
|
|
import { DmpToDatasetDialogComponent } from '../dmp-to-dataset/dmp-to-dataset-dialog.component';
|
2020-10-07 11:42:10 +02:00
|
|
|
import { GrantEditorModel } from '@app/ui/grant/editor/grant-editor.model';
|
2017-12-14 18:13:28 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-dmp-editor-component',
|
|
|
|
templateUrl: 'dmp-editor.component.html',
|
2019-01-18 18:03:45 +01:00
|
|
|
styleUrls: ['./dmp-editor.component.scss']
|
2017-12-14 18:13:28 +01:00
|
|
|
})
|
2019-01-24 16:30:23 +01:00
|
|
|
export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
2017-12-18 11:01:22 +01:00
|
|
|
|
2019-05-21 15:42:28 +02:00
|
|
|
editMode = true;
|
|
|
|
// editMode = false;
|
2017-12-21 10:16:46 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
|
|
|
isNew = true;
|
2019-04-26 16:05:15 +02:00
|
|
|
isPublic = false;
|
2019-06-25 15:02:54 +02:00
|
|
|
isFinalized = false;
|
2020-08-06 12:20:28 +02:00
|
|
|
hasChanges = false;
|
2020-08-31 01:43:11 +02:00
|
|
|
isDiscarded = false;
|
2020-08-31 18:08:32 +02:00
|
|
|
hasDmpId = false;
|
2020-08-06 12:20:28 +02:00
|
|
|
isUserOwner: boolean = true;
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
dmp: DmpEditorModel;
|
2020-09-04 18:27:41 +02:00
|
|
|
dmpModel: DmpModel;
|
2018-10-05 17:00:54 +02:00
|
|
|
formGroup: FormGroup = null;
|
2020-08-25 17:34:28 +02:00
|
|
|
// datasetFormGroup: FormGroup;
|
2020-07-17 16:46:53 +02:00
|
|
|
formGroupRawValue: any;
|
2020-08-06 12:20:28 +02:00
|
|
|
datasetId: string = null;
|
|
|
|
datasets = new FormArray([]);
|
2020-08-31 18:08:32 +02:00
|
|
|
datasetWizardEditorModel: DatasetWizardEditorModel;
|
2018-10-05 17:00:54 +02:00
|
|
|
createNewVersion;
|
2020-08-06 12:20:28 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
associatedUsers: Array<UserModel>;
|
2019-05-28 09:49:09 +02:00
|
|
|
people: Array<UserInfoListingModel>;
|
2019-02-13 14:44:08 +01:00
|
|
|
filteredOptions: DmpProfileListing[];
|
|
|
|
selectedDmpProfileDefinition: DmpProfileDefinition;
|
2020-08-06 12:20:28 +02:00
|
|
|
|
2019-02-13 14:44:08 +01:00
|
|
|
DynamicDmpFieldResolverComponent: any;
|
2020-02-11 17:27:54 +01:00
|
|
|
lock: LockModel;
|
|
|
|
lockStatus: Boolean;
|
2020-08-06 12:20:28 +02:00
|
|
|
|
|
|
|
selectedTab = 0;
|
2020-07-17 16:46:53 +02:00
|
|
|
step: number = 0;
|
2020-09-09 16:52:42 +02:00
|
|
|
stepsBeforeDatasets: number = 4;
|
|
|
|
maxStep: number = 4;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
constructor(
|
2019-01-18 18:03:45 +01:00
|
|
|
private dmpProfileService: DmpProfileService,
|
2020-08-25 17:34:28 +02:00
|
|
|
private datasetWizardService: DatasetWizardService,
|
2020-09-08 15:54:01 +02:00
|
|
|
private datasetService: DatasetService,
|
2019-01-18 18:03:45 +01:00
|
|
|
private dmpService: DmpService,
|
2018-10-05 17:00:54 +02:00
|
|
|
private route: ActivatedRoute,
|
2019-01-18 18:03:45 +01:00
|
|
|
private router: Router,
|
|
|
|
private language: TranslateService,
|
|
|
|
private dialog: MatDialog,
|
2019-04-26 16:05:15 +02:00
|
|
|
private uiNotificationService: UiNotificationService,
|
2019-12-19 14:48:24 +01:00
|
|
|
private authentication: AuthService,
|
2019-04-26 16:05:15 +02:00
|
|
|
private authService: AuthService,
|
2020-02-11 17:27:54 +01:00
|
|
|
private formService: FormService,
|
2020-03-26 17:44:12 +01:00
|
|
|
private lockService: LockService,
|
|
|
|
private configurationService: ConfigurationService
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
2018-11-27 18:33:17 +01:00
|
|
|
super();
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:30:23 +01:00
|
|
|
ngOnInit() {
|
2018-11-27 18:33:17 +01:00
|
|
|
this.route.params
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe((params: Params) => {
|
|
|
|
const itemId = params['id'];
|
2019-04-26 16:05:15 +02:00
|
|
|
const publicId = params['publicId'];
|
2019-07-18 16:16:12 +02:00
|
|
|
const queryParams = this.route.snapshot.queryParams;
|
|
|
|
const tabToNav = queryParams['tab'];
|
2020-08-31 18:08:32 +02:00
|
|
|
const dmpId = params['dmpId'];
|
2020-08-04 13:35:02 +02:00
|
|
|
this.datasetId = queryParams['dataset'];
|
|
|
|
// if (queryParams['step']) { this.step = queryParams['step']; }
|
2018-11-27 18:33:17 +01:00
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
const grantRequestItem: RequestItem<GrantCriteria> = new RequestItem();
|
|
|
|
grantRequestItem.criteria = new GrantCriteria();
|
2018-11-27 18:33:17 +01:00
|
|
|
const organisationRequestItem: RequestItem<BaseCriteria> = new RequestItem();
|
|
|
|
organisationRequestItem.criteria = new BaseCriteria();
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
// this.grantAutoCompleteConfiguration = {
|
|
|
|
// filterFn: this.searchGrant.bind(this),
|
|
|
|
// initialItems: (extraData) => this.searchGrant(''),
|
2019-05-28 09:49:09 +02:00
|
|
|
// displayFn: (item) => item['label'],
|
|
|
|
// titleFn: (item) => item['label']
|
|
|
|
// };
|
2020-08-04 13:35:02 +02:00
|
|
|
|
2020-04-27 15:21:03 +02:00
|
|
|
switch (tabToNav) {
|
2020-04-01 17:16:06 +02:00
|
|
|
case 'general':
|
|
|
|
this.selectedTab = 0;
|
|
|
|
break;
|
|
|
|
case 'grant':
|
|
|
|
this.selectedTab = 1;
|
|
|
|
break;
|
|
|
|
case 'datasetDescriptions':
|
|
|
|
this.selectedTab = 2;
|
|
|
|
break;
|
|
|
|
case 'peoples':
|
|
|
|
this.selectedTab = 3;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-27 18:33:17 +01:00
|
|
|
if (itemId != null) {
|
|
|
|
this.isNew = false;
|
2019-09-23 10:17:03 +02:00
|
|
|
this.dmpService.getSingle(itemId).pipe(map(data => data as DmpModel))
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(async data => {
|
2020-02-11 17:27:54 +01:00
|
|
|
this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => {
|
|
|
|
this.lockStatus = lockStatus;
|
2020-09-04 18:27:41 +02:00
|
|
|
this.dmpModel = data;
|
|
|
|
|
2020-04-27 15:21:03 +02:00
|
|
|
this.dmp = new DmpEditorModel();
|
|
|
|
this.dmp.grant = new GrantTabModel();
|
|
|
|
this.dmp.project = new ProjectFormModel();
|
|
|
|
this.dmp.funder = new FunderFormModel();
|
2020-06-03 11:13:31 +02:00
|
|
|
this.dmp.extraProperties = new ExtraPropertiesFormModel();
|
2020-04-27 15:21:03 +02:00
|
|
|
this.dmp.fromModel(data);
|
|
|
|
this.formGroup = this.dmp.buildForm();
|
2020-10-05 10:34:08 +02:00
|
|
|
// console.log(this.formGroup);
|
2020-08-06 12:20:28 +02:00
|
|
|
|
2020-08-04 13:35:02 +02:00
|
|
|
this.datasets = this.formGroup.get('datasets') as FormArray;
|
2020-08-31 01:43:11 +02:00
|
|
|
|
2020-07-20 17:24:29 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2020-07-29 17:04:19 +02:00
|
|
|
this.maxStep = this.formGroup.get('datasets') ? this.maxStep + this.formGroup.get('datasets').value.length - 1 : this.maxStep;
|
2020-07-20 17:24:29 +02:00
|
|
|
|
2020-04-27 15:21:03 +02:00
|
|
|
this.setIsUserOwner();
|
|
|
|
if (!this.isUserOwner) {
|
|
|
|
this.isFinalized = true;
|
|
|
|
this.formGroup.disable();
|
|
|
|
}
|
2020-02-11 17:27:54 +01:00
|
|
|
|
2020-08-04 13:35:02 +02:00
|
|
|
if (this.datasetId) {
|
|
|
|
this.step = this.formGroup.get('datasets')['controls'].findIndex((dataset) => { return this.datasetId === dataset.get('id').value; }) + this.stepsBeforeDatasets;
|
|
|
|
}
|
|
|
|
|
2020-04-27 15:21:03 +02:00
|
|
|
//this.registerFormEventsForDmpProfile(this.dmp.definition);
|
|
|
|
if (!this.editMode || this.dmp.status === DmpStatus.Finalized || lockStatus) {
|
|
|
|
this.isFinalized = true;
|
|
|
|
this.formGroup.disable();
|
2020-02-11 17:27:54 +01:00
|
|
|
}
|
2020-04-27 15:21:03 +02:00
|
|
|
|
|
|
|
if (this.isAuthenticated) {
|
|
|
|
if (!lockStatus) {
|
|
|
|
this.lock = new LockModel(data.id, this.getUserFromDMP());
|
|
|
|
|
|
|
|
this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => {
|
|
|
|
this.lock.id = Guid.parse(result);
|
|
|
|
interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// if (!this.isAuthenticated) {
|
|
|
|
const breadCrumbs = [];
|
|
|
|
breadCrumbs.push({
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.language.instant('NAV-BAR.MY-DMPS'),
|
|
|
|
url: "/plans"
|
|
|
|
});
|
|
|
|
breadCrumbs.push({
|
|
|
|
parentComponentName: 'DmpListingComponent',
|
|
|
|
label: this.dmp.label,
|
|
|
|
url: '/plans/edit/' + this.dmp.id,
|
|
|
|
// notFoundResolver: [await this.grantService.getSingle(this.dmp.grant.id).map(x => ({ label: x.label, url: '/grants/edit/' + x.id }) as BreadcrumbItem).toPromise()]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
this.breadCrumbs = observableOf(breadCrumbs);
|
2019-06-07 17:21:09 +02:00
|
|
|
}
|
2020-04-27 15:21:03 +02:00
|
|
|
this.associatedUsers = data.associatedUsers;
|
|
|
|
this.people = data.users;
|
2020-09-24 19:28:03 +02:00
|
|
|
this.formGroup.valueChanges.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
2020-04-27 15:21:03 +02:00
|
|
|
})
|
2018-11-27 18:33:17 +01:00
|
|
|
});
|
2019-04-26 16:05:15 +02:00
|
|
|
} else if (publicId != null) {
|
|
|
|
this.isNew = false;
|
|
|
|
this.isPublic = true;
|
2020-04-01 17:16:06 +02:00
|
|
|
this.isFinalized = true;
|
2019-09-23 10:17:03 +02:00
|
|
|
this.dmpService.getSinglePublic(publicId).pipe(map(data => data as DmpModel))
|
2019-04-26 16:05:15 +02:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(async data => {
|
2020-04-01 17:16:06 +02:00
|
|
|
// this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => {
|
|
|
|
// this.lockStatus = true;
|
2020-09-04 18:27:41 +02:00
|
|
|
this.dmpModel = data;
|
|
|
|
|
2019-06-12 15:01:55 +02:00
|
|
|
this.dmp = new DmpEditorModel();
|
2019-08-01 09:54:40 +02:00
|
|
|
this.dmp.grant = new GrantTabModel();
|
2019-08-20 17:32:42 +02:00
|
|
|
this.dmp.project = new ProjectFormModel();
|
2019-08-26 16:29:57 +02:00
|
|
|
this.dmp.funder = new FunderFormModel();
|
2020-06-03 11:13:31 +02:00
|
|
|
this.dmp.extraProperties = new ExtraPropertiesFormModel();
|
2019-06-12 15:01:55 +02:00
|
|
|
this.dmp.fromModel(data);
|
2019-04-26 16:05:15 +02:00
|
|
|
this.formGroup = this.dmp.buildForm();
|
2020-07-20 17:24:29 +02:00
|
|
|
|
2020-08-06 12:20:28 +02:00
|
|
|
// this.formGroup.get('datasets')['controls'].forEach(element => {
|
|
|
|
// this.datasets.push(element);
|
|
|
|
// });
|
|
|
|
this.datasets = this.formGroup.get('datasets') as FormArray;
|
2020-07-20 17:24:29 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2020-07-29 17:04:19 +02:00
|
|
|
this.maxStep = this.formGroup.get('datasets') ? this.maxStep + this.formGroup.get('datasets').value.length - 1 : this.maxStep;
|
2020-07-20 17:24:29 +02:00
|
|
|
|
2019-05-23 17:48:54 +02:00
|
|
|
//this.registerFormEventsForDmpProfile(this.dmp.definition);
|
2020-04-01 17:16:06 +02:00
|
|
|
this.formGroup.disable();
|
2019-06-11 10:25:32 +02:00
|
|
|
// if (!this.isAuthenticated) {
|
2019-06-21 15:55:38 +02:00
|
|
|
const breadcrumbs = [];
|
2019-06-25 15:02:54 +02:00
|
|
|
breadcrumbs.push({ parentComponentName: null, label: this.language.instant('NAV-BAR.PUBLIC-DMPS').toUpperCase(), url: '/plans' });
|
2019-06-21 15:55:38 +02:00
|
|
|
breadcrumbs.push({ parentComponentName: null, label: this.dmp.label, url: '/plans/publicEdit/' + this.dmp.id });
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf(breadcrumbs);
|
2019-06-21 15:55:38 +02:00
|
|
|
// this.breadCrumbs = Observable.of([
|
|
|
|
// {
|
|
|
|
// parentComponentName: 'DmpListingComponent',
|
|
|
|
// label: this.language.instant('NAV-BAR.MY-DMPS'),
|
|
|
|
// url: 'plans',
|
2019-08-01 09:54:40 +02:00
|
|
|
// notFoundResolver: [await this.grantService.getSingle(this.dmp.grant.id).map(x => ({ label: x.label, url: '/grants/edit/' + x.id }) as BreadcrumbItem).toPromise()]
|
2019-06-21 15:55:38 +02:00
|
|
|
// }]
|
|
|
|
// );
|
|
|
|
this.associatedUsers = data.associatedUsers;
|
2019-06-11 10:25:32 +02:00
|
|
|
// }
|
2020-04-01 17:16:06 +02:00
|
|
|
// if (!lockStatus) {
|
|
|
|
// this.lock = new LockModel(data.id, this.getUserFromDMP());
|
2020-02-11 17:27:54 +01:00
|
|
|
|
2020-04-01 17:16:06 +02:00
|
|
|
// this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => {
|
|
|
|
// this.lock.id = Guid.parse(result);
|
|
|
|
// interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock());
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// })
|
2020-09-24 19:28:03 +02:00
|
|
|
this.formGroup.valueChanges.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
2020-08-31 18:08:32 +02:00
|
|
|
});
|
2020-09-24 19:28:03 +02:00
|
|
|
});
|
2020-09-30 13:39:38 +02:00
|
|
|
} else {
|
2020-08-06 12:20:28 +02:00
|
|
|
this.dmp = new DmpEditorModel();
|
|
|
|
this.dmp.grant = new GrantTabModel();
|
|
|
|
this.dmp.project = new ProjectFormModel();
|
|
|
|
this.dmp.funder = new FunderFormModel();
|
|
|
|
this.dmp.extraProperties = new ExtraPropertiesFormModel();
|
|
|
|
this.dmp.extraProperties.visible = false;
|
|
|
|
this.dmp.extraProperties.contact = this.authService.current().id;
|
|
|
|
this.formGroup = this.dmp.buildForm();
|
2020-08-04 13:35:02 +02:00
|
|
|
|
2020-07-20 17:24:29 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2020-07-29 17:04:19 +02:00
|
|
|
this.maxStep = this.formGroup.get('datasets') ? this.maxStep + this.formGroup.get('datasets').value.length - 1 : this.maxStep;
|
2020-07-20 17:24:29 +02:00
|
|
|
|
2019-01-24 11:46:29 +01:00
|
|
|
this.registerFormEventsForNewItem();
|
2019-06-07 13:03:10 +02:00
|
|
|
if (this.isAuthenticated) {
|
2019-06-26 17:34:43 +02:00
|
|
|
this.language.get('NAV-BAR.MY-DMPS').pipe(takeUntil(this._destroyed)).subscribe(x => {
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-06-26 17:34:43 +02:00
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: x,
|
|
|
|
url: '/plans'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: "CREATE NEW DMP",
|
|
|
|
url: "/plans/new"
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
})
|
2019-06-07 13:03:10 +02:00
|
|
|
}
|
2020-09-24 19:28:03 +02:00
|
|
|
this.formGroup.valueChanges.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
2018-11-27 18:33:17 +01:00
|
|
|
}
|
|
|
|
});
|
2019-01-24 11:46:29 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
this.route
|
|
|
|
.queryParams
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
2018-10-05 17:00:54 +02:00
|
|
|
.subscribe(params => {
|
|
|
|
this.createNewVersion = params['clone'];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-20 17:24:29 +02:00
|
|
|
copyFormControl(control: AbstractControl) {
|
|
|
|
if (control instanceof FormControl) {
|
|
|
|
return new FormControl(control.value);
|
|
|
|
} else if (control instanceof FormGroup) {
|
|
|
|
const copy = new FormGroup({});
|
|
|
|
Object.keys(control.getRawValue()).forEach(key => {
|
|
|
|
copy.addControl(key, this.copyFormControl(control.controls[key]));
|
|
|
|
});
|
|
|
|
return copy;
|
|
|
|
} else if (control instanceof FormArray) {
|
|
|
|
const copy = new FormArray([]);
|
|
|
|
control.controls.forEach(control => {
|
|
|
|
copy.push(this.copyFormControl(control));
|
|
|
|
})
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 16:46:53 +02:00
|
|
|
public formChanged() {
|
2020-08-31 01:43:11 +02:00
|
|
|
if (!this.isDiscarded) {
|
|
|
|
this.hasChanges = true;
|
|
|
|
}
|
2020-07-17 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
2019-04-26 16:05:15 +02:00
|
|
|
isAuthenticated() {
|
|
|
|
return this.authService.current() != null;
|
|
|
|
}
|
2019-02-13 14:44:08 +01:00
|
|
|
|
2019-12-19 14:48:24 +01:00
|
|
|
setIsUserOwner() {
|
|
|
|
if (this.dmp) {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
this.isUserOwner = principal.id === this.dmp.users.find(x => x.role === Role.Owner).id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 09:19:48 +01:00
|
|
|
getUserFromDMP(): any {
|
|
|
|
if (this.dmp) {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
return this.dmp.users.find(x => x.id === principal.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 14:44:08 +01:00
|
|
|
registerFormEventsForNewItem() {
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-01-24 11:46:29 +01:00
|
|
|
{
|
|
|
|
parentComponentName: 'DmpListingComponent',
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.language.instant('NAV-BAR.MY-DMPS'),
|
2019-02-13 14:44:08 +01:00
|
|
|
url: 'plans',
|
2019-01-24 11:46:29 +01:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-02-14 13:14:44 +01:00
|
|
|
dmpProfileSearch(query: string) {
|
2019-02-13 14:44:08 +01:00
|
|
|
let fields: Array<string> = new Array();
|
|
|
|
var request = new DataTableRequest<DmpProfileCriteria>(0, 10, { fields: fields });
|
|
|
|
request.criteria = new DmpProfileCriteria();
|
2019-09-23 10:17:03 +02:00
|
|
|
return this.dmpProfileService.getPaged(request).pipe(map(x => x.data));
|
2019-02-13 14:44:08 +01:00
|
|
|
}
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
// searchGrant(query: string) {
|
|
|
|
// const grantRequestItem: RequestItem<GrantCriteria> = new RequestItem();
|
|
|
|
// grantRequestItem.criteria = new GrantCriteria();
|
|
|
|
// grantRequestItem.criteria.like = query;
|
|
|
|
// return this.grantService.getWithExternal(grantRequestItem);
|
2019-05-28 09:49:09 +02:00
|
|
|
// }
|
2018-10-05 17:00:54 +02:00
|
|
|
|
2020-09-17 17:48:13 +02:00
|
|
|
formSubmit(addNew?: boolean, showAddDatasetDialog?: boolean): void {
|
2019-12-11 15:51:03 +01:00
|
|
|
this.formService.touchAllFormFields(this.formGroup);
|
2020-09-24 19:28:03 +02:00
|
|
|
// if (this.isNewDataset) {
|
|
|
|
// if (!this.isDatasetFormValid) {
|
|
|
|
// this.showValidationErrorsDialog();
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// this.onDatasetSubmit();
|
|
|
|
// }
|
|
|
|
// else {
|
2020-10-05 10:34:08 +02:00
|
|
|
// console.log("update ", this.formGroup);
|
2020-10-02 09:15:02 +02:00
|
|
|
if (!this.isFormValid()) {
|
|
|
|
this.showValidationErrorsDialog();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.onSubmit(addNew, showAddDatasetDialog);
|
2020-09-24 19:28:03 +02:00
|
|
|
// }
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public isFormValid() {
|
2019-12-11 15:51:03 +01:00
|
|
|
return this.formGroup.valid;
|
|
|
|
// return this.formGroup.get('label').valid && this.formGroup.get('profiles').valid &&
|
|
|
|
// (this.formGroup.get('funder').get('label').valid || this.formGroup.get('funder').get('existFunder').valid) &&
|
|
|
|
// (this.formGroup.get('grant').get('label').valid || this.formGroup.get('grant').get('existGrant').valid);
|
|
|
|
}
|
|
|
|
|
2020-08-25 17:34:28 +02:00
|
|
|
public isDatasetFormValid() {
|
|
|
|
return this.formGroup.get('datasets')['controls'][0].valid;
|
|
|
|
}
|
|
|
|
|
2019-12-11 15:51:03 +01:00
|
|
|
private showValidationErrorsDialog(projectOnly?: boolean) {
|
|
|
|
const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, {
|
|
|
|
disableClose: true,
|
2020-09-25 13:03:04 +02:00
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
2019-12-11 15:51:03 +01:00
|
|
|
data: {
|
|
|
|
formGroup: this.formGroup,
|
|
|
|
projectOnly: projectOnly
|
|
|
|
},
|
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2020-09-17 17:48:13 +02:00
|
|
|
onSubmit(addNew?: boolean, showAddDatasetDialog?: boolean): void {
|
|
|
|
this.dmpService.createDmp(this.formGroup.getRawValue())
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-08-20 17:32:42 +02:00
|
|
|
complete => {
|
2020-10-06 10:21:15 +02:00
|
|
|
this.formGroup.get('id').setValue(complete.id);
|
|
|
|
this.formGroup.get('modified').setValue(complete.modified);
|
2019-08-20 17:32:42 +02:00
|
|
|
if (showAddDatasetDialog) {
|
|
|
|
this.addDatasetOpenDialog(complete);
|
|
|
|
}
|
2020-09-17 17:48:13 +02:00
|
|
|
if (addNew) {
|
|
|
|
this.onCallbackSuccessAddNew(complete);
|
|
|
|
}
|
|
|
|
else { this.onCallbackSuccess(complete) }
|
2019-08-20 17:32:42 +02:00
|
|
|
},
|
2019-08-22 16:53:25 +02:00
|
|
|
error => {
|
|
|
|
this.formGroup.get('status').setValue(DmpStatus.Draft);
|
|
|
|
this.onCallbackError(error);
|
|
|
|
}
|
2020-09-17 17:48:13 +02:00
|
|
|
);
|
|
|
|
// this.dmpService.createDmpWithDatasets(this.formGroup.getRawValue())
|
2020-07-29 17:04:19 +02:00
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(
|
|
|
|
// complete => {
|
|
|
|
// if (showAddDatasetDialog) {
|
|
|
|
// this.addDatasetOpenDialog(complete);
|
|
|
|
// }
|
2020-09-17 17:48:13 +02:00
|
|
|
// else if (this.step < this.stepsBeforeDatasets) { this.onCallbackSuccess(complete) }
|
|
|
|
// else { this.onCallbackSuccess(complete, this.datasetId) }
|
2020-07-29 17:04:19 +02:00
|
|
|
// },
|
|
|
|
// error => {
|
|
|
|
// this.formGroup.get('status').setValue(DmpStatus.Draft);
|
|
|
|
// this.onCallbackError(error);
|
|
|
|
// }
|
2020-09-17 17:48:13 +02:00
|
|
|
// )
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 17:34:28 +02:00
|
|
|
onDatasetSubmit(): void {
|
|
|
|
this.datasetWizardService.createDataset(this.formGroup.get('datasets')['controls'][0].getRawValue())
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
data => {
|
|
|
|
this.onCallbackSuccess(this.formGroup.get('datasets')['controls'][0].get('id').value);
|
|
|
|
},
|
|
|
|
error => this.onCallbackError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-02 09:15:02 +02:00
|
|
|
onCallbackSuccess(dmp?: DmpModel, datasetId?: string): 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);
|
2020-10-05 10:34:08 +02:00
|
|
|
// console.log(dmp)
|
|
|
|
// if (dmp) {
|
|
|
|
// let dmpEditorModel: DmpEditorModel;
|
|
|
|
// dmpEditorModel = new DmpEditorModel();
|
|
|
|
// dmpEditorModel.grant = new GrantTabModel();
|
|
|
|
// dmpEditorModel.project = new ProjectFormModel();
|
|
|
|
// dmpEditorModel.funder = new FunderFormModel();
|
|
|
|
// dmpEditorModel.extraProperties = new ExtraPropertiesFormModel();
|
|
|
|
// dmpEditorModel.fromModel(dmp);
|
|
|
|
// this.formGroup = dmpEditorModel.buildForm();
|
|
|
|
// } else {
|
|
|
|
// this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans']); });
|
|
|
|
// }
|
2020-10-02 09:15:02 +02:00
|
|
|
if (dmp.id != null) {
|
|
|
|
datasetId ? this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans', 'edit', dmp.id], { queryParams: { dataset: datasetId } }); }) : this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans', 'edit', dmp.id]); })
|
2020-08-04 13:35:02 +02:00
|
|
|
} else {
|
|
|
|
this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans']); });
|
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(error: any) {
|
2020-02-24 10:38:26 +01:00
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message, SnackBarNotificationLevel.Error);
|
2018-10-05 17:00:54 +02:00
|
|
|
this.setErrorModel(error.error);
|
|
|
|
//this.validateAllFormFields(this.formGroup);
|
|
|
|
}
|
|
|
|
|
2020-10-02 09:15:02 +02:00
|
|
|
onCallbackSuccessAddNew(dmp?: DmpModel) {
|
2020-09-17 17:48:13 +02:00
|
|
|
// this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
2020-10-06 10:21:15 +02:00
|
|
|
// this.router.navigate(['/datasets', 'new', dmp.id]);
|
|
|
|
this.editDataset(dmp.id, true);
|
2020-09-17 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
public setErrorModel(validationErrorModel: ValidationErrorModel) {
|
|
|
|
Object.keys(validationErrorModel).forEach(item => {
|
|
|
|
(<any>this.dmp.validationErrorModel)[item] = (<any>validationErrorModel)[item];
|
2018-10-05 17:00:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-21 15:42:28 +02:00
|
|
|
public cancel(id: String): void {
|
2019-06-21 15:55:38 +02:00
|
|
|
if (id != null) {
|
2020-02-11 17:27:54 +01:00
|
|
|
this.lockService.unlockTarget(this.dmp.id).pipe(takeUntil(this._destroyed)).subscribe(
|
|
|
|
complete => {
|
|
|
|
this.router.navigate(['/plans/overview/' + id]);
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.formGroup.get('status').setValue(DmpStatus.Draft);
|
|
|
|
this.onCallbackError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
2019-06-21 15:55:38 +02:00
|
|
|
} else {
|
|
|
|
this.router.navigate(['/plans']);
|
|
|
|
}
|
2019-05-30 16:40:32 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
public invite(): void {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/invite/' + this.dmp.id]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:30:23 +01:00
|
|
|
public delete(): void {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '300px',
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-01-24 16:30:23 +01:00
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
2019-06-14 10:21:24 +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'),
|
|
|
|
isDeleteConfirmation: true
|
2019-01-24 16:30:23 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this.dmpService.delete(this.dmp.id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-08-20 17:32:42 +02:00
|
|
|
complete => { this.onCallbackSuccess() },
|
|
|
|
error => this.onDeleteCallbackError(error)
|
2019-01-24 16:30:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
2019-02-15 15:19:07 +01:00
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
displayWith(item: any) {
|
|
|
|
if (!item) { return null; }
|
|
|
|
return item['label'];
|
|
|
|
}
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
redirectToGrant() {
|
|
|
|
this.router.navigate(['grants/edit/' + this.dmp.grant.id]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
redirectToDatasets() {
|
2019-04-22 11:35:50 +02:00
|
|
|
this.router.navigate(['datasets'], { queryParams: { dmpId: this.dmp.id } });
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
newVersion(id: String, label: String) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans/new_version/' + id, { dmpLabel: label }]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 11:52:35 +02:00
|
|
|
// OLD CLONE VERSION
|
|
|
|
// clone(id: String) {
|
|
|
|
// this.router.navigate(['/plans/clone/' + id]);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// NEW CLONE VERSION
|
|
|
|
// clone(dmp: DmpListingModel) {
|
|
|
|
// this.openCloneDialog();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// openCloneDialog() {
|
|
|
|
// const dialogRef = this.dialog.open(CloneDialogComponent, {
|
|
|
|
// maxWidth: '700px',
|
2020-09-03 17:49:45 +02:00
|
|
|
// maxHeight: '80vh',
|
2020-09-03 11:52:35 +02:00
|
|
|
// data: {
|
|
|
|
// formGroup: this.formGroup,
|
|
|
|
// datasets: this.formGroup.get('datasets').value,
|
|
|
|
// confirmButton: this.language.instant('DMP-EDITOR.CLONE-DIALOG.CLONE'),
|
|
|
|
// cancelButton: this.language.instant('DMP-EDITOR.CLONE-DIALOG.CANCEL'),
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
// if (result) {
|
|
|
|
// this.dmpService.clone(this.formGroup.getRawValue(), this.formGroup.get('id').value)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(
|
|
|
|
// complete => this.onCloneCallbackSuccess(complete),
|
|
|
|
// error => this.onCloneCallbackError(error)
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
2018-10-11 13:22:03 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
viewVersions(rowId: String, rowLabel: String) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-10-09 10:28:44 +02:00
|
|
|
|
|
|
|
downloadXml(id: string) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmpService.downloadXML(id)
|
2018-11-27 18:33:17 +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);
|
|
|
|
});
|
2018-10-09 10:28:44 +02:00
|
|
|
}
|
|
|
|
|
2018-10-19 09:35:35 +02:00
|
|
|
downloadDocx(id: string) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmpService.downloadDocx(id)
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
2019-02-06 11:46:14 +01:00
|
|
|
const blob = new Blob([response.body], { type: 'application/msword' });
|
2018-11-27 18:33:17 +01:00
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
2018-10-19 09:35:35 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 09:48:56 +02:00
|
|
|
downloadPDF(id: string) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmpService.downloadPDF(id)
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
2019-02-06 11:46:14 +01:00
|
|
|
const blob = new Blob([response.body], { type: 'application/pdf' });
|
2018-11-27 18:33:17 +01:00
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
2018-10-22 09:48:56 +02:00
|
|
|
}
|
|
|
|
|
2019-06-04 16:04:04 +02:00
|
|
|
downloadJson(id: string) {
|
|
|
|
this.dmpService.downloadJson(id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/json' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
FileSaver.saveAs(blob, filename);
|
2020-10-09 12:04:38 +02:00
|
|
|
}, async error => {
|
|
|
|
this.onExportCallbackError(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async onExportCallbackError(error: any) {
|
|
|
|
const errorJsonText = await error.error.text();
|
|
|
|
const errorObj = JSON.parse(errorJsonText);
|
|
|
|
this.uiNotificationService.snackBarNotification(errorObj.message, SnackBarNotificationLevel.Error);
|
2019-06-04 16:04:04 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 10:28:44 +02: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;
|
|
|
|
}
|
2018-10-11 13:22:03 +02:00
|
|
|
|
|
|
|
public enableForm() {
|
2019-01-18 18:03:45 +01:00
|
|
|
if (this.formGroup.get('status').value !== DmpStatus.Finalized) {
|
2018-10-12 10:22:23 +02:00
|
|
|
this.editMode = true;
|
|
|
|
this.formGroup.enable();
|
|
|
|
}
|
2019-02-14 13:14:44 +01:00
|
|
|
//else {
|
|
|
|
// this.dmpService.unlock(this.formGroup.get('id').value)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(x => {
|
|
|
|
// this.editMode = true;
|
|
|
|
// this.formGroup.get('status').patchValue(DmpStatus.Draft);
|
|
|
|
// this.formGroup.enable();
|
|
|
|
// });
|
|
|
|
// }
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public disableForm() {
|
|
|
|
this.editMode = false;
|
|
|
|
this.formGroup.disable();
|
|
|
|
}
|
|
|
|
|
2020-09-04 18:27:41 +02:00
|
|
|
save() {
|
2019-07-02 12:19:15 +02:00
|
|
|
this.formSubmit(true);
|
|
|
|
}
|
|
|
|
|
2020-09-04 18:27:41 +02:00
|
|
|
addDataset() {
|
2020-09-17 17:48:13 +02:00
|
|
|
this.formSubmit(true, false);
|
|
|
|
// Add dataset to list
|
|
|
|
// if (!this.formGroup.get('datasets')) {
|
|
|
|
// this.formGroup.addControl('datasets', new FormBuilder().array(new Array<FormControl>()));
|
|
|
|
// }
|
|
|
|
// this.formGroup.get('datasets')['controls'].push(new DatasetWizardEditorModel().buildForm());
|
|
|
|
// this.datasets = this.formGroup.get('datasets') as FormArray;
|
|
|
|
// this.step = this.stepsBeforeDatasets + this.formGroup.get('datasets')['controls'].length - 1;
|
|
|
|
// this.maxStep = this.maxStep + this.formGroup.get('datasets')['controls'].length - 1;
|
2020-09-04 18:27:41 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 09:36:18 +02:00
|
|
|
hasProfile(): boolean {
|
|
|
|
return this.formGroup.get('profiles') && this.formGroup.get('profiles').value && this.formGroup.get('profiles').value.length > 0;
|
|
|
|
}
|
|
|
|
|
2020-10-02 09:15:02 +02:00
|
|
|
addDatasetOpenDialog(dmp: DmpModel) {
|
2019-07-02 12:19:15 +02:00
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '500px',
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-07-02 12:19:15 +02:00
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ADD-DATASET'),
|
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
2019-07-18 10:50:19 +02:00
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.NO'),
|
2019-07-02 12:19:15 +02:00
|
|
|
isDeleteConfirmation: false
|
|
|
|
}
|
|
|
|
});
|
2019-07-01 11:35:09 +02:00
|
|
|
|
2019-07-02 12:19:15 +02:00
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
2020-09-08 09:36:18 +02:00
|
|
|
// this.router.navigate(['datasets/new/' + id]);
|
|
|
|
this.addDataset();
|
2019-07-02 12:19:15 +02:00
|
|
|
} else {
|
2020-10-02 09:15:02 +02:00
|
|
|
dmp.id != null ? this.router.navigate(['/plans', 'edit', dmp.id]) : this.router.navigate(['/plans']);
|
2019-07-02 12:19:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-05 10:34:08 +02:00
|
|
|
editDataset(id: string, isNew: boolean) {
|
|
|
|
const dialogRef = this.dialog.open(DmpToDatasetDialogComponent, {
|
|
|
|
width: '500px',
|
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
if (isNew) {
|
|
|
|
this.router.navigate(['/datasets', 'new', id]);
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['/datasets', 'edit', id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-09-16 17:19:29 +02:00
|
|
|
}
|
|
|
|
|
2019-07-02 12:19:15 +02:00
|
|
|
saveAndFinalize() {
|
2019-07-01 11:35:09 +02:00
|
|
|
const dialogInputModel: DmpFinalizeDialogInput = {
|
|
|
|
dmpLabel: this.formGroup.get('label').value,
|
|
|
|
dmpDescription: this.formGroup.get('description').value,
|
|
|
|
datasets: this.formGroup.get('datasets').value.map(x => {
|
|
|
|
return { label: x.label, id: x.id, status: x.status };
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
const dialogRef = this.dialog.open(DmpFinalizeDialogComponent, {
|
2019-06-21 15:55:38 +02:00
|
|
|
maxWidth: '500px',
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2018-10-11 13:22:03 +02:00
|
|
|
data: {
|
2019-07-01 11:35:09 +02:00
|
|
|
dialogInputModel: dialogInputModel,
|
2019-06-21 15:55:38 +02:00
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.FINALIZE-ITEM'),
|
|
|
|
confirmButton: this.language.instant('DMP-FINALISE-DIALOG.SUBMIT'),
|
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
|
|
|
});
|
2020-01-10 11:44:00 +01:00
|
|
|
dialogRef.afterClosed()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
if (result && !result.cancelled) {
|
|
|
|
this.formGroup.get('status').setValue(DmpStatus.Finalized);
|
|
|
|
this.formGroup.get('datasetsToBeFinalized').setValue(result.datasetsToBeFinalized);
|
|
|
|
this.formSubmit(false);
|
|
|
|
//this.router.navigate(['/plans/overview/' + this.formGroup.get('id').value]);
|
|
|
|
dialogRef.close();
|
|
|
|
}
|
|
|
|
});
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
2019-09-25 11:44:22 +02:00
|
|
|
|
2020-02-11 17:27:54 +01:00
|
|
|
private pumpLock() {
|
|
|
|
this.lock.touchedAt = new Date();
|
2020-04-27 15:21:03 +02:00
|
|
|
this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => this.lock.id = Guid.parse(result));
|
2020-02-11 17:27:54 +01:00
|
|
|
}
|
|
|
|
|
2020-08-04 13:35:02 +02:00
|
|
|
public changeStep(index: number, dataset?: FormControl) {
|
2020-07-17 16:46:53 +02:00
|
|
|
this.step = index;
|
2020-08-04 13:35:02 +02:00
|
|
|
if (dataset) { this.datasetId = dataset.get('id').value };
|
2020-07-17 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public nextStep() {
|
|
|
|
this.step = this.step < this.maxStep ? this.step + 1 : this.step;
|
2020-08-04 13:35:02 +02:00
|
|
|
if (this.step >= this.stepsBeforeDatasets) {
|
|
|
|
this.datasetId = this.datasets.at(this.step - this.stepsBeforeDatasets).get('id').value;
|
|
|
|
}
|
2020-07-17 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public previousStep() {
|
|
|
|
this.step = this.step !== 0 ? this.step - 1 : this.step;
|
2020-08-04 13:35:02 +02:00
|
|
|
if (this.step >= this.stepsBeforeDatasets) {
|
|
|
|
this.datasetId = this.datasets.at(this.step - this.stepsBeforeDatasets).get('id').value;
|
|
|
|
}
|
2020-07-17 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public isDirty(): boolean {
|
2020-08-31 01:43:11 +02:00
|
|
|
return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty
|
2020-07-17 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public discardChanges() {
|
2020-08-31 01:43:11 +02:00
|
|
|
this.isDiscarded = true;
|
2020-07-17 16:46:53 +02:00
|
|
|
this.hasChanges = false;
|
2020-09-24 19:28:03 +02:00
|
|
|
if (!this.isNew) {
|
2020-10-07 11:42:10 +02:00
|
|
|
let grantControl;
|
|
|
|
if(this.formGroup.get('grant').get('existGrant')) {
|
|
|
|
grantControl = new GrantTabModel();
|
|
|
|
grantControl.fromModel(this.formGroup.get('grant').get('existGrant').value);
|
|
|
|
} else {
|
|
|
|
grantControl = new GrantEditorModel();
|
|
|
|
grantControl.fromModel(this.formGroup.get('grant').value);
|
|
|
|
}
|
|
|
|
grantControl.buildForm()
|
|
|
|
|
2020-08-31 01:43:11 +02:00
|
|
|
this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue)));
|
2020-10-07 11:42:10 +02:00
|
|
|
|
2020-10-07 12:14:19 +02:00
|
|
|
if(this.formGroup.get('grant').get('existGrant')) {
|
|
|
|
this.formGroup.get('grant').get('existGrant').setValue(grantControl.existGrant);
|
|
|
|
} else {
|
|
|
|
this.formGroup.get('grant').setValue(grantControl);
|
|
|
|
}
|
2020-09-24 19:28:03 +02:00
|
|
|
} else {
|
|
|
|
this.formGroup.reset();
|
|
|
|
this.formGroup.get('extraProperties').get('visible').setValue(false);
|
|
|
|
this.formGroup.get('extraProperties').get('contact').setValue(this.authService.current().id);
|
|
|
|
this.formGroup.get('associatedUsers').setValue([]);
|
2020-08-31 01:43:11 +02:00
|
|
|
}
|
|
|
|
this.isDiscarded = false;
|
2020-07-17 16:46:53 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 15:54:01 +02:00
|
|
|
public removeDataset(datasetId: string, index: number) {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '300px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'),
|
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
if (datasetId) {
|
|
|
|
this.datasetService.delete(datasetId)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => {
|
|
|
|
this.onDeleteCallbackSuccess();
|
|
|
|
},
|
|
|
|
error => this.onDeleteCallbackError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
this.formGroup.get('datasets')['controls'].splice(index, 1);
|
|
|
|
this.step = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.dmp.id != null ? this.router.navigate(['/plans', 'edit', this.dmp.id]) : this.router.navigate(['/plans']);
|
|
|
|
}
|
|
|
|
|
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",
|
|
|
|
// jsonButton: "JSON"
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
// if (result == "pdf") {
|
|
|
|
// this.downloadPDF(this.dmp.id);
|
|
|
|
// } else if (result == "xml") {
|
|
|
|
// this.downloadXml(this.dmp.id);
|
|
|
|
// } else if (result == "doc") {
|
|
|
|
// this.downloadDocx(this.dmp.id);
|
|
|
|
// } else if (result == "json") {
|
|
|
|
// this.downloadJson(this.dmp.id)
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|