From c2872c7f44cb36a54a7210022a7cf161cab1ef0a Mon Sep 17 00:00:00 2001 From: "Darryl L. Pierce" Date: Sat, 25 Jul 2020 09:40:36 -0400 Subject: [PATCH] Added confirmation dialog when selecting to delete physical files [#285] --- .../consolidate-library.component.html | 1 + .../consolidate-library.component.spec.ts | 26 +++++++++++++++++++ .../consolidate-library.component.ts | 21 +++++++++++++++ .../src/assets/i18n/en/library.json | 4 +++ .../src/assets/i18n/es/library.json | 4 +++ .../src/assets/i18n/fr/library.json | 4 +++ .../src/assets/i18n/pt/library.json | 4 +++ 7 files changed, 64 insertions(+) diff --git a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html index dfe021124..21145b75b 100644 --- a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html +++ b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.html @@ -3,6 +3,7 @@
diff --git a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts index 50a15cbc9..ab6f0c3ad 100644 --- a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts +++ b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.spec.ts @@ -231,4 +231,30 @@ describe('ConsolidateLibraryComponent', () => { }); }); }); + + describe('choosing to delete physical files', () => { + beforeEach(() => { + spyOn(confirmationService, 'confirm').and.callFake( + (confirm: Confirmation) => confirm.reject() + ); + component.showDeleteFilesWarning(true); + }); + + it('confirms with the user', () => { + expect(confirmationService.confirm).toHaveBeenCalled(); + }); + }); + + describe('choosing not to delete physical files', () => { + beforeEach(() => { + spyOn(confirmationService, 'confirm').and.callFake( + (confirm: Confirmation) => confirm.reject() + ); + component.showDeleteFilesWarning(false); + }); + + it('confirms with the user', () => { + expect(confirmationService.confirm).not.toHaveBeenCalled(); + }); + }); }); diff --git a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts index 99b824fb9..f5720bbe2 100644 --- a/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts +++ b/comixed-frontend/src/app/library/components/consolidate-library/consolidate-library.component.ts @@ -73,6 +73,12 @@ export class ConsolidateLibraryComponent implements OnInit, OnDestroy { this.consolidatingSubscription.unsubscribe(); } + set deletePhysicalFiles(deletePhysicalFiles: boolean) { + this.consolidationForm.controls['deletePhysicalFiles'].setValue( + deletePhysicalFiles + ); + } + consolidateLibrary() { this.confirmationService.confirm({ header: this.translateService.instant( @@ -115,4 +121,19 @@ export class ConsolidateLibraryComponent implements OnInit, OnDestroy { } }); } + + showDeleteFilesWarning(checked: boolean) { + if (checked) { + this.confirmationService.confirm({ + icon: 'fa fa-fw fas fa-skull-crossbones', + header: this.translateService.instant( + 'consolidate-library.delete-files-warning.header' + ), + message: this.translateService.instant( + 'consolidate-library.delete-files-warning.message' + ), + reject: () => (this.deletePhysicalFiles = false) + }); + } + } } diff --git a/comixed-frontend/src/assets/i18n/en/library.json b/comixed-frontend/src/assets/i18n/en/library.json index 81bcb9609..1edce2b66 100644 --- a/comixed-frontend/src/assets/i18n/en/library.json +++ b/comixed-frontend/src/assets/i18n/en/library.json @@ -428,6 +428,10 @@ "button": { "start": "Start Consolidation" }, + "delete-files-warning": { + "header": "Delete Files Warning", + "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" + }, "confirm": { "header": "Consolidate Library", "message": "Are you sure you want to consolidate the library and {deletePhysicalFiles, select, true{delete} other{not delete}} the comic files?" diff --git a/comixed-frontend/src/assets/i18n/es/library.json b/comixed-frontend/src/assets/i18n/es/library.json index 6f31df38e..12a8db447 100644 --- a/comixed-frontend/src/assets/i18n/es/library.json +++ b/comixed-frontend/src/assets/i18n/es/library.json @@ -428,6 +428,10 @@ "button": { "start": "Comenzar la consolidación" }, + "delete-files-warning": { + "header": "Delete Files Warning", + "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" + }, "confirm": { "header": "Consolidar la biblioteca", "message": "¿Seguro que quieres consolidar la biblitoteca y {deletePhysicalFiles, select, true{borrar} other{no borrar}} los archivos físicos de cómics?" diff --git a/comixed-frontend/src/assets/i18n/fr/library.json b/comixed-frontend/src/assets/i18n/fr/library.json index c5132981b..1cc18d211 100644 --- a/comixed-frontend/src/assets/i18n/fr/library.json +++ b/comixed-frontend/src/assets/i18n/fr/library.json @@ -428,6 +428,10 @@ "button": { "start": "Commencer la consolidation" }, + "delete-files-warning": { + "header": "Delete Files Warning", + "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" + }, "confirm": { "header": "Consolider la bibliothèque", "message": "Êtes-vous sûr de vouloir consolider la bibliothèque et {deletePhysicalFiles, select, true{supprimer} other{ne pas supprimer}} les fichiers de bande dessinée?" diff --git a/comixed-frontend/src/assets/i18n/pt/library.json b/comixed-frontend/src/assets/i18n/pt/library.json index 959e5b5b2..55a87b879 100644 --- a/comixed-frontend/src/assets/i18n/pt/library.json +++ b/comixed-frontend/src/assets/i18n/pt/library.json @@ -428,6 +428,10 @@ "button": { "start": "Start Consolidation" }, + "delete-files-warning": { + "header": "Delete Files Warning", + "message": "WARNING! Deleting the physical files can NOT be undone. Are you sure you want to delete the physical files?" + }, "confirm": { "header": "Consolidate Library", "message": "Are you sure you want to consolidate the library and {deletePhysicalFiles, select, true{delete} other{not delete}} the comic files?"