From ee6e3c6b2af39c66e4975fdacafda8a68176cf33 Mon Sep 17 00:00:00 2001 From: Edi Cziszter Date: Mon, 17 Jan 2022 13:33:24 +0200 Subject: [PATCH] confirmation dialog for template upload with the same name --- .../reports/reports-screen.component.ts | 23 ++++++++++++++++++- apps/red-ui/src/assets/i18n/en.json | 6 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen.component.ts index 3d34001ee..1d51481ec 100644 --- a/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen.component.ts @@ -92,6 +92,28 @@ export class ReportsScreenComponent implements OnInit { } const dossierTemplateId = this._dossierTemplatesService.activeDossierTemplateId; + + if (!!this.availableTemplates.find(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'), + }); + + this._dialogService.openDialog('confirm', null, data, null, async result => { + if (result) { + await this._openConfirmationDialog(file, dossierTemplateId); + } + }); + } else { + await this._openConfirmationDialog(file, dossierTemplateId); + } + + this._fileInput.nativeElement.value = null; + } + + private async _openConfirmationDialog(file: File, dossierTemplateId: string) { if (this._isExcelFile(file)) { const data = new ConfirmationDialogInput({ title: _('confirmation-dialog.upload-report-template.title'), @@ -113,7 +135,6 @@ export class ReportsScreenComponent implements OnInit { await this._reportTemplateService.uploadTemplateForm(dossierTemplateId, false, file).toPromise(); await this._loadReportTemplates(); } - this._fileInput.nativeElement.value = null; } private async _deleteTemplate(template: IReportTemplate) { diff --git a/apps/red-ui/src/assets/i18n/en.json b/apps/red-ui/src/assets/i18n/en.json index fa8141da2..b651fd42b 100644 --- a/apps/red-ui/src/assets/i18n/en.json +++ b/apps/red-ui/src/assets/i18n/en.json @@ -454,6 +454,12 @@ "deny-text": "Cancel Upload", "question": "Please choose if {fileName} is a single or multi-file report template", "title": "Report Template Upload" + }, + "report-template-same-name": { + "confirmation-text": "Yes. Continue upload.", + "deny-text": "No. Cancel Upload", + "question": "There is already a Report Template with the name: {fileName}. Do you wish to continue?", + "title": "Report Template Upload" } }, "content": "Reason",