2019-09-23 10:17:03 +02:00
|
|
|
|
2019-03-05 11:20:10 +01:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
import { MatStepper } from '@angular/material/stepper';
|
2019-03-06 15:41:24 +01:00
|
|
|
import { Router } from '@angular/router';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DatasetStatus } from '@app/core/common/enum/dataset-status';
|
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { QuickWizardService } from '@app/core/services/quick-wizard/quick-wizard.service';
|
|
|
|
import { CheckDeactivateBaseComponent } from '@app/library/deactivate/deactivate.component';
|
|
|
|
import { DatasetCreateWizardModel } from '@app/ui/dataset-create-wizard/dataset-create-wizard.model';
|
|
|
|
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { DatasetEditorWizardComponent } from '@app/ui/quick-wizard/dataset-editor/dataset-editor-wizard.component';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2019-03-14 17:04:20 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { Observable, of as observableOf } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-03-05 11:20:10 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'dataset-create-wizard.component',
|
|
|
|
templateUrl: 'dataset-create-wizard.component.html',
|
|
|
|
styleUrls: ['./dataset-create-wizard.component.scss'],
|
|
|
|
})
|
2019-09-24 16:55:03 +02:00
|
|
|
export class DatasetCreateWizard extends CheckDeactivateBaseComponent implements OnInit, IBreadCrumbComponent {
|
2019-03-06 15:41:24 +01:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2021-09-24 20:52:14 +02:00
|
|
|
@ViewChild(DatasetEditorWizardComponent) datasetEditorWizardComponent: DatasetEditorWizardComponent;
|
2019-03-05 11:20:10 +01:00
|
|
|
isLinear = false;
|
2019-03-14 17:04:20 +01:00
|
|
|
isNew = true;
|
2019-09-24 16:55:03 +02:00
|
|
|
isSubmitted = false;
|
2019-03-05 11:20:10 +01:00
|
|
|
formGroup: FormGroup;
|
|
|
|
|
2019-03-26 16:43:19 +01:00
|
|
|
|
2019-03-05 11:20:10 +01:00
|
|
|
datasetCreateWizardModel: DatasetCreateWizardModel;
|
2019-09-23 10:17:03 +02:00
|
|
|
@ViewChild('stepper', { static: true }) stepper: MatStepper;
|
2019-03-05 11:20:10 +01:00
|
|
|
|
|
|
|
constructor(
|
2019-03-06 15:41:24 +01:00
|
|
|
private router: Router,
|
2019-03-05 11:20:10 +01:00
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
public quickWizardService: QuickWizardService,
|
2019-03-14 17:04:20 +01:00
|
|
|
public language: TranslateService,
|
2019-03-26 16:43:19 +01:00
|
|
|
private uiNotificationService: UiNotificationService,
|
|
|
|
private dialog: MatDialog
|
2019-03-05 11:20:10 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.datasetCreateWizardModel = new DatasetCreateWizardModel();
|
|
|
|
this.formGroup = this.datasetCreateWizardModel.buildForm();
|
2019-06-19 10:59:47 +02:00
|
|
|
this.language.get('NAV-BAR.DATASET-DESCRIPTION-WIZARD').pipe(takeUntil(this._destroyed)).subscribe(x => {
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([
|
2019-06-19 10:59:47 +02:00
|
|
|
{
|
|
|
|
parentComponentName: 'Dashboard',
|
|
|
|
label: x,
|
|
|
|
url: '/datasetcreatewizard'
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
})
|
|
|
|
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
2019-03-26 16:43:19 +01:00
|
|
|
if (this.formGroup.get('datasets') && this.formGroup.get('datasets').get('datasetsList') && (this.formGroup.get('datasets').get('datasetsList') as FormArray).length > 0) {
|
|
|
|
for (let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls) {
|
2019-06-25 11:16:37 +02:00
|
|
|
control.get('status').setValue(DatasetStatus.Draft);
|
2019-03-26 16:43:19 +01:00
|
|
|
}
|
2019-06-19 10:59:47 +02:00
|
|
|
// this.onSubmitSave();
|
|
|
|
const dmpId = this.formGroup.get('dmpMeta').get('dmp').value.id;
|
|
|
|
this.quickWizardService.createQuickDatasetWizard(this.formGroup.value)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => this.onCallbackSuccess(dmpId)
|
2019-09-24 16:55:03 +02:00
|
|
|
);
|
2019-03-26 16:43:19 +01:00
|
|
|
} else {
|
|
|
|
return;
|
2019-03-14 19:00:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveFinalize() {
|
2019-06-26 11:24:06 +02:00
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '300px',
|
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('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: false
|
2019-03-26 16:43:19 +01:00
|
|
|
}
|
2019-06-26 11:24:06 +02:00
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
if (this.formGroup.get('datasets') && this.formGroup.get('datasets').get('datasetsList') && (this.formGroup.get('datasets').get('datasetsList') as FormArray).length > 0) {
|
|
|
|
for (let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls) {
|
|
|
|
control.get('status').setValue(DatasetStatus.Finalized);
|
|
|
|
}
|
|
|
|
this.onSubmitSaveAndFinalize();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|
|
|
|
|
2019-06-19 10:59:47 +02:00
|
|
|
// onSubmitSave() {
|
|
|
|
// const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
// data: {
|
|
|
|
// message: this.language.instant('QUICKWIZARD.SAVE-DIALOG.TITLE'),
|
|
|
|
// confirmButton: this.language.instant('QUICKWIZARD.SAVE-DIALOG.ACTIONS.AFFIRMATIVE'),
|
|
|
|
// cancelButton: this.language.instant('QUICKWIZARD.SAVE-DIALOG.ACTIONS.NEGATIVE')
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
// if (result) {
|
|
|
|
// this.datasetEditorWizardComponent.addDataset();
|
|
|
|
// } else if (result === false) {
|
|
|
|
// this.quickWizardService.createQuickDatasetWizard(this.formGroup.value)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(
|
|
|
|
// complete => this.onCallbackSuccess()
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
2019-03-26 16:43:19 +01:00
|
|
|
|
|
|
|
onSubmitSaveAndFinalize() {
|
2019-06-19 10:59:47 +02:00
|
|
|
const dmpId = this.formGroup.get('dmpMeta').get('dmp').value.id;
|
2019-03-05 11:20:10 +01:00
|
|
|
this.quickWizardService.createQuickDatasetWizard(this.formGroup.value)
|
2019-03-14 17:04:20 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-06-19 10:59:47 +02:00
|
|
|
complete => this.onCallbackSuccess(dmpId)
|
2019-09-24 16:55:03 +02:00
|
|
|
);
|
2019-03-14 17:04:20 +01:00
|
|
|
}
|
|
|
|
|
2019-03-26 16:43:19 +01:00
|
|
|
hasDatasets() {
|
|
|
|
if ((this.formGroup.get('datasets').get('datasetsList') as FormArray).length > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:00:02 +01:00
|
|
|
public isFormValid() {
|
2019-03-26 16:43:19 +01:00
|
|
|
return this.formGroup.valid;
|
|
|
|
}
|
2019-03-14 19:00:02 +01:00
|
|
|
|
2019-06-19 10:59:47 +02:00
|
|
|
onCallbackSuccess(dmpId: string): void {
|
2019-10-02 13:11:19 +02:00
|
|
|
this.isSubmitted = true;
|
2019-03-14 17:04:20 +01:00
|
|
|
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
2019-06-19 10:59:47 +02:00
|
|
|
this.router.navigate(['/plans/overview/' + dmpId]);
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
|
2019-03-06 10:43:48 +01:00
|
|
|
isActive(step: string): boolean {
|
2019-03-14 17:04:20 +01:00
|
|
|
switch (step) {
|
|
|
|
case 'step1':
|
|
|
|
return this.stepper.selectedIndex == 0;
|
|
|
|
case 'step2':
|
|
|
|
return this.stepper.selectedIndex == 1;
|
|
|
|
}
|
|
|
|
}
|
2019-09-24 16:55:03 +02:00
|
|
|
|
|
|
|
canDeactivate(): boolean {
|
|
|
|
return this.isSubmitted || !this.formGroup.dirty;
|
|
|
|
}
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|