RED-5201 -> Confusing dialogs when uploading a multi-file report template for which a single-file version already exists

This commit is contained in:
Valentin Mihai 2022-09-14 20:00:28 +03:00
parent 323c6ac28d
commit a11a3f8d60

View File

@ -78,25 +78,25 @@ export class ReportsScreenComponent implements OnInit {
return;
}
if (this.availableTemplates$.value.some(template => template.fileName === file.name)) {
const data = new ConfirmationDialogInput({
title: _('confirmation-dialog.report-template-same-name.title'),
question: _('confirmation-dialog.report-template-same-name.question'),
confirmationText: _('confirmation-dialog.report-template-same-name.confirmation-text'),
denyText: _('confirmation-dialog.report-template-same-name.deny-text'),
translateParams: {
fileName: file.name,
},
});
this._dialogService.openDialog('confirm', null, data, null, result => {
if (result) {
this._openConfirmationDialog(file);
const data = new ConfirmationDialogInput({
title: _('confirmation-dialog.upload-report-template.title'),
question: _('confirmation-dialog.upload-report-template.question'),
confirmationText: _('confirmation-dialog.upload-report-template.confirmation-text'),
denyText: _('confirmation-dialog.upload-report-template.deny-text'),
alternativeConfirmationText: _('confirmation-dialog.upload-report-template.alternate-confirmation-text'),
translateParams: {
fileName: file.name,
},
});
this._dialogService.openDialog('confirm', null, data, null, async result => {
if (result) {
if (this.availableTemplates$.value.some(template => template.fileName === file.name)) {
await this._openOverwriteConfirmationDialog(file, result > 1);
} else {
await this._uploadTemplateForm(file, result > 1);
}
});
} else {
this._openConfirmationDialog(file);
}
}
});
this._fileInput.nativeElement.value = null;
}
@ -111,27 +111,31 @@ export class ReportsScreenComponent implements OnInit {
: placeholdersDescriptionsTranslations[type];
}
private _openConfirmationDialog(file: File): void {
private async _openOverwriteConfirmationDialog(file: File, multiFileReport: boolean): Promise<void> {
const data = new ConfirmationDialogInput({
title: _('confirmation-dialog.upload-report-template.title'),
question: _('confirmation-dialog.upload-report-template.question'),
confirmationText: _('confirmation-dialog.upload-report-template.confirmation-text'),
denyText: _('confirmation-dialog.upload-report-template.deny-text'),
alternativeConfirmationText: _('confirmation-dialog.upload-report-template.alternate-confirmation-text'),
title: _('confirmation-dialog.report-template-same-name.title'),
question: _('confirmation-dialog.report-template-same-name.question'),
confirmationText: _('confirmation-dialog.report-template-same-name.confirmation-text'),
denyText: _('confirmation-dialog.report-template-same-name.deny-text'),
translateParams: {
fileName: file.name,
},
});
this._dialogService.openDialog('confirm', null, data, null, async result => {
if (result) {
this._loadingService.start();
await firstValueFrom(this._reportTemplateService.uploadTemplateForm(this.#dossierTemplateId, result > 1, file));
await this._loadReportTemplates();
this._loadingService.stop();
await this._uploadTemplateForm(file, multiFileReport);
}
});
}
private async _uploadTemplateForm(file: File, multiFileReport: boolean): Promise<void> {
this._loadingService.start();
await firstValueFrom(this._reportTemplateService.uploadTemplateForm(this.#dossierTemplateId, multiFileReport, file));
await this._loadReportTemplates();
this._loadingService.stop();
}
private async _deleteTemplate(template: IReportTemplate) {
await firstValueFrom(this._reportTemplateService.delete(template.dossierTemplateId, template.templateId));
await this._loadReportTemplates();