2021-03-19 13:32:17 +01:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2021-03-18 17:02:09 +01:00
|
|
|
import { AbstractControl, FormArray, 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';
|
2019-06-03 11:01:42 +02:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DatasetStatus } from '@app/core/common/enum/dataset-status';
|
|
|
|
import { DmpStatus } from '@app/core/common/enum/dmp-status';
|
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
|
|
|
|
import { DmpModel } from '@app/core/model/dmp/dmp';
|
|
|
|
import { DmpListingModel } from '@app/core/model/dmp/dmp-listing';
|
|
|
|
import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria';
|
|
|
|
import { DmpCriteria } from '@app/core/query/dmp/dmp-criteria';
|
|
|
|
import { RequestItem } from '@app/core/query/request-item';
|
|
|
|
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { ExternalSourcesConfigurationService } from '@app/core/services/external-sources/external-sources-configuration.service';
|
|
|
|
import { ExternalSourcesService } from '@app/core/services/external-sources/external-sources.service';
|
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration';
|
|
|
|
import { DatasetCopyDialogueComponent } from '@app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component';
|
|
|
|
import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
|
|
|
|
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { DatasetDescriptionFormEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
|
2021-03-19 13:32:17 +01:00
|
|
|
import { Link, LinkToScroll, TableOfContents } from '@app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2019-12-13 12:15:12 +01:00
|
|
|
import { FormService } from '@common/forms/form-service';
|
|
|
|
import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
2019-12-13 12:15:12 +01:00
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import * as FileSaver from 'file-saver';
|
2021-06-22 13:12:58 +02:00
|
|
|
import { Observable, of as observableOf, interval} from 'rxjs';
|
2021-04-07 11:58:45 +02:00
|
|
|
import { catchError, debounceTime, map, takeUntil } from 'rxjs/operators';
|
2020-02-11 17:27:54 +01:00
|
|
|
import { LockService } from '@app/core/services/lock/lock.service';
|
|
|
|
import { Location } from '@angular/common';
|
|
|
|
import { LockModel } from '@app/core/model/lock/lock.model';
|
|
|
|
import { Guid } from '@common/types/guid';
|
|
|
|
import { isNullOrUndefined } from 'util';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
2020-03-26 17:44:12 +01:00
|
|
|
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
2020-09-18 17:51:42 +02:00
|
|
|
import { SaveType } from '@app/core/common/enum/save-type';
|
2020-11-02 17:08:25 +01:00
|
|
|
import { DatasetWizardModel } from '@app/core/model/dataset/dataset-wizard';
|
2020-12-14 18:28:13 +01:00
|
|
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
2021-04-13 10:19:09 +02:00
|
|
|
import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service';
|
2021-06-22 13:12:58 +02:00
|
|
|
import { PopupNotificationDialogComponent } from '@app/library/notification/popup/popup-notification.component';
|
2021-06-23 09:54:05 +02:00
|
|
|
import { CheckDeactivateBaseComponent } from '@app/library/deactivate/deactivate.component';
|
2020-09-17 17:48:13 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-dataset-wizard-component',
|
|
|
|
templateUrl: 'dataset-wizard.component.html',
|
|
|
|
styleUrls: ['./dataset-wizard.component.scss']
|
|
|
|
})
|
2021-06-23 09:54:05 +02:00
|
|
|
export class DatasetWizardComponent extends CheckDeactivateBaseComponent implements OnInit, IBreadCrumbComponent {
|
|
|
|
canDeactivate(): boolean {
|
|
|
|
return !this.isDirty();
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
|
|
|
viewOnly = false;
|
|
|
|
editMode = false;
|
2019-04-01 12:42:46 +02:00
|
|
|
publicMode = false;
|
2020-09-18 17:51:42 +02:00
|
|
|
hasChanges = false;
|
|
|
|
isDiscarded = false;
|
|
|
|
formGroupRawValue: any;
|
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;
|
2020-02-11 17:27:54 +01:00
|
|
|
lock: LockModel;
|
|
|
|
lockStatus: Boolean;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2020-09-16 17:19:29 +02:00
|
|
|
step: number = 0;
|
|
|
|
stepOffset: number = 1;
|
2020-09-17 17:48:13 +02:00
|
|
|
maxStep: number;
|
|
|
|
|
|
|
|
saveAnd = SaveType;
|
2020-11-02 17:08:25 +01:00
|
|
|
datasetSavedLinks: any = null;
|
|
|
|
|
|
|
|
scrollTop: number;
|
2020-11-06 11:42:31 +01:00
|
|
|
tocScrollTop: number;
|
|
|
|
links: Link[] = [];
|
2021-03-17 16:49:42 +01:00
|
|
|
//the table seraches for elements to scroll on page with id (TOCENTRY_ID_PREFIX+fieldsetId<Tocentry>)
|
|
|
|
TOCENTRY_ID_PREFIX="TocEntRy";
|
2021-03-19 11:04:01 +01:00
|
|
|
showtocentriesErrors = false;
|
2021-03-19 13:32:17 +01:00
|
|
|
@ViewChild('table0fContents', {static: false}) table0fContents: TableOfContents;
|
|
|
|
hintErrors: boolean = false;
|
2021-04-07 11:58:45 +02:00
|
|
|
datasetIsOnceSaved = false;
|
2020-09-16 17:19:29 +02:00
|
|
|
|
2021-04-06 08:57:17 +02:00
|
|
|
fieldsetIdWithFocus:string;
|
2021-04-13 10:19:09 +02:00
|
|
|
visRulesService:VisibilityRulesService;
|
2021-04-06 08:57:17 +02:00
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
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-12-13 12:15:12 +01:00
|
|
|
private uiNotificationService: UiNotificationService,
|
2020-02-11 17:27:54 +01:00
|
|
|
private formService: FormService,
|
|
|
|
private lockService: LockService,
|
|
|
|
private location: Location,
|
2020-03-26 17:44:12 +01:00
|
|
|
private authService: AuthService,
|
2020-12-14 18:28:13 +01:00
|
|
|
private configurationService: ConfigurationService,
|
|
|
|
private httpClient: HttpClient,
|
|
|
|
private matomoService: MatomoService
|
2019-01-18 18:03:45 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-14 18:28:13 +01:00
|
|
|
this.matomoService.trackPageView('Dataset Editor');
|
2019-01-18 18:03:45 +01:00
|
|
|
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-10-17 09:43:28 +02:00
|
|
|
displayFn: (item) => this.getDatasetDisplay(item),
|
2019-09-23 13:06:58 +02:00
|
|
|
titleFn: (item) => item['label'],
|
2020-01-16 15:00:58 +01:00
|
|
|
subtitleFn: (item) => this.language.instant('DATASET-WIZARD.FIRST-STEP.SUB-TITLE') + new Date(item['creationTime']).toISOString()
|
2019-12-13 12:15:12 +01:00
|
|
|
// iconFn: (item) => this.publicMode ? '' : (item['status'] ? 'lock' : 'lock_open'),
|
|
|
|
// linkFn: (item) => this.publicMode ? '/explore-plans/overview/' + item['id'] : '/plans/overview/' + item['id']
|
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 => {
|
2020-02-11 17:27:54 +01:00
|
|
|
this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => {
|
|
|
|
this.lockStatus = lockStatus;
|
2020-09-16 17:19:29 +02:00
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
|
|
|
this.needsUpdate();
|
|
|
|
this.breadCrumbs = observableOf([
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.datasetWizardModel.label,
|
|
|
|
url: '/datasets/edit/' + this.datasetWizardModel.id,
|
|
|
|
notFoundResolver: [
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS').toUpperCase(),
|
|
|
|
url: '/datasets'
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}]);
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
2020-09-18 17:51:42 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2020-09-16 17:19:29 +02:00
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
|
|
|
if (this.datasetWizardModel.status === DatasetStatus.Finalized || lockStatus) {
|
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
|
|
|
if (!lockStatus && !isNullOrUndefined(this.authService.current())) {
|
|
|
|
this.lock = new LockModel(data.id, this.authService.current());
|
2020-02-11 17:27:54 +01:00
|
|
|
|
2020-09-16 17:19:29 +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());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
|
|
|
this.loadDatasetProfiles();
|
|
|
|
this.registerFormListeners();
|
2021-06-22 13:12:58 +02:00
|
|
|
|
|
|
|
if(lockStatus){
|
|
|
|
this.dialog.open(PopupNotificationDialogComponent,{data:{
|
|
|
|
title:this.language.instant('DATASET-WIZARD.LOCKED.TITLE'),
|
|
|
|
message:this.language.instant('DATASET-WIZARD.LOCKED.MESSAGE')
|
|
|
|
}, maxWidth:'30em'});
|
|
|
|
}
|
2020-09-16 17:19:29 +02:00
|
|
|
// this.availableProfiles = this.datasetWizardModel.dmp.profiles;
|
|
|
|
})
|
2019-07-26 10:37:26 +02:00
|
|
|
},
|
2019-10-17 09:43:28 +02:00
|
|
|
error => {
|
2020-02-26 12:36:42 +01:00
|
|
|
switch (error.status) {
|
|
|
|
case 403:
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.DATASET-NOT-ALLOWED'), SnackBarNotificationLevel.Error);
|
|
|
|
break;
|
|
|
|
case 404:
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.MESSAGES.DATASET-NOT-FOUND'), SnackBarNotificationLevel.Error);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.ERRORS.HTTP-REQUEST-ERROR'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
this.router.navigate(['/datasets/']);
|
2019-10-17 09:43:28 +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();
|
2020-09-18 17:51:42 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2019-01-18 18:03:45 +01:00
|
|
|
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 => {
|
2020-02-11 17:27:54 +01:00
|
|
|
this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => {
|
|
|
|
this.lockStatus = lockStatus;
|
2020-09-16 17:19:29 +02:00
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
this.formGroup.get('id').setValue(null);
|
|
|
|
this.dmpService.getSingle(newDmpId).pipe(map(data => data as DmpModel))
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.datasetWizardModel.dmp = data;
|
|
|
|
this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp);
|
2020-09-18 17:51:42 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2020-09-16 17:19:29 +02:00
|
|
|
|
|
|
|
this.loadDatasetProfiles();
|
|
|
|
this.breadCrumbs = observableOf([
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS'),
|
|
|
|
url: '/datasets',
|
|
|
|
notFoundResolver: [
|
|
|
|
// {
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.datasetWizardModel.dmp.grant.label,
|
|
|
|
// url: '/grants/edit/' + this.datasetWizardModel.dmp.grant.id
|
|
|
|
// },
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.datasetWizardModel.dmp.label,
|
|
|
|
url: '/plans/edit/' + this.datasetWizardModel.dmp.id,
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}]);
|
|
|
|
});
|
2019-03-28 15:53:17 +01:00
|
|
|
});
|
2020-09-16 17:19:29 +02:00
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
|
|
|
if (this.datasetWizardModel.status === DatasetStatus.Finalized || lockStatus) {
|
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
|
|
|
}
|
|
|
|
if (!lockStatus && !isNullOrUndefined(this.authService.current())) {
|
|
|
|
this.lock = new LockModel(data.id, this.authService.current());
|
2020-02-11 17:27:54 +01:00
|
|
|
|
2020-09-16 17:19:29 +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());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP.
|
|
|
|
this.loadDatasetProfiles();
|
|
|
|
// 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);
|
2019-10-23 12:03:12 +02:00
|
|
|
this.router.navigate(['/datasets/publicEdit/' + this.publicId]);
|
2019-09-23 11:11:00 +02:00
|
|
|
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();
|
2020-09-18 17:51:42 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2020-03-13 17:37:40 +01:00
|
|
|
this.formGroup.disable();
|
|
|
|
this.viewOnly = true;
|
2019-04-01 12:42:46 +02:00
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
|
|
|
this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp);
|
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);
|
2020-09-18 17:51:42 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
|
|
|
|
2019-04-22 11:11:21 +02:00
|
|
|
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();
|
|
|
|
});
|
2020-02-11 17:27:54 +01:00
|
|
|
|
2019-04-22 11:11:21 +02:00
|
|
|
} else {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel();
|
|
|
|
this.formGroup = this.datasetWizardModel.buildForm();
|
2020-09-18 17:51:42 +02:00
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
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
|
|
|
|
2020-09-17 17:48:13 +02:00
|
|
|
!this.isNew ? this.maxStep = 1 : this.maxStep = 0;
|
2020-09-18 17:51:42 +02: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); }
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
2021-04-07 11:58:45 +02:00
|
|
|
// private _listenersSubscription:Subscription = new Subscription();
|
2019-06-27 17:13:33 +02:00
|
|
|
registerFormListeners() {
|
2021-04-07 11:58:45 +02:00
|
|
|
// const dmpSubscription =
|
2019-06-27 17:13:33 +02:00
|
|
|
this.formGroup.get('dmp').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.dmpValueChanged(x);
|
|
|
|
});
|
2021-04-07 11:58:45 +02:00
|
|
|
// const profileSubscription =
|
2019-06-27 17:13:33 +02:00
|
|
|
this.formGroup.get('profile').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
2020-09-21 17:05:53 +02:00
|
|
|
if (x) {
|
2021-06-11 11:16:50 +02:00
|
|
|
this.showtocentriesErrors = false;
|
2020-09-21 17:05:53 +02:00
|
|
|
this.datasetProfileValueChanged(x.id);
|
|
|
|
this.formChanged();
|
|
|
|
}
|
2019-06-27 17:13:33 +02:00
|
|
|
});
|
2021-04-07 11:58:45 +02:00
|
|
|
// const labelSubscription =
|
2020-09-21 17:05:53 +02:00
|
|
|
this.formGroup.get('label').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
2021-04-07 11:58:45 +02:00
|
|
|
// const descriptionSubscription =
|
2020-09-21 17:05:53 +02:00
|
|
|
this.formGroup.get('description').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
2021-04-07 11:58:45 +02:00
|
|
|
// const uriSubscription =
|
2020-09-21 17:05:53 +02:00
|
|
|
this.formGroup.get('uri').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
2021-04-07 11:58:45 +02:00
|
|
|
// const tagsSubscription =
|
2020-09-21 17:05:53 +02:00
|
|
|
this.formGroup.get('tags').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
|
|
|
if (this.formGroup.get('datasetProfileDefinition')) {
|
2021-04-07 11:58:45 +02:00
|
|
|
// const datasetProfileDefinitionSubscription =
|
2020-09-21 17:05:53 +02:00
|
|
|
this.formGroup.get('datasetProfileDefinition').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
2021-04-07 11:58:45 +02:00
|
|
|
// this._listenersSubscription.add(datasetProfileDefinitionSubscription);
|
2020-09-21 17:05:53 +02:00
|
|
|
}
|
2021-04-07 11:58:45 +02:00
|
|
|
|
|
|
|
// this._listenersSubscription.add(dmpSubscription);
|
|
|
|
// this._listenersSubscription.add(profileSubscription);
|
|
|
|
// this._listenersSubscription.add(labelSubscription);
|
|
|
|
// this._listenersSubscription.add(descriptionSubscription);
|
|
|
|
// this._listenersSubscription.add(uriSubscription);
|
|
|
|
// this._listenersSubscription.add(tagsSubscription);
|
2019-06-27 17:13:33 +02:00
|
|
|
}
|
2021-04-07 11:58:45 +02:00
|
|
|
// private _unregisterFormListeners(){
|
|
|
|
// this._listenersSubscription.unsubscribe();
|
|
|
|
// this._listenersSubscription = new Subscription();
|
|
|
|
// }
|
2019-06-27 17:13:33 +02:00
|
|
|
|
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');
|
2020-09-17 17:48:13 +02:00
|
|
|
this.getDefinition(profiledId);
|
|
|
|
this.maxStep = 1;
|
2019-06-03 11:01:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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>();
|
2020-01-16 15:00:58 +01:00
|
|
|
fields.push('-created');
|
2019-01-29 17:25:40 +01:00
|
|
|
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, null, { fields: fields });
|
|
|
|
dmpDataTableRequest.criteria = new DmpCriteria();
|
|
|
|
dmpDataTableRequest.criteria.like = query;
|
2019-12-13 12:36:25 +01:00
|
|
|
dmpDataTableRequest.criteria.status = DmpStatus.Draft;
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-18 17:51:42 +02:00
|
|
|
public formChanged() {
|
|
|
|
if (!this.isDiscarded) {
|
|
|
|
this.hasChanges = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
public cancel(): void {
|
2020-02-11 17:27:54 +01:00
|
|
|
if (!isNullOrUndefined(this.lock)) {
|
|
|
|
this.lockService.unlockTarget(this.datasetWizardModel.id).pipe(takeUntil(this._destroyed)).subscribe(
|
|
|
|
complete => {
|
2020-03-17 14:57:28 +01:00
|
|
|
this.publicMode ? this.router.navigate(['/explore']) : this.router.navigate(['/datasets']);
|
2020-02-11 17:27:54 +01:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.formGroup.get('status').setValue(DmpStatus.Draft);
|
|
|
|
this.onCallbackError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
} else {
|
2020-03-17 14:57:28 +01:00
|
|
|
this.publicMode ? this.router.navigate(['/explore']) : this.router.navigate(['/datasets']);
|
2020-02-11 17:27:54 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
2019-10-17 09:43:28 +02:00
|
|
|
getDatasetDisplay(item: any): string {
|
|
|
|
if (!this.publicMode) {
|
|
|
|
return (item['status'] ? this.language.instant('TYPES.DATASET-STATUS.FINALISED').toUpperCase() : this.language.instant('TYPES.DATASET-STATUS.DRAFT').toUpperCase()) + ': ' + item['label'];
|
|
|
|
}
|
|
|
|
else { return item['label']; }
|
|
|
|
}
|
|
|
|
|
2020-09-17 17:48:13 +02:00
|
|
|
getDefinition(profileId: string) {
|
2019-06-03 11:01:42 +02:00
|
|
|
// if (this.formGroup.invalid) { setTimeout(() => this.stepper.selectedIndex = 0); return; }
|
2020-09-17 17:48:13 +02:00
|
|
|
this.datasetWizardService.getDefinition(profileId)
|
2019-06-03 11:01:42 +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());
|
2021-04-07 11:58:45 +02:00
|
|
|
|
|
|
|
// const datasetProfileDefinitionForm = this.datasetProfileDefinitionModel.buildForm();
|
|
|
|
|
|
|
|
// let profId = null;
|
|
|
|
// try{
|
|
|
|
// profId = this.formGroup.get('profile').value.id;
|
|
|
|
// }catch{
|
|
|
|
|
|
|
|
// }
|
|
|
|
// if(this.formGroupRawValue && this.formGroupRawValue.datasetProfileDefinition && (this.formGroupRawValue.profile.id === profId)){
|
|
|
|
// // this.formGroup.get('datasetProfileDefinition').patchValue( this.formGroupRawValue.datasetProfileDefinition);
|
|
|
|
// datasetProfileDefinitionForm.patchValue(this.formGroupRawValue.datasetProfileDefinition);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// this.formGroup.addControl('datasetProfileDefinition', datasetProfileDefinitionForm);
|
|
|
|
this.formGroup.get('datasetProfileDefinition').valueChanges
|
|
|
|
.pipe(debounceTime(600))
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => {
|
|
|
|
this.formChanged();
|
|
|
|
});
|
2019-06-03 11:01:42 +02:00
|
|
|
});
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-13 12:15:12 +01:00
|
|
|
// formSubmit(): void {
|
|
|
|
// if (!this.isFormValid()) { return; }
|
|
|
|
// this.onSubmit();
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
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-12-11 15:51:03 +01:00
|
|
|
if (controlName != 'datasetProfileDefinition' && !formGroup.get(controlName).disabled && !(formGroup.get(controlName).valid)) {
|
2019-07-02 17:28:43 +02:00
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return isValid;
|
|
|
|
}
|
|
|
|
|
2019-12-13 12:15:12 +01:00
|
|
|
// onSubmit(): void {
|
|
|
|
// this.datasetWizardService.createDataset(this.formGroup.value)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(
|
|
|
|
// 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
|
|
|
|
2020-09-17 17:48:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
submit(saveType?: SaveType) {
|
2020-11-02 17:08:25 +01:00
|
|
|
this.scrollTop = document.getElementById('dataset-editor-form').scrollTop;
|
2020-11-06 11:42:31 +01:00
|
|
|
this.tocScrollTop = document.getElementById('stepper-options').scrollTop;
|
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))
|
2019-12-13 12:15:12 +01:00
|
|
|
.subscribe(
|
|
|
|
data => {
|
2021-06-23 09:54:05 +02:00
|
|
|
this.hasChanges = false;
|
2021-04-07 11:58:45 +02:00
|
|
|
this.datasetIsOnceSaved = true;
|
2021-06-23 09:54:05 +02:00
|
|
|
this.onCallbackSuccess(data, saveType);
|
2019-12-13 12:15:12 +01:00
|
|
|
},
|
|
|
|
error => this.onCallbackError(error));
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-18 17:02:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private _getErrorMessage(formControl: AbstractControl, name: string): string[] {
|
|
|
|
const errors: string[] = [];
|
|
|
|
Object.keys(formControl.errors).forEach(key => {
|
|
|
|
if (key === 'required') { errors.push(this.language.instant(name + ": " + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.REQUIRED'))); }
|
|
|
|
// if (key === 'required') { errors.push(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.THIS-FIELD') + ' "' + this.getPlaceHolder(formControl) + '" ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-ERROR') + ', ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.REQUIRED')); }
|
|
|
|
else if (key === 'email') { errors.push(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.THIS-FIELD') + ' "' + name + '" ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-ERROR') + ', ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.EMAIL')); }
|
|
|
|
else if (key === 'min') { errors.push(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.THIS-FIELD') + ' "' + name + '" ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-ERROR') + ', ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.MIN-VALUE', { 'min': formControl.getError('min').min })); }
|
|
|
|
else if (key === 'max') { errors.push(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.THIS-FIELD') + ' "' + name + '" ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-ERROR') + ', ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.MAX-VALUE', { 'max': formControl.getError('max').max })); }
|
|
|
|
else { errors.push(this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.THIS-FIELD') + ' "' + name + '" ' + this.language.instant('GENERAL.FORM-VALIDATION-DISPLAY-DIALOG.HAS-ERROR') + ', ' + formControl.errors[key].message); }
|
|
|
|
});
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _getPlaceHolder(formControl: any): string {
|
|
|
|
if (formControl.nativeElement.localName === 'input' || formControl.nativeElement.localName === 'textarea') {
|
|
|
|
return formControl.nativeElement.getAttribute('placeholder');
|
|
|
|
} else if (formControl.nativeElement.localName === 'mat-select') {
|
|
|
|
return formControl.nativeElement.getAttribute('aria-label');
|
|
|
|
} else if (formControl.nativeElement.localName === 'app-single-auto-complete') {
|
|
|
|
return (Array.from(formControl.nativeElement.firstChild.children).filter((x: any) => x.localName === 'input')[0] as any).getAttribute('placeholder');
|
|
|
|
} else if (formControl.nativeElement.localName === 'app-multiple-auto-complete') {
|
|
|
|
return (Array.from(formControl.nativeElement.firstChild.children).filter((x: any) => x.localName === 'input')[0] as any).getAttribute('placeholder');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private _buildSemiFormErrorMessages(): string[]{//not including datasetProfileDefinition
|
|
|
|
const errmess: string[] = [];
|
|
|
|
Object.keys(this.formGroup.controls).forEach(controlName=>{
|
|
|
|
if(controlName != 'datasetProfileDefinition' && this.formGroup.get(controlName).invalid){
|
|
|
|
errmess.push(...this._buildErrorMessagesForAbstractControl(this.formGroup.get(controlName), controlName));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return errmess;
|
|
|
|
}
|
|
|
|
|
|
|
|
// takes as an input an abstract control and gets its error messages[]
|
|
|
|
private _buildErrorMessagesForAbstractControl(aControl: AbstractControl, controlName: string):string[]{
|
|
|
|
const errmess:string[] = [];
|
|
|
|
|
|
|
|
if(aControl.invalid){
|
|
|
|
|
2021-03-19 11:04:01 +01:00
|
|
|
if(aControl.errors){
|
2021-03-18 17:02:09 +01:00
|
|
|
//check if has placeholder
|
|
|
|
if( (<any>aControl).nativeElement !== undefined && (<any>aControl).nativeElement !== null){
|
2021-03-19 12:30:21 +01:00
|
|
|
const placeholder = this._getPlaceHolder(aControl);
|
|
|
|
if(placeholder){
|
|
|
|
controlName = placeholder;
|
|
|
|
}
|
2021-03-18 17:02:09 +01:00
|
|
|
}
|
|
|
|
const errorMessage = this._getErrorMessage(aControl, controlName);
|
|
|
|
|
|
|
|
errmess.push(...errorMessage);
|
|
|
|
}
|
|
|
|
|
2021-03-19 11:04:01 +01:00
|
|
|
/*in case the aControl is FormControl then the it should have provided its error messages above.
|
|
|
|
No need to check case of FormControl below*/
|
|
|
|
|
2021-03-18 17:02:09 +01:00
|
|
|
if(aControl instanceof FormGroup){
|
|
|
|
|
|
|
|
const fg = aControl as FormGroup;
|
|
|
|
//check children
|
|
|
|
Object.keys(fg.controls).forEach(controlName=>{
|
|
|
|
errmess.push(...this._buildErrorMessagesForAbstractControl(fg.get(controlName), controlName));
|
|
|
|
});
|
|
|
|
}else if(aControl instanceof FormArray){
|
|
|
|
|
|
|
|
const fa = aControl as FormArray;
|
|
|
|
|
|
|
|
fa.controls.forEach((control,index)=>{
|
|
|
|
errmess.push(... this._buildErrorMessagesForAbstractControl(control, `${controlName} --> ${index+1}`));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errmess;
|
|
|
|
}
|
|
|
|
|
2020-09-17 17:48:13 +02:00
|
|
|
save(saveType?: SaveType) {
|
2021-03-19 13:32:17 +01:00
|
|
|
|
|
|
|
Object.keys(this.formGroup.controls).forEach(controlName=>{
|
|
|
|
if(controlName == 'datasetProfileDefinition'){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.formService.touchAllFormFields(this.formGroup.get(controlName));
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// this.formService.touchAllFormFields(this.formGroup);
|
2019-12-13 12:15:12 +01:00
|
|
|
if (!this.isSemiFormValid(this.formGroup)) {
|
2021-03-18 17:02:09 +01:00
|
|
|
//build messages
|
|
|
|
const errorMessages = this._buildSemiFormErrorMessages();
|
|
|
|
this.showValidationErrorsDialog(undefined, errorMessages);
|
2021-03-19 13:32:17 +01:00
|
|
|
this.hintErrors = true;
|
2019-12-13 12:15:12 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-09-17 17:48:13 +02:00
|
|
|
this.submit(saveType);
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-18 17:02:09 +01:00
|
|
|
private showValidationErrorsDialog(projectOnly?: boolean, errmess?: string[]) {
|
|
|
|
if(errmess){
|
|
|
|
const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, {
|
|
|
|
disableClose: true,
|
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
errorMessages:errmess,
|
|
|
|
projectOnly: projectOnly
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, {
|
|
|
|
disableClose: true,
|
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
formGroup: this.formGroup,
|
|
|
|
projectOnly: projectOnly
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-13 12:15:12 +01:00
|
|
|
}
|
|
|
|
|
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-10-17 09:43:28 +02:00
|
|
|
if (this.formGroup.get('dmp').value && !this.publicMode) {
|
2019-09-24 17:32:23 +02:00
|
|
|
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-12-13 12:15:12 +01:00
|
|
|
this.formService.touchAllFormFields(this.formGroup);
|
|
|
|
if (!this.isFormValid()) {
|
|
|
|
this.showValidationErrorsDialog();
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-11-02 17:08:25 +01:00
|
|
|
onCallbackSuccess(data?: DatasetWizardModel, saveType?: SaveType): 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-11-02 16:38:19 +01:00
|
|
|
if (data) {
|
2020-09-17 17:48:13 +02:00
|
|
|
if (saveType === this.saveAnd.addNew) {
|
|
|
|
this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'new', this.formGroup.get('dmp').value.id]); })
|
|
|
|
} else if (saveType === this.saveAnd.close) {
|
|
|
|
this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans', 'edit', this.formGroup.get('dmp').value.id]); });
|
|
|
|
} else {
|
2020-11-02 17:08:25 +01:00
|
|
|
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
|
|
|
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
|
|
|
|
2020-11-12 16:57:09 +01:00
|
|
|
// setTimeout(() => { this.formGroup = null; });
|
2020-11-02 17:08:25 +01:00
|
|
|
setTimeout(() => {
|
2020-11-12 16:57:09 +01:00
|
|
|
this.formGroup.get('id').patchValue(data.id);
|
|
|
|
this.formGroup.get('modified').patchValue(data.modified);
|
|
|
|
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
2020-11-12 17:18:09 +01:00
|
|
|
this.hasChanges = false;
|
2020-11-12 16:57:09 +01:00
|
|
|
|
|
|
|
// this.formGroup = this.datasetWizardModel.buildForm();
|
|
|
|
// if (this.formGroup.get('datasetProfileDefinition')) {
|
|
|
|
// this.formGroup.removeControl('datasetProfileDefinition');
|
|
|
|
// this.getDefinition(data.profile.id);
|
|
|
|
// this.maxStep = 1;
|
|
|
|
// } else {
|
|
|
|
// this.getDefinition(data.profile.id);
|
|
|
|
// this.maxStep = 1;
|
|
|
|
// }
|
2020-11-02 17:08:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
document.getElementById('dataset-editor-form').scrollTop = this.scrollTop;
|
2020-11-06 11:42:31 +01:00
|
|
|
document.getElementById('stepper-options').scrollTop = this.tocScrollTop;
|
2020-11-02 17:08:25 +01:00
|
|
|
}, 500);
|
|
|
|
|
|
|
|
// this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', data.id]); });
|
2020-09-17 17:48:13 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['/datasets']);
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(error: any) {
|
2021-07-09 12:03:09 +02:00
|
|
|
const errmes = error && error.message? error.message as string : null;
|
|
|
|
let feedbackMessage = this.language.instant('DATASET-EDITOR.ERRORS.ERROR-OCCURED');
|
|
|
|
if(errmes){
|
|
|
|
feedbackMessage += errmes;
|
|
|
|
}
|
|
|
|
this.uiNotificationService.snackBarNotification(feedbackMessage, SnackBarNotificationLevel.Warning);
|
2019-01-18 18:03:45 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-12-13 12:15:12 +01:00
|
|
|
complete => this.onCallbackSuccess(),
|
2019-09-23 11:11:00 +02:00
|
|
|
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-11-07 16:01:43 +01:00
|
|
|
width: '500px',
|
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 {
|
2020-02-11 17:27:54 +01:00
|
|
|
return true;
|
2019-04-22 11:11:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-22 14:46:48 +02:00
|
|
|
|
|
|
|
linkToScroll: LinkToScroll;
|
|
|
|
onStepFound(linkToScroll: LinkToScroll) {
|
|
|
|
this.linkToScroll = linkToScroll;
|
|
|
|
}
|
2020-02-11 17:27:54 +01:00
|
|
|
|
|
|
|
private pumpLock() {
|
|
|
|
this.lock.touchedAt = new Date();
|
2020-09-16 17:19:29 +02:00
|
|
|
this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => {
|
2020-02-11 17:27:54 +01:00
|
|
|
if (!isNullOrUndefined(result)) {
|
2020-09-16 17:19:29 +02:00
|
|
|
this.lock.id = Guid.parse(result);
|
2020-02-11 17:27:54 +01:00
|
|
|
} else {
|
|
|
|
this.location.back();
|
|
|
|
}
|
2020-09-16 17:19:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public changeStep(index: number, dataset?: FormControl) {
|
2021-03-17 10:08:59 +01:00
|
|
|
if(this.step != index){ //view is changing
|
|
|
|
this.resetScroll();
|
|
|
|
}
|
2020-09-16 17:19:29 +02:00
|
|
|
this.step = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
public nextStep() {
|
2021-03-17 10:08:59 +01:00
|
|
|
if(this.step < this.maxStep){//view is changing
|
2021-03-19 13:32:17 +01:00
|
|
|
if(this.step === 0 && this.table0fContents){
|
|
|
|
this.table0fContents.seekToFirstElement();
|
|
|
|
}
|
|
|
|
this.step++;
|
2021-03-17 10:08:59 +01:00
|
|
|
this.resetScroll();
|
|
|
|
}
|
|
|
|
// this.step = this.step < this.maxStep ? this.step + 1 : this.step;
|
2020-09-16 17:19:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public previousStep() {
|
2021-03-19 13:32:17 +01:00
|
|
|
if(this.step > 0){
|
2021-03-17 10:08:59 +01:00
|
|
|
this.resetScroll();
|
2021-03-19 13:32:17 +01:00
|
|
|
this.step--;
|
2021-03-17 10:08:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// this.step = this.step !== 0 ? this.step - 1 : this.step;
|
2020-11-11 11:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private resetScroll() {
|
|
|
|
document.getElementById('dataset-editor-form').scrollTop = 0;
|
2020-09-16 17:19:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isDirty() {
|
2020-09-18 17:51:42 +02:00
|
|
|
return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty
|
2020-09-16 17:19:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
discardChanges() {
|
2021-04-07 11:58:45 +02:00
|
|
|
// this.isDiscarded = true;
|
|
|
|
// this.hasChanges = false;
|
|
|
|
// this.hintErrors = false;
|
|
|
|
let messageText = "";
|
|
|
|
let confirmButtonText ="";
|
|
|
|
let cancelButtonText = "";
|
|
|
|
let isDeleteConfirmation = false;
|
|
|
|
|
|
|
|
if (this.isNew && !this.datasetIsOnceSaved) {
|
|
|
|
|
|
|
|
messageText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-NEW-MESSAGE');
|
|
|
|
confirmButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-NEW-CONFIRM');
|
|
|
|
cancelButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-NEW-DENY');
|
|
|
|
isDeleteConfirmation = true;
|
|
|
|
|
|
|
|
// Object.keys(this.formGroup['controls']).forEach((key: string) => {
|
|
|
|
// if (key !== 'dmp' && (key!== 'profile')) {
|
|
|
|
// if(key === 'datasetProfileDefinition'){
|
|
|
|
// this.formGroup.get(key).patchValue(this.datasetProfileDefinitionModel.buildForm().getRawValue);
|
|
|
|
// }else{
|
|
|
|
// this.formGroup.get(key).reset();
|
|
|
|
// }
|
2021-04-06 08:57:17 +02:00
|
|
|
|
2021-04-07 11:58:45 +02:00
|
|
|
// }
|
|
|
|
// });
|
2020-09-18 17:51:42 +02:00
|
|
|
} else {
|
2021-04-07 11:58:45 +02:00
|
|
|
|
|
|
|
messageText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-EDITED-MESSAGE');
|
|
|
|
confirmButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-EDITED-CONFIRM');
|
|
|
|
cancelButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-EDITED-DENY');
|
|
|
|
isDeleteConfirmation = false;
|
|
|
|
|
|
|
|
// this.isDiscarded = true;
|
|
|
|
// this.hasChanges = false;
|
|
|
|
// this.hintErrors = false;
|
|
|
|
// // this._unregisterFormListeners();
|
|
|
|
// this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue)));
|
|
|
|
// // this.registerFormListeners();
|
|
|
|
// this.isDiscarded = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-18 17:51:42 +02:00
|
|
|
}
|
2021-04-07 11:58:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: messageText,
|
|
|
|
confirmButton: confirmButtonText,
|
|
|
|
cancelButton: cancelButtonText,
|
|
|
|
isDeleteConfirmation: true
|
2021-04-09 10:31:16 +02:00
|
|
|
},
|
|
|
|
maxWidth:'40em'
|
2021-04-07 11:58:45 +02:00
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this.backToDmp(this.formGroup.get('dmp').value.id)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this.isDiscarded = false;
|
2020-09-16 17:19:29 +02:00
|
|
|
}
|
|
|
|
|
2020-09-17 17:48:13 +02:00
|
|
|
addDataset(dmpId: string) {
|
|
|
|
this.router.navigate(['/datasets', 'new', dmpId]);
|
2020-09-16 17:19:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
backToDmp(id: string) {
|
|
|
|
this.router.navigate(['/plans', 'edit', id]);
|
2020-02-11 17:27:54 +01:00
|
|
|
}
|
2020-10-16 15:48:28 +02:00
|
|
|
|
|
|
|
datasetInfoValid(): boolean {
|
|
|
|
return this.formGroup.get('label') && this.formGroup.get('label').valid && this.formGroup.get('profile') && this.formGroup.get('profile').valid;
|
|
|
|
}
|
2020-11-02 17:08:25 +01:00
|
|
|
|
2020-11-06 11:42:31 +01:00
|
|
|
getLinks(currentLinks: Link[]) {
|
|
|
|
this.links = currentLinks;
|
2020-11-02 17:08:25 +01:00
|
|
|
}
|
2021-03-09 09:04:50 +01:00
|
|
|
|
|
|
|
printForm(){
|
|
|
|
console.log(this.formGroup);
|
|
|
|
}
|
|
|
|
printFormValue(){
|
|
|
|
console.log(this.formGroup.value);
|
|
|
|
}
|
2021-06-11 11:16:50 +02:00
|
|
|
touchForm(){
|
|
|
|
this.formGroup.markAllAsTouched();
|
|
|
|
this.showtocentriesErrors = true;
|
|
|
|
}
|
2021-03-17 10:08:59 +01:00
|
|
|
|
|
|
|
// tocentries;
|
|
|
|
// this.tocentries = this.getTocEntries(this.formGroup.get('datasetProfileDefinition')); //TODO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get tocentries(){
|
|
|
|
// const form = this.formGroup.get('datasetProfileDefinition')
|
|
|
|
// if(!form) return null;
|
|
|
|
|
|
|
|
// return this.getTocEntries(this.formGroup.get('datasetProfileDefinition'));
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// private _buildRecursively(form: FormGroup,whatAmI:ToCEntryType):ToCEntry{
|
|
|
|
// if(!form) return null;
|
|
|
|
|
|
|
|
// switch(whatAmI){
|
|
|
|
// case ToCEntryType.Section:
|
|
|
|
// const sections = form.get('sections') as FormArray;
|
|
|
|
// const fieldsets = form.get('compositeFields') as FormArray;
|
|
|
|
|
|
|
|
|
|
|
|
// const tempResult:ToCEntry[] = [];
|
|
|
|
|
|
|
|
// if(sections &§ions.length){
|
|
|
|
// sections.controls.forEach(section=>{
|
|
|
|
// tempResult.push(this._buildRecursively(section as FormGroup, ToCEntryType.Section));
|
|
|
|
// });
|
|
|
|
|
|
|
|
// }else if(fieldsets && fieldsets.length){
|
|
|
|
// fieldsets.controls.forEach(fieldset=>{
|
|
|
|
// tempResult.push(this._buildRecursively(fieldset as FormGroup, ToCEntryType.FieldSet));
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// return {
|
|
|
|
// form: form,
|
|
|
|
// id: form.get('id').value,
|
|
|
|
// label: form.get('title').value,
|
|
|
|
// numbering: '',
|
|
|
|
// subEntries:tempResult,
|
|
|
|
// subEntriesType: sections &§ions.length? ToCEntryType.Section: ToCEntryType.FieldSet,
|
|
|
|
// type: ToCEntryType.Section,
|
|
|
|
// ordinal: form.get('ordinal').value
|
|
|
|
// }
|
|
|
|
// case ToCEntryType.FieldSet:
|
|
|
|
// return {
|
|
|
|
// form: form,
|
|
|
|
// label:form.get('title').value,
|
|
|
|
// id: form.get('id').value,
|
|
|
|
// numbering:'s',
|
|
|
|
// subEntries:[],
|
|
|
|
// subEntriesType: ToCEntryType.Field,
|
|
|
|
// type: ToCEntryType.FieldSet,
|
|
|
|
// ordinal: form.get('ordinal').value
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// private _sortByOrdinal(tocentries: ToCEntry[]){
|
|
|
|
|
|
|
|
// if(!tocentries || !tocentries.length) return;
|
|
|
|
|
|
|
|
// tocentries.sort(this._customCompare);
|
|
|
|
// tocentries.forEach(entry=>{
|
|
|
|
// this._sortByOrdinal(entry.subEntries);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// private _customCompare(a,b){
|
|
|
|
// return a.ordinal - b.ordinal;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// private _calculateNumbering(tocentries: ToCEntry[], depth:number[] = []){
|
|
|
|
// if(!tocentries || !tocentries.length){
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let prefixNumbering = depth.length? depth.join('.'): '';
|
|
|
|
|
|
|
|
// if(depth.length) prefixNumbering = prefixNumbering+".";
|
|
|
|
// tocentries.forEach((entry,i)=>{
|
|
|
|
// entry.numbering = prefixNumbering + (i+1);
|
|
|
|
// this._calculateNumbering(entry.subEntries, [...depth, i+1])
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// getTocEntries(form): ToCEntry[] {
|
|
|
|
// if (form == null) { return []; }
|
|
|
|
// const result: ToCEntry[] = [];
|
|
|
|
|
|
|
|
// //build parent pages
|
|
|
|
// (form.get('pages') as FormArray).controls.forEach((pageElement, i) => {
|
|
|
|
// result.push({
|
|
|
|
// id: i+'id',
|
|
|
|
// label: pageElement.get('title').value,
|
|
|
|
// type: ToCEntryType.Page,
|
|
|
|
// form: pageElement,
|
|
|
|
// numbering: (i + 1).toString(),
|
|
|
|
// subEntriesType: ToCEntryType.Section,
|
|
|
|
// subEntries:[],
|
|
|
|
// ordinal: pageElement.get('ordinal').value
|
|
|
|
// } as ToCEntry)
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// result.forEach((entry,i)=>{
|
|
|
|
|
|
|
|
// const sections = entry.form.get('sections') as FormArray;
|
|
|
|
|
|
|
|
// sections.controls.forEach(section=>{
|
|
|
|
// const tempResults = this._buildRecursively(section as FormGroup,ToCEntryType.Section);
|
|
|
|
// entry.subEntries.push(tempResults);
|
|
|
|
// });
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// this._sortByOrdinal(result);
|
|
|
|
// //calculate numbering
|
|
|
|
// this._calculateNumbering(result);
|
|
|
|
// return result;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|