Skip to content

Commit

Permalink
Added confirmation dialog when selecting to delete physical files [#285]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce authored and BRUCELLA2 committed Jul 26, 2020
1 parent d971293 commit c2872c7
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 0 deletions.
Expand Up @@ -3,6 +3,7 @@
<div class="ui-g-12">
<p-checkbox id="delete-physical-files"
[binary]="true"
(onChange)="showDeleteFilesWarning($event)"
formControlName="deletePhysicalFiles"></p-checkbox>
<label for="delete-physical-files">{{"consolidate-library.label.delete-physical-files"|translate}}</label>
</div>
Expand Down
Expand Up @@ -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();
});
});
});
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
});
}
}
}
4 changes: 4 additions & 0 deletions comixed-frontend/src/assets/i18n/en/library.json
Expand Up @@ -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?"
Expand Down
4 changes: 4 additions & 0 deletions comixed-frontend/src/assets/i18n/es/library.json
Expand Up @@ -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?"
Expand Down
4 changes: 4 additions & 0 deletions comixed-frontend/src/assets/i18n/fr/library.json
Expand Up @@ -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?"
Expand Down
4 changes: 4 additions & 0 deletions comixed-frontend/src/assets/i18n/pt/library.json
Expand Up @@ -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?"
Expand Down

0 comments on commit c2872c7

Please sign in to comment.