Ticket 8391: DMP Editor: Add dialog before Discard. Dataset Editor: On Discard reset the form instead of go back in dmp editor.

This commit is contained in:
Konstantinos Triantafyllou 2023-03-15 15:55:57 +02:00
parent 180e02c829
commit 6ca77c2df2
10 changed files with 116 additions and 63 deletions

View File

@ -93,6 +93,8 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
availableProfiles: DatasetProfileModel[] = []; availableProfiles: DatasetProfileModel[] = [];
itemId: string; itemId: string;
dmpId: string;
newDmpId: string;
publicId: string; publicId: string;
profileUpdateId: string; profileUpdateId: string;
downloadDocumentId: string; downloadDocumentId: string;
@ -166,14 +168,24 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
const params = this.route.snapshot.params; const params = this.route.snapshot.params;
const queryParams = this.route.snapshot.queryParams; const queryParams = this.route.snapshot.queryParams;
this.itemId = params['id']; this.itemId = params['id'];
const dmpId = params['dmpId']; this.dmpId = params['dmpId'];
const newDmpId = queryParams['newDmpId']; this.newDmpId = queryParams['newDmpId'];
this.publicId = params['publicId']; this.publicId = params['publicId'];
this.profileUpdateId = params['updateId']; this.profileUpdateId = params['updateId'];
this.itemId ? this.downloadDocumentId = this.itemId : this.downloadDocumentId = this.publicId this.itemId ? this.downloadDocumentId = this.itemId : this.downloadDocumentId = this.publicId
if (this.itemId != null && newDmpId == null) { this.init();
// this.route.params
// .pipe(takeUntil(this._destroyed))
// .subscribe((params: Params) => {
// const itemId = params['id'];
// if (itemId != null) { setTimeout(() => this.stepper.selectedIndex = 2); }
// });
}
init() {
if (this.itemId != null && this.newDmpId == null) {
this.isNew = false; this.isNew = false;
this.datasetWizardService.getSingle(this.itemId) this.datasetWizardService.getSingle(this.itemId)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
@ -239,9 +251,9 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
this.router.navigate(['/datasets/']); this.router.navigate(['/datasets/']);
return observableOf(null); return observableOf(null);
}); });
} else if (dmpId != null) { } else if (this.dmpId != null) {
this.isNew = true; this.isNew = true;
this.dmpService.getSingleNoDatasets(dmpId).pipe(map(data => data as DmpModel)) this.dmpService.getSingleNoDatasets(this.dmpId).pipe(map(data => data as DmpModel))
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(data => { .subscribe(data => {
this.datasetWizardModel = new DatasetWizardEditorModel(); this.datasetWizardModel = new DatasetWizardEditorModel();
@ -294,7 +306,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
}]); }]);
}); });
}); });
} else if (newDmpId != null) { } else if (this.newDmpId != null) {
this.isNew = false; this.isNew = false;
this.isCopy = true; this.isCopy = true;
this.datasetWizardService.getSingle(this.itemId) this.datasetWizardService.getSingle(this.itemId)
@ -306,7 +318,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
this.datasetWizardModel.status = 0; this.datasetWizardModel.status = 0;
this.formGroup = this.datasetWizardModel.buildForm(); this.formGroup = this.datasetWizardModel.buildForm();
this.formGroup.get('id').setValue(null); this.formGroup.get('id').setValue(null);
this.dmpService.getSingleNoDatasets(newDmpId).pipe(map(data => data as DmpModel)) this.dmpService.getSingleNoDatasets(this.newDmpId).pipe(map(data => data as DmpModel))
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(data => { .subscribe(data => {
setTimeout(() => { setTimeout(() => {
@ -442,13 +454,6 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
url: '/datasets/new/' url: '/datasets/new/'
}]); }]);
} }
// this.route.params
// .pipe(takeUntil(this._destroyed))
// .subscribe((params: Params) => {
// const itemId = params['id'];
// if (itemId != null) { setTimeout(() => this.stepper.selectedIndex = 2); }
// });
} }
// private _listenersSubscription:Subscription = new Subscription(); // private _listenersSubscription:Subscription = new Subscription();
@ -953,9 +958,10 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
document.getElementById('dataset-editor-form').scrollTop = this.scrollTop; document.getElementById('dataset-editor-form').scrollTop = this.scrollTop;
document.getElementById('stepper-options').scrollTop = this.tocScrollTop; document.getElementById('stepper-options').scrollTop = this.tocScrollTop;
}, 500); }, 500);
this.saving = false; this.saving = false;
this.isNew = false; if(this.isNew) {
this.reloadDateset(this.datasetWizardModel.id);
}
// this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', data.id]); }); // this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', data.id]); });
} }
} else { } else {
@ -1326,7 +1332,10 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
}); });
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) { if (result) {
this.backToDmp(this.formGroup.get('dmp').value.id) // this.backToDmp(this.formGroup.get('dmp').value.id)
setTimeout(x => {
this.init();
});
} }
}); });
@ -1338,6 +1347,10 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme
this.router.navigate(['/datasets', 'new', dmpId]); this.router.navigate(['/datasets', 'new', dmpId]);
} }
reloadDateset(datasetId: string) {
this.router.navigate(['/datasets', 'edit', datasetId]);
}
backToDmp(id: string) { backToDmp(id: string) {
this.router.navigate(['/plans', 'edit', id]); this.router.navigate(['/plans', 'edit', id]);
} }

View File

@ -43,7 +43,7 @@
[vertical]="true" class="ml-2 mr-2"></mat-divider> [vertical]="true" class="ml-2 mr-2"></mat-divider>
<div class="col-auto d-flex align-items-center"> <div class="col-auto d-flex align-items-center">
<button [disabled]="saving" *ngIf="isDirty()" type="button" mat-raised-button class="discard-btn mr-3" (click)="discardChanges()"> <button [disabled]="saving" *ngIf="isDirty()" type="button" mat-raised-button class="discard-btn mr-3" (click)="discard()">
{{'DMP-EDITOR.ACTIONS.DISCARD' | translate}} {{'DMP-EDITOR.ACTIONS.DISCARD' | translate}}
</button> </button>
<button [disabled]="saving" *ngIf="isNew" mat-raised-button type="button" (click)="save()" class="save-btn"> <button [disabled]="saving" *ngIf="isNew" mat-raised-button type="button" (click)="save()" class="save-btn">

View File

@ -555,7 +555,12 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements
this.people = dmp.users; this.people = dmp.users;
setTimeout(() => { this.formGroup = null; }); setTimeout(() => { this.formGroup = null; });
setTimeout(() => { this.formGroup = dmpEditorModel.buildForm(); }); setTimeout(() => {
this.formGroup = dmpEditorModel.buildForm();
this.formGroup.valueChanges.pipe(takeUntil(this._destroyed))
.subscribe(x => {
this.formChanged();
});});
setTimeout(() => { document.getElementById('editor-form').scrollTop = this.scrollTop; }); setTimeout(() => { document.getElementById('editor-form').scrollTop = this.scrollTop; });
this.saving = false; this.saving = false;
this.isNew = false; this.isNew = false;
@ -1047,6 +1052,39 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements
return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty
} }
public discard() {
let messageText = "";
let confirmButtonText = "";
let cancelButtonText = "";
if (this.isNew) {
messageText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-NEW-MESSAGE');
confirmButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-NEW-CONFIRM');
cancelButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-NEW-DENY');
} else {
messageText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-EDITED-MESSAGE');
confirmButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-EDITED-CONFIRM');
cancelButtonText = this.language.instant('DATASET-EDITOR.ACTIONS.DISCARD.DISCARD-EDITED-DENY');
}
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
restoreFocus: false,
data: {
message: messageText,
confirmButton: confirmButtonText,
cancelButton: cancelButtonText,
isDeleteConfirmation: true
},
maxWidth: '40em'
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
// this.backToDmp(this.formGroup.get('dmp').value.id)
setTimeout(x => {
this.discardChanges();
});
}
});
}
public discardChanges() { public discardChanges() {
this.isDiscarded = true; this.isDiscarded = true;
this.hasChanges = false; this.hasChanges = false;

View File

@ -44,6 +44,26 @@ export class DatasetDescriptionComponent extends BaseComponent implements OnInit
} }
ngOnInit() { ngOnInit() {
this.init();
}
ngOnChanges(changes: SimpleChanges) {
this.init();
// When the form is changed set stepper index to 0.
// if (this.stepper && changes['form'] && !changes['form'].isFirstChange()) {
// this.stepper.selectedIndex = 0;
// } else if (this.stepper && changes['linkToScroll'] && changes['linkToScroll'].currentValue) {
// if (changes['linkToScroll'].currentValue.page >= 0) {
// this.stepper.selectedIndex = changes['linkToScroll'].currentValue.page;
// }
// }
}
ngAfterViewInit() {
}
init() {
this.tocentries = this.getTocEntries(); this.tocentries = this.getTocEntries();
const rules_to_append = this._enrichWithMultiplicityRules(this.tocentries); const rules_to_append = this._enrichWithMultiplicityRules(this.tocentries);
@ -64,33 +84,15 @@ export class DatasetDescriptionComponent extends BaseComponent implements OnInit
this.hiddenEntriesIds = this._findHiddenEntries(this.tocentries); this.hiddenEntriesIds = this._findHiddenEntries(this.tocentries);
this.visibilityRulesService.visibilityChange this.visibilityRulesService.visibilityChange
.pipe( .pipe(
takeUntil(this._destroyed), takeUntil(this._destroyed),
debounceTime(100) debounceTime(100)
) )
.subscribe(_=>{ .subscribe(_=>{
this.hiddenEntriesIds = this._findHiddenEntries(this.tocentries); this.hiddenEntriesIds = this._findHiddenEntries(this.tocentries);
}) })
} }
ngOnChanges(changes: SimpleChanges) {
// When the form is changed set stepper index to 0.
// if (this.stepper && changes['form'] && !changes['form'].isFirstChange()) {
// this.stepper.selectedIndex = 0;
// } else if (this.stepper && changes['linkToScroll'] && changes['linkToScroll'].currentValue) {
// if (changes['linkToScroll'].currentValue.page >= 0) {
// this.stepper.selectedIndex = changes['linkToScroll'].currentValue.page;
// }
// }
}
ngAfterViewInit() {
}
onAskedToScroll(panel: MatExpansionPanel, id?:string){ onAskedToScroll(panel: MatExpansionPanel, id?:string){
panel.open(); panel.open();
this.fieldsetFocusChange.emit(id); this.fieldsetFocusChange.emit(id);

View File

@ -1273,10 +1273,10 @@
"DELETE": "Löschen", "DELETE": "Löschen",
"UPDATE": "Update", "UPDATE": "Update",
"DISCARD": { "DISCARD": {
"DISCARD-NEW-MESSAGE": "All changes made will be discarded and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-NEW-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-NEW-CONFIRM": "Yes, discard and remove dataset.", "DISCARD-NEW-CONFIRM": "Yes, revert changes.",
"DISCARD-NEW-DENY": "No.", "DISCARD-NEW-DENY": "No.",
"DISCARD-EDITED-MESSAGE": "All unsaved changes will be reverted to their initial state and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-EDITED-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.", "DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.",
"DISCARD-EDITED-DENY": "No." "DISCARD-EDITED-DENY": "No."
}, },

View File

@ -1273,11 +1273,11 @@
"DELETE": "Delete", "DELETE": "Delete",
"UPDATE": "Update", "UPDATE": "Update",
"DISCARD": { "DISCARD": {
"DISCARD-NEW-MESSAGE": "All changes made will be discarded and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-NEW-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-NEW-CONFIRM": "Yes, discard and remove dataset.", "DISCARD-NEW-CONFIRM": "Yes, revert changes.",
"DISCARD-NEW-DENY": "No.", "DISCARD-NEW-DENY": "No.",
"DISCARD-EDITED-MESSAGE": "All unsaved changes will be reverted to their initial state and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-EDITED-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.", "DISCARD-EDITED-CONFIRM": "Yes, revert changes.",
"DISCARD-EDITED-DENY": "No." "DISCARD-EDITED-DENY": "No."
}, },
"DISABLED-EXPORT": "Please save your changes to export this Dataset" "DISABLED-EXPORT": "Please save your changes to export this Dataset"

View File

@ -1273,10 +1273,10 @@
"DELETE": "Διαγραφή", "DELETE": "Διαγραφή",
"UPDATE": "Ενημέρωση", "UPDATE": "Ενημέρωση",
"DISCARD": { "DISCARD": {
"DISCARD-NEW-MESSAGE": "All changes made will be discarded and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-NEW-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-NEW-CONFIRM": "Yes, discard and remove dataset.", "DISCARD-NEW-CONFIRM": "Yes, revert changes.",
"DISCARD-NEW-DENY": "No.", "DISCARD-NEW-DENY": "No.",
"DISCARD-EDITED-MESSAGE": "All unsaved changes will be reverted to their initial state and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-EDITED-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.", "DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.",
"DISCARD-EDITED-DENY": "No." "DISCARD-EDITED-DENY": "No."
}, },

View File

@ -1273,10 +1273,10 @@
"DELETE": "Vymazať", "DELETE": "Vymazať",
"UPDATE": "Aktualizovať", "UPDATE": "Aktualizovať",
"DISCARD": { "DISCARD": {
"DISCARD-NEW-MESSAGE": "All changes made will be discarded and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-NEW-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-NEW-CONFIRM": "Yes, discard and remove dataset.", "DISCARD-NEW-CONFIRM": "Yes, revert changes.",
"DISCARD-NEW-DENY": "No.", "DISCARD-NEW-DENY": "No.",
"DISCARD-EDITED-MESSAGE": "All unsaved changes will be reverted to their initial state and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-EDITED-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.", "DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.",
"DISCARD-EDITED-DENY": "No." "DISCARD-EDITED-DENY": "No."
}, },

View File

@ -1273,10 +1273,10 @@
"DELETE": "Obrišite", "DELETE": "Obrišite",
"UPDATE": "Ažurirajte", "UPDATE": "Ažurirajte",
"DISCARD": { "DISCARD": {
"DISCARD-NEW-MESSAGE": "All changes made will be discarded and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-NEW-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-NEW-CONFIRM": "Yes, discard and remove dataset.", "DISCARD-NEW-CONFIRM": "Yes, revert changes.",
"DISCARD-NEW-DENY": "No.", "DISCARD-NEW-DENY": "No.",
"DISCARD-EDITED-MESSAGE": "All unsaved changes will be reverted to their initial state and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-EDITED-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.", "DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.",
"DISCARD-EDITED-DENY": "No." "DISCARD-EDITED-DENY": "No."
}, },

View File

@ -1273,10 +1273,10 @@
"DELETE": "Sil", "DELETE": "Sil",
"UPDATE": "Güncelle", "UPDATE": "Güncelle",
"DISCARD": { "DISCARD": {
"DISCARD-NEW-MESSAGE": "All changes made will be discarded and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-NEW-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-NEW-CONFIRM": "Yes, discard and remove dataset.", "DISCARD-NEW-CONFIRM": "Yes, revert changes.",
"DISCARD-NEW-DENY": "No.", "DISCARD-NEW-DENY": "No.",
"DISCARD-EDITED-MESSAGE": "All unsaved changes will be reverted to their initial state and you will be redirected back to DMP Editor. Would you like to proceed?", "DISCARD-EDITED-MESSAGE": "All unsaved changes will be lost. Would you like to proceed?",
"DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.", "DISCARD-EDITED-CONFIRM": "Yes, revert changes and go back.",
"DISCARD-EDITED-DENY": "No." "DISCARD-EDITED-DENY": "No."
}, },