After dmp save remain at the same position

This commit is contained in:
apapachristou 2020-11-02 18:18:49 +02:00
parent abfb6342b2
commit b13dab598f
2 changed files with 32 additions and 19 deletions

View File

@ -82,7 +82,7 @@
<app-form-progress-indication class="col-12" *ngIf="formGroup" [formGroup]="formGroup" [isDmpEditor]="true"></app-form-progress-indication>
</div>
</div>
<div class="col-auto form">
<div class="col-auto form" id="editor-form">
<main-info [hidden]="this.step !== 0" [formGroup]="formGroup" [isUserOwner]="isUserOwner" (onFormChanged)="formChanged()"></main-info>
<funding-info [hidden]="this.step !== 1" [formGroup]="formGroup" [grantformGroup]="formGroup.get('grant')" [projectFormGroup]="formGroup.get('project')" [funderFormGroup]="formGroup.get('funder')" [isFinalized]="isFinalized || lockStatus" [isNew]="isNew" [isUserOwner]="isUserOwner" (onFormChanged)="formChanged()"></funding-info>
<license-info [hidden]="this.step !== 2" [formGroup]="formGroup" [isUserOwner]="isUserOwner" (onFormChanged)="formChanged()"></license-info>

View File

@ -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) {