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