From 758c72ed2e352b79647d57c0f77dc9c59e8716ef Mon Sep 17 00:00:00 2001 From: apapachristou Date: Thu, 27 Jun 2019 18:13:33 +0300 Subject: [PATCH] Adds button to change Dataset Status, if DMP is Draft --- .../dataset-wizard.component.html | 2 + .../dataset-wizard.component.scss | 2 +- .../dataset-wizard.component.ts | 106 ++++++------------ dmp-frontend/src/assets/i18n/en.json | 1 + 4 files changed, 41 insertions(+), 70 deletions(-) diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html index eb572899c..d836e7b24 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html @@ -101,6 +101,8 @@ (click)="saveFinalize();" type="button">{{ 'DATASET-WIZARD.ACTIONS.FINALIZE' | translate }}
+ diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss index 9e1c72c2b..b2049965d 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss @@ -9,7 +9,7 @@ .description-action-row { margin-top: 1em; } - .deleteButton { + .deleteButton, .reverseButton { margin-top: 15px; margin-bottom: 15px; margin-right: 15px; diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index f6df069d9..9c1ef05e4 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -29,6 +29,7 @@ import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCru import { DatasetDescriptionFormEditorModel } from '../../misc/dataset-description-form/dataset-description-form.model'; import { DatasetCopyDialogueComponent } from './dataset-copy-dialogue/dataset-copy-dialogue.component'; import { DatasetWizardEditorModel } from './dataset-wizard-editor.model'; +import { DmpStatus } from '../../../core/common/enum/dmp-status'; @Component({ selector: 'app-dataset-wizard-component', @@ -58,6 +59,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr profileUpdateId: string; downloadDocumentId: string; isLinear = false; + hasReversableStatus: boolean = false; constructor( private datasetWizardService: DatasetWizardService, @@ -83,31 +85,6 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr const dmpRequestItem: RequestItem = new RequestItem(); dmpRequestItem.criteria = new DmpCriteria(); - // const externalDatasetRequestItem: RequestItem = new RequestItem(); - // externalDatasetRequestItem.criteria = new ExternalDatasetCriteria(); - // this.externalDatasetAutoCompleteConfiguration = new AutoCompleteConfiguration(this.externalSourcesService.searchDatasetSExternalDatasetservice.bind(this.externalSourcesService), - // externalDatasetRequestItem, new BehaviorSubject(false)); - - // const registriesRequestItem: RequestItem = new RequestItem(); - // registriesRequestItem.criteria = new RegistryCriteria(); - // this.registriesAutoCompleteConfiguration = new AutoCompleteConfiguration(this.externalSourcesService.searchDatasetRegistry.bind(this.externalSourcesService), - // registriesRequestItem, new BehaviorSubject(false)); - - // const dataRepositoriesRequestItem: RequestItem = new RequestItem(); - // dataRepositoriesRequestItem.criteria = new DataRepositoryCriteria(); - // this.dataRepositoriesAutoCompleteConfiguration = new AutoCompleteConfiguration(this.externalSourcesService.searchDatasetRepository.bind(this.externalSourcesService), - // dataRepositoriesRequestItem, new BehaviorSubject(false)); - - // const servicesRequestItem: RequestItem = new RequestItem(); - // servicesRequestItem.criteria = new ServiceCriteria(); - // this.servicesAutoCompleteConfiguration = new AutoCompleteConfiguration(this.externalSourcesService.searchDatasetService.bind(this.externalSourcesService), - // servicesRequestItem, new BehaviorSubject(false)); - - // const tagsRequestItem: RequestItem = new RequestItem(); - // tagsRequestItem.criteria = new TagCriteria(); - // this.tagsAutoCompleteConfiguration = new AutoCompleteConfiguration(this.externalSourcesService.searchDatasetTags.bind(this.externalSourcesService), - // tagsRequestItem, new BehaviorSubject(false)); - this.dmpAutoCompleteConfiguration = { filterFn: this.searchDmp.bind(this), initialItems: (extraData) => this.searchDmp(''), @@ -138,11 +115,6 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr label: this.datasetWizardModel.label, url: '/datasets/edit/' + this.datasetWizardModel.id, notFoundResolver: [ - // { - // parentComponentName: null, - // label: this.datasetWizardModel.dmp.label, - // url: '/plans/overview/' + this.datasetWizardModel.dmp.id - // }, { parentComponentName: null, label: this.language.instant('NAV-BAR.MY-DATASET-DESCRIPTIONS').toUpperCase(), @@ -158,16 +130,11 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr } // if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. this.loadDatasetProfiles(); - this.formGroup.get('dmp').valueChanges - .pipe(takeUntil(this._destroyed)) - .subscribe(() => { - this.dmpValueChanged(this.formGroup.get('dmp').value); - }); - this.formGroup.get('profile').valueChanges - .pipe(takeUntil(this._destroyed)) - .subscribe(x => { - this.datasetProfileValueChanged(x); - }); + this.registerFormListeners(); + + if (this.formGroup.get('dmp').value.status == DmpStatus.Draft && this.formGroup.get('status').value == DatasetStatus.Finalized) { + this.hasReversableStatus = true; + } }); } else if (dmpId != null) { this.isNew = true; @@ -179,21 +146,10 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr this.datasetWizardModel.dmp = data; this.formGroup = this.datasetWizardModel.buildForm(); this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft; - if (this.datasetWizardModel.status === DatasetStatus.Finalized) { - this.formGroup.disable(); - this.viewOnly = true; - } + this.loadDatasetProfiles(); - this.formGroup.get('dmp').valueChanges - .pipe(takeUntil(this._destroyed)) - .subscribe(() => { - this.dmpValueChanged(this.formGroup.get('dmp').value); - }); - this.formGroup.get('profile').valueChanges - .pipe(takeUntil(this._destroyed)) - .subscribe(x => { - this.datasetProfileValueChanged(x); - }); + this.registerFormListeners(); + this.breadCrumbs = Observable.of([ { parentComponentName: null, @@ -327,16 +283,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr this.viewOnly = true; } //if (this.viewOnly) { this.formGroup.disable(); } // For future use, to make Dataset edit like DMP. - this.formGroup.get('dmp').valueChanges - .pipe(takeUntil(this._destroyed)) - .subscribe(x => { - this.dmpValueChanged(x); - }); - this.formGroup.get('profile').valueChanges - .pipe(takeUntil(this._destroyed)) - .subscribe(x => { - this.datasetProfileValueChanged(x); - }); + this.registerFormListeners(); this.dmpValueChanged(null); this.breadCrumbs = Observable.of([ { @@ -354,6 +301,19 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr // }); } + registerFormListeners() { + this.formGroup.get('dmp').valueChanges + .pipe(takeUntil(this._destroyed)) + .subscribe(x => { + this.dmpValueChanged(x); + }); + this.formGroup.get('profile').valueChanges + .pipe(takeUntil(this._destroyed)) + .subscribe(x => { + this.datasetProfileValueChanged(x); + }); + } + dmpValueChanged(dmp: DmpListingModel) { if (dmp) { this.formGroup.get('profile').enable(); @@ -446,13 +406,21 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr }); } - save() { - //if (!this.isFormValid()) { return; } - this.formGroup.get('status').setValue(DatasetStatus.Draft); this.submit(); } + reverse() { + this.hasReversableStatus = false; + this.datasetWizardModel.status = DatasetStatus.Draft; + setTimeout(x => { this.formGroup = null; }); + setTimeout(x => { + this.formGroup = this.datasetWizardModel.buildForm(); + this.registerFormListeners(); + }); + + } + saveFinalize() { const dialogRef = this.dialog.open(ConfirmationDialogComponent, { data: { @@ -599,9 +567,9 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr maxWidth: '300px', data: { message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'), - confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'), + confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'), cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'), - isDeleteConfirmation: false + isDeleteConfirmation: true } }); dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index c114e1779..ccf003783 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -324,6 +324,7 @@ "SAVE": "Save", "SAVE-AND-FINALISE": "Save and Finalize", "FINALIZE": "Finalize", + "REVERSE": "Undo Finalization", "DOWNLOAD-PDF": "Download PDF", "DOWNLOAD-XML": "Download XML", "DOWNLOAD-DOCX": "Download DOCX",