From 5944dfc0059c39ef5e669005e8a1a9dd2296f07f Mon Sep 17 00:00:00 2001 From: apapachristou Date: Thu, 17 Sep 2020 18:48:13 +0300 Subject: [PATCH] Dataset editor changes on save --- .../dataset-wizard/dataset-wizard.service.ts | 4 +- .../dataset-wizard.component.html | 20 ++++---- .../dataset-wizard.component.scss | 1 + .../dataset-wizard.component.ts | 48 ++++++++++++++----- .../app/ui/dmp/clone/dmp-clone.component.html | 7 ++- .../ui/dmp/editor/dmp-editor.component.html | 7 ++- .../ui/dmp/editor/dmp-editor.component.scss | 3 +- .../app/ui/dmp/editor/dmp-editor.component.ts | 45 ++++++++++------- .../table-of-contents.ts | 2 +- dmp-frontend/src/assets/i18n/de.json | 1 + dmp-frontend/src/assets/i18n/en.json | 1 + dmp-frontend/src/assets/i18n/es.json | 1 + dmp-frontend/src/assets/i18n/gr.json | 1 + dmp-frontend/src/assets/i18n/tr.json | 1 + 14 files changed, 91 insertions(+), 51 deletions(-) diff --git a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts index 4db5fc2ee..8d20be7d8 100644 --- a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts +++ b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts @@ -42,8 +42,8 @@ export class DatasetWizardService { return this.http.delete(this.actionUrl + 'delete/' + id, { headers: this.headers }); } - createDataset(datasetModel: DatasetWizardModel): Observable { - return this.http.post(this.actionUrl, datasetModel, { headers: this.headers }); + createDataset(datasetModel: DatasetWizardModel): Observable { + return this.http.post(this.actionUrl, datasetModel, { headers: this.headers }); } public downloadPDF(id: string): Observable> { 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 c709ca791..d713b8079 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 @@ -27,8 +27,9 @@
- - + + +
@@ -51,7 +52,7 @@
0. {{'DMP-EDITOR.STEPPER.MAIN-INFO' | translate}} (5)
- +
@@ -60,14 +61,17 @@ chevron_left
{{'DMP-EDITOR.STEPPER.PREVIOUS' | translate}}
-
+
chevron_right
{{'DMP-EDITOR.STEPPER.NEXT' | translate}}
-
- - add{{'DMP-LISTING.ACTIONS.ADD-DATASET-SHORT' | translate}} - +
+ chevron_right +
{{'DMP-EDITOR.STEPPER.NEXT' | translate}}
+
+
+ add +
{{'DMP-LISTING.ACTIONS.ADD-DATASET-SHORT' | 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 f4fc2cc1f..876c2da36 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 @@ -356,6 +356,7 @@ display: flex; align-items: center; padding-left: 0.625rem; + padding-right: 0.625rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 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 c072f84e0..119dea19c 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 @@ -42,6 +42,12 @@ import { AuthService } from '@app/core/services/auth/auth.service'; import { environment } from 'environments/environment'; import { ConfigurationService } from '@app/core/services/configuration/configuration.service'; + +enum SaveType { + close = 0, + addNew = 1 +} + @Component({ selector: 'app-dataset-wizard-component', templateUrl: 'dataset-wizard.component.html', @@ -74,7 +80,9 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr step: number = 0; stepOffset: number = 1; - maxStep: number = 1; + maxStep: number; + + saveAnd = SaveType; constructor( private datasetWizardService: DatasetWizardService, @@ -350,6 +358,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr }]); } + !this.isNew ? this.maxStep = 1 : this.maxStep = 0; // this.route.params // .pipe(takeUntil(this._destroyed)) // .subscribe((params: Params) => { @@ -367,7 +376,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr this.formGroup.get('profile').valueChanges .pipe(takeUntil(this._destroyed)) .subscribe(x => { - this.datasetProfileValueChanged(x); + this.datasetProfileValueChanged(x.id); }); } @@ -387,7 +396,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr datasetProfileValueChanged(profiledId: string) { if (profiledId && profiledId.length > 0) { this.formGroup.removeControl('datasetProfileDefinition'); - this.getDefinition(); + this.getDefinition(profiledId); + this.maxStep = 1; } } @@ -439,9 +449,9 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr else { return item['label']; } } - getDefinition() { + getDefinition(profileId: string) { // if (this.formGroup.invalid) { setTimeout(() => this.stepper.selectedIndex = 0); return; } - this.datasetWizardService.getDefinition(this.formGroup.get('profile').value) + this.datasetWizardService.getDefinition(profileId) .pipe(takeUntil(this._destroyed)) .subscribe(item => { this.datasetWizardModel.datasetProfileDefinition = new DatasetDescriptionFormEditorModel().fromModel(item); @@ -487,23 +497,25 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr // ); // } - submit() { + + + submit(saveType?: SaveType) { this.datasetWizardService.createDataset(this.formGroup.getRawValue()) .pipe(takeUntil(this._destroyed)) .subscribe( data => { - this.onCallbackSuccess(this.datasetWizardModel.id); + this.onCallbackSuccess(data, saveType); }, error => this.onCallbackError(error)); } - save() { + save(saveType?: SaveType) { this.formService.touchAllFormFields(this.formGroup); if (!this.isSemiFormValid(this.formGroup)) { this.showValidationErrorsDialog(); return; } - this.submit(); + this.submit(saveType); } private showValidationErrorsDialog(projectOnly?: boolean) { @@ -567,9 +579,19 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr }); } - onCallbackSuccess(id?: String): void { + onCallbackSuccess(id?: String, saveType?: SaveType): void { this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success); - id ? this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', id]); }) : this.router.navigate(['/datasets']); + if (id) { + 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 { + this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', id]); }); + } + } else { + this.router.navigate(['/datasets']); + } } onCallbackError(error: any) { @@ -799,8 +821,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr } - addDataset() { - + addDataset(dmpId: string) { + this.router.navigate(['/datasets', 'new', dmpId]); } backToDmp(id: string) { diff --git a/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.html b/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.html index 49ed481f7..718543659 100644 --- a/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.html +++ b/dmp-frontend/src/app/ui/dmp/clone/dmp-clone.component.html @@ -93,10 +93,9 @@ chevron_right
{{'DMP-EDITOR.STEPPER.NEXT' | translate}}
-
- - add{{'DMP-LISTING.ACTIONS.ADD-DATASET-SHORT' | translate}} - +
+ add +
{{'DMP-LISTING.ACTIONS.ADD-DATASET-SHORT' | translate}}
diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html index 619e0af27..37c50992d 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.html @@ -117,10 +117,9 @@ chevron_right
{{'DMP-EDITOR.STEPPER.NEXT' | translate}}
-
- - add{{'DMP-LISTING.ACTIONS.ADD-DATASET-SHORT' | translate}} - +
+ add +
{{'DMP-LISTING.ACTIONS.ADD-DATASET-SHORT' | translate}}
diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss index fe394b212..67566b300 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.scss @@ -286,7 +286,8 @@ a:hover { justify-content: left; display: flex; align-items: center; - padding-left: 0.625rem; + padding-left: 0.625rem; + padding-right: 0.625rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts index ca80a16b4..74e29e842 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts @@ -422,7 +422,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC // return this.grantService.getWithExternal(grantRequestItem); // } - formSubmit(showAddDatasetDialog?: boolean): void { + formSubmit(addNew?: boolean, showAddDatasetDialog?: boolean): void { this.formService.touchAllFormFields(this.formGroup); if (this.isNewDataset) { if (!this.isDatasetFormValid) { @@ -436,7 +436,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.showValidationErrorsDialog(); return; } - this.onSubmit(showAddDatasetDialog); + this.onSubmit(addNew, showAddDatasetDialog); } } @@ -461,37 +461,39 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC }); } - onSubmit(showAddDatasetDialog?: boolean): void { - this.dmpService.createDmpWithDatasets(this.formGroup.getRawValue()) + onSubmit(addNew?: boolean, showAddDatasetDialog?: boolean): void { + this.dmpService.createDmp(this.formGroup.getRawValue()) .pipe(takeUntil(this._destroyed)) .subscribe( complete => { if (showAddDatasetDialog) { this.addDatasetOpenDialog(complete); } - else if (this.step < this.stepsBeforeDatasets) { this.onCallbackSuccess(complete) } - else { this.onCallbackSuccess(complete, this.datasetId) } + if (addNew) { + this.onCallbackSuccessAddNew(complete); + } + else { this.onCallbackSuccess(complete) } }, error => { this.formGroup.get('status').setValue(DmpStatus.Draft); this.onCallbackError(error); } - ) - // this.dmpService.createDmp(this.formGroup.getRawValue()) + ); + // this.dmpService.createDmpWithDatasets(this.formGroup.getRawValue()) // .pipe(takeUntil(this._destroyed)) // .subscribe( // complete => { // if (showAddDatasetDialog) { // this.addDatasetOpenDialog(complete); // } - // else { this.onCallbackSuccess(complete) } + // else if (this.step < this.stepsBeforeDatasets) { this.onCallbackSuccess(complete) } + // else { this.onCallbackSuccess(complete, this.datasetId) } // }, // error => { // this.formGroup.get('status').setValue(DmpStatus.Draft); // this.onCallbackError(error); // } - // ); - + // ) } onDatasetSubmit(): void { @@ -520,6 +522,11 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC //this.validateAllFormFields(this.formGroup); } + onCallbackSuccessAddNew(id?: String) { + // this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success); + this.router.navigate(['/datasets', 'new', id]); + } + public setErrorModel(validationErrorModel: ValidationErrorModel) { Object.keys(validationErrorModel).forEach(item => { (this.dmp.validationErrorModel)[item] = (validationErrorModel)[item]; @@ -712,13 +719,15 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC } addDataset() { - if (!this.formGroup.get('datasets')) { - this.formGroup.addControl('datasets', new FormBuilder().array(new Array())); - } - 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; + this.formSubmit(true, false); + // Add dataset to list + // if (!this.formGroup.get('datasets')) { + // this.formGroup.addControl('datasets', new FormBuilder().array(new Array())); + // } + // 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; } hasProfile(): boolean { diff --git a/dmp-frontend/src/app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents.ts b/dmp-frontend/src/app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents.ts index 8400829ae..1c53596d9 100644 --- a/dmp-frontend/src/app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents.ts +++ b/dmp-frontend/src/app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents.ts @@ -99,7 +99,7 @@ export class TableOfContents extends BaseComponent implements OnInit { } this.links = links; // Initialize selected for button next on dataset wizard component editor - this.links[0].selected = true; + this.links.length > 0 ? this.links[0].selected = true : null; }) } diff --git a/dmp-frontend/src/assets/i18n/de.json b/dmp-frontend/src/assets/i18n/de.json index d3ffa9fee..121c14118 100644 --- a/dmp-frontend/src/assets/i18n/de.json +++ b/dmp-frontend/src/assets/i18n/de.json @@ -491,6 +491,7 @@ "GO-TO-DMP": "Gehe zu Datensatzbeschreibung DMP", "SAVE": "Speichern", "SAVE-AND-ADD": "Save & Add New", + "SAVE-AND-CLOSE": "Save & Close", "SAVE-AND-FINALISE": "Speichern und Fertigstellen", "FINALIZE": "Fertigstellen", "REVERSE": "Fertigstellung rückgängig machen", diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index d807aacbe..0a5981fb7 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -530,6 +530,7 @@ "GO-TO-DMP": "Go to Dataset Description's DMP", "SAVE": "Save", "SAVE-AND-ADD": "Save & Add New", + "SAVE-AND-CLOSE": "Save & Close", "SAVE-AND-FINALISE": "Save and Finalize", "FINALIZE": "Finalize", "REVERSE": "Undo Finalization", diff --git a/dmp-frontend/src/assets/i18n/es.json b/dmp-frontend/src/assets/i18n/es.json index 29bb94f6b..51e262ecd 100644 --- a/dmp-frontend/src/assets/i18n/es.json +++ b/dmp-frontend/src/assets/i18n/es.json @@ -531,6 +531,7 @@ "GO-TO-DMP": "Ir al PGD de la descripción del dataset", "SAVE": "Grabar", "SAVE-AND-ADD": "Save & Add New", + "SAVE-AND-CLOSE": "Save & Close", "SAVE-AND-FINALISE": "Grabar y finalizar", "FINALIZE": "Finalizar", "REVERSE": "Deshacer la finalización", diff --git a/dmp-frontend/src/assets/i18n/gr.json b/dmp-frontend/src/assets/i18n/gr.json index b104e8438..5330bdf24 100644 --- a/dmp-frontend/src/assets/i18n/gr.json +++ b/dmp-frontend/src/assets/i18n/gr.json @@ -528,6 +528,7 @@ "GO-TO-DMP": "Μετάβαση σε Περιγραφή Συνόλου Δεδομένων του Σχεδίου Διαχείρισης Δεδομένων", "SAVE": "Save", "SAVE-AND-ADD": "Save & Add New", + "SAVE-AND-CLOSE": "Save & Close", "SAVE-AND-FINALISE": "Αποθήκευση και Οριστικοποίηση", "FINALIZE": "Οριστικοποίηση", "REVERSE": "Αναίρεση Οριστικοποίησης", diff --git a/dmp-frontend/src/assets/i18n/tr.json b/dmp-frontend/src/assets/i18n/tr.json index 602c44ff5..3a70acbd8 100644 --- a/dmp-frontend/src/assets/i18n/tr.json +++ b/dmp-frontend/src/assets/i18n/tr.json @@ -526,6 +526,7 @@ "GO-TO-DMP": "Veri seti Tanımı VYP'na Git", "SAVE": "Kaydet", "SAVE-AND-ADD": "Save & Add New", + "SAVE-AND-CLOSE": "Save & Close", "SAVE-AND-FINALISE": "Kaydet ve Bitir", "FINALIZE": "Tamamla", "REVERSE": "Tamamlamayı Geri Al",