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 8e5cc03fd..94c168100 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 @@ -82,7 +82,7 @@ -
+
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 6e5a702a3..a3ac243a6 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 @@ -96,6 +96,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC stepsBeforeDatasets: number = 4; maxStep: number = 4; + scrollTop: number; + constructor( private dmpProfileService: DmpProfileService, private datasetWizardService: DatasetWizardService, @@ -169,7 +171,6 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.dmp.extraProperties = new ExtraPropertiesFormModel(); this.dmp.fromModel(data); this.formGroup = this.dmp.buildForm(); - // console.log(this.formGroup); this.datasets = this.formGroup.get('datasets') as FormArray; @@ -436,6 +437,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC } onSubmit(addNew?: boolean, showAddDatasetDialog?: boolean): void { + this.scrollTop = document.getElementById('editor-form').scrollTop; + this.dmpService.createDmp(this.formGroup.getRawValue()) .pipe(takeUntil(this._destroyed)) .subscribe( @@ -484,25 +487,35 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC } onCallbackSuccess(dmp?: DmpModel, datasetId?: string): void { + + // On save keep editor position this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success); - // console.log(dmp) - // if (dmp) { - // let dmpEditorModel: DmpEditorModel; - // dmpEditorModel = new DmpEditorModel(); - // dmpEditorModel.grant = new GrantTabModel(); - // dmpEditorModel.project = new ProjectFormModel(); - // dmpEditorModel.funder = new FunderFormModel(); - // dmpEditorModel.extraProperties = new ExtraPropertiesFormModel(); - // dmpEditorModel.fromModel(dmp); - // this.formGroup = dmpEditorModel.buildForm(); - // } else { - // this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans']); }); - // } - if (dmp.id != null) { - datasetId ? this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans', 'edit', dmp.id], { queryParams: { dataset: datasetId } }); }) : this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans', 'edit', dmp.id]); }) + if (dmp) { + let dmpEditorModel: DmpEditorModel; + dmpEditorModel = new DmpEditorModel(); + dmpEditorModel.grant = new GrantTabModel(); + dmpEditorModel.project = new ProjectFormModel(); + dmpEditorModel.funder = new FunderFormModel(); + dmpEditorModel.extraProperties = new ExtraPropertiesFormModel(); + dmpEditorModel.fromModel(dmp); + this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue())); + this.associatedUsers = dmp.associatedUsers; + this.people = dmp.users; + + setTimeout(() => { this.formGroup = null; }); + setTimeout(() => { this.formGroup = dmpEditorModel.buildForm(); }); + setTimeout(() => { document.getElementById('editor-form').scrollTop = this.scrollTop; }); + } else { this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans']); }); } + + // Uncomment to not keep editor position on save + // if (dmp.id != null) { + // datasetId ? this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans', 'edit', dmp.id], { queryParams: { dataset: datasetId } }); }) : this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans', 'edit', dmp.id]); }) + // } else { + // this.router.navigate(['/reload']).then(() => { this.router.navigate(['/plans']); }); + // } } onCallbackError(error: any) { @@ -836,7 +849,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.hasChanges = false; if (!this.isNew) { let grantControl; - if(this.formGroup.get('grant').get('existGrant')) { + if (this.formGroup.get('grant').get('existGrant')) { grantControl = new GrantTabModel(); grantControl.fromModel(this.formGroup.get('grant').get('existGrant').value); } else { @@ -847,7 +860,7 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue))); - if(this.formGroup.get('grant').get('existGrant')) { + if (this.formGroup.get('grant').get('existGrant')) { this.formGroup.get('grant').get('existGrant').setValue(grantControl.existGrant); } else { this.formGroup.get('grant').setValue(grantControl);