mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-31 10:37:12 -04:00 
			
		
		
		
	Refactored delete dialog into a more generic confirm dialog
This commit is contained in:
		
							parent
							
								
									1c4d19198f
								
							
						
					
					
						commit
						5bea5e75c0
					
				| @ -16,7 +16,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | |||||||
| import { DatePipe } from '@angular/common'; | import { DatePipe } from '@angular/common'; | ||||||
| import { NotFoundComponent } from './components/not-found/not-found.component'; | import { NotFoundComponent } from './components/not-found/not-found.component'; | ||||||
| import { CorrespondentListComponent } from './components/manage/correspondent-list/correspondent-list.component'; | import { CorrespondentListComponent } from './components/manage/correspondent-list/correspondent-list.component'; | ||||||
| import { DeleteDialogComponent } from './components/common/delete-dialog/delete-dialog.component'; | import { ConfirmDialogComponent } from './components/common/confirm-dialog/confirm-dialog.component'; | ||||||
| import { CorrespondentEditDialogComponent } from './components/manage/correspondent-list/correspondent-edit-dialog/correspondent-edit-dialog.component'; | import { CorrespondentEditDialogComponent } from './components/manage/correspondent-list/correspondent-edit-dialog/correspondent-edit-dialog.component'; | ||||||
| import { TagEditDialogComponent } from './components/manage/tag-list/tag-edit-dialog/tag-edit-dialog.component'; | import { TagEditDialogComponent } from './components/manage/tag-list/tag-edit-dialog/tag-edit-dialog.component'; | ||||||
| import { DocumentTypeEditDialogComponent } from './components/manage/document-type-list/document-type-edit-dialog/document-type-edit-dialog.component'; | import { DocumentTypeEditDialogComponent } from './components/manage/document-type-list/document-type-edit-dialog/document-type-edit-dialog.component'; | ||||||
| @ -63,7 +63,7 @@ import { DocumentTitlePipe } from './pipes/document-title.pipe'; | |||||||
|     SettingsComponent, |     SettingsComponent, | ||||||
|     NotFoundComponent, |     NotFoundComponent, | ||||||
|     CorrespondentEditDialogComponent, |     CorrespondentEditDialogComponent, | ||||||
|     DeleteDialogComponent, |     ConfirmDialogComponent, | ||||||
|     TagEditDialogComponent, |     TagEditDialogComponent, | ||||||
|     DocumentTypeEditDialogComponent, |     DocumentTypeEditDialogComponent, | ||||||
|     TagComponent, |     TagComponent, | ||||||
|  | |||||||
| @ -5,10 +5,10 @@ | |||||||
|       </button> |       </button> | ||||||
|     </div> |     </div> | ||||||
|     <div class="modal-body"> |     <div class="modal-body"> | ||||||
|       <p><b>{{message}}</b></p> |       <p *ngIf="messageBold"><b>{{messageBold}}</b></p> | ||||||
|       <p *ngIf="message2">{{message2}}</p> |       <p *ngIf="message">{{message}}</p> | ||||||
|     </div> |     </div> | ||||||
|     <div class="modal-footer"> |     <div class="modal-footer"> | ||||||
|       <button type="button" class="btn btn-outline-dark" (click)="cancelClicked()">Cancel</button> |       <button type="button" class="btn btn-outline-dark" (click)="cancelClicked()">Cancel</button> | ||||||
|       <button type="button" class="btn btn-danger" (click)="deleteClicked.emit()">Delete</button> |       <button type="button" class="btn" [class]="btnClass" (click)="confirmClicked.emit()">{{btnCaption}}</button> | ||||||
|     </div> |     </div> | ||||||
| @ -1,20 +1,20 @@ | |||||||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||||||
| 
 | 
 | ||||||
| import { DeleteDialogComponent } from './delete-dialog.component'; | import { ConfirmDialogComponent } from './confirm-dialog.component'; | ||||||
| 
 | 
 | ||||||
| describe('DeleteDialogComponent', () => { | describe('ConfirmDialogComponent', () => { | ||||||
|   let component: DeleteDialogComponent; |   let component: ConfirmDialogComponent; | ||||||
|   let fixture: ComponentFixture<DeleteDialogComponent>; |   let fixture: ComponentFixture<ConfirmDialogComponent>; | ||||||
| 
 | 
 | ||||||
|   beforeEach(async () => { |   beforeEach(async () => { | ||||||
|     await TestBed.configureTestingModule({ |     await TestBed.configureTestingModule({ | ||||||
|       declarations: [ DeleteDialogComponent ] |       declarations: [ ConfirmDialogComponent ] | ||||||
|     }) |     }) | ||||||
|     .compileComponents(); |     .compileComponents(); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   beforeEach(() => { |   beforeEach(() => { | ||||||
|     fixture = TestBed.createComponent(DeleteDialogComponent); |     fixture = TestBed.createComponent(ConfirmDialogComponent); | ||||||
|     component = fixture.componentInstance; |     component = fixture.componentInstance; | ||||||
|     fixture.detectChanges(); |     fixture.detectChanges(); | ||||||
|   }); |   }); | ||||||
| @ -0,0 +1,37 @@ | |||||||
|  | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||||||
|  | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||||||
|  | 
 | ||||||
|  | @Component({ | ||||||
|  |   selector: 'app-confirm-dialog', | ||||||
|  |   templateUrl: './confirm-dialog.component.html', | ||||||
|  |   styleUrls: ['./confirm-dialog.component.scss'] | ||||||
|  | }) | ||||||
|  | export class ConfirmDialogComponent implements OnInit { | ||||||
|  | 
 | ||||||
|  |   constructor(public activeModal: NgbActiveModal) { } | ||||||
|  | 
 | ||||||
|  |   @Output() | ||||||
|  |   public confirmClicked = new EventEmitter() | ||||||
|  | 
 | ||||||
|  |   @Input() | ||||||
|  |   title = "Confirmation" | ||||||
|  | 
 | ||||||
|  |   @Input() | ||||||
|  |   messageBold | ||||||
|  | 
 | ||||||
|  |   @Input() | ||||||
|  |   message | ||||||
|  | 
 | ||||||
|  |   @Input() | ||||||
|  |   btnClass = "btn-primary" | ||||||
|  | 
 | ||||||
|  |   @Input() | ||||||
|  |   btnCaption = "Confirm" | ||||||
|  | 
 | ||||||
|  |   ngOnInit(): void { | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   cancelClicked() { | ||||||
|  |     this.activeModal.close() | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -1,31 +0,0 @@ | |||||||
| import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; |  | ||||||
| import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |  | ||||||
| 
 |  | ||||||
| @Component({ |  | ||||||
|   selector: 'app-delete-dialog', |  | ||||||
|   templateUrl: './delete-dialog.component.html', |  | ||||||
|   styleUrls: ['./delete-dialog.component.scss'] |  | ||||||
| }) |  | ||||||
| export class DeleteDialogComponent implements OnInit { |  | ||||||
| 
 |  | ||||||
|   constructor(public activeModal: NgbActiveModal) { } |  | ||||||
| 
 |  | ||||||
|   @Output() |  | ||||||
|   public deleteClicked = new EventEmitter() |  | ||||||
| 
 |  | ||||||
|   @Input() |  | ||||||
|   title = "Delete confirmation" |  | ||||||
| 
 |  | ||||||
|   @Input() |  | ||||||
|   message = "Do you really want to delete this?" |  | ||||||
| 
 |  | ||||||
|   @Input() |  | ||||||
|   message2 |  | ||||||
| 
 |  | ||||||
|   ngOnInit(): void { |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   cancelClicked() { |  | ||||||
|     this.activeModal.close() |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @ -13,7 +13,7 @@ import { CorrespondentService } from 'src/app/services/rest/correspondent.servic | |||||||
| import { DocumentTypeService } from 'src/app/services/rest/document-type.service'; | import { DocumentTypeService } from 'src/app/services/rest/document-type.service'; | ||||||
| import { DocumentService } from 'src/app/services/rest/document.service'; | import { DocumentService } from 'src/app/services/rest/document.service'; | ||||||
| import { environment } from 'src/environments/environment'; | import { environment } from 'src/environments/environment'; | ||||||
| import { DeleteDialogComponent } from '../common/delete-dialog/delete-dialog.component'; | import { ConfirmDialogComponent } from '../common/confirm-dialog/confirm-dialog.component'; | ||||||
| import { CorrespondentEditDialogComponent } from '../manage/correspondent-list/correspondent-edit-dialog/correspondent-edit-dialog.component'; | import { CorrespondentEditDialogComponent } from '../manage/correspondent-list/correspondent-edit-dialog/correspondent-edit-dialog.component'; | ||||||
| import { DocumentTypeEditDialogComponent } from '../manage/document-type-list/document-type-edit-dialog/document-type-edit-dialog.component'; | import { DocumentTypeEditDialogComponent } from '../manage/document-type-list/document-type-edit-dialog/document-type-edit-dialog.component'; | ||||||
| 
 | 
 | ||||||
| @ -155,10 +155,13 @@ export class DocumentDetailComponent implements OnInit { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   delete() { |   delete() { | ||||||
|     let modal = this.modalService.open(DeleteDialogComponent, {backdrop: 'static'}) |     let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) | ||||||
|     modal.componentInstance.message = `Do you really want to delete document '${this.document.title}'?` |     modal.componentInstance.title = "Confirm delete" | ||||||
|     modal.componentInstance.message2 = `The files for this document will be deleted permanently. This operation cannot be undone.` |     modal.componentInstance.messageBold = `Do you really want to delete document '${this.document.title}'?` | ||||||
|     modal.componentInstance.deleteClicked.subscribe(() => { |     modal.componentInstance.message = `The files for this document will be deleted permanently. This operation cannot be undone.` | ||||||
|  |     modal.componentInstance.btnClass = "btn-danger" | ||||||
|  |     modal.componentInstance.btnCaption = "Delete document" | ||||||
|  |     modal.componentInstance.confirmClicked.subscribe(() => { | ||||||
|       this.documentsService.delete(this.document).subscribe(() => { |       this.documentsService.delete(this.document).subscribe(() => { | ||||||
|         modal.close()   |         modal.close()   | ||||||
|         this.close() |         this.close() | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ import { MatchingModel, MATCHING_ALGORITHMS, MATCH_AUTO } from 'src/app/data/mat | |||||||
| import { ObjectWithId } from 'src/app/data/object-with-id'; | import { ObjectWithId } from 'src/app/data/object-with-id'; | ||||||
| import { SortableDirective, SortEvent } from 'src/app/directives/sortable.directive'; | import { SortableDirective, SortEvent } from 'src/app/directives/sortable.directive'; | ||||||
| import { AbstractPaperlessService } from 'src/app/services/rest/abstract-paperless-service'; | import { AbstractPaperlessService } from 'src/app/services/rest/abstract-paperless-service'; | ||||||
| import { DeleteDialogComponent } from '../../common/delete-dialog/delete-dialog.component'; | import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'; | ||||||
| 
 | 
 | ||||||
| @Directive() | @Directive() | ||||||
| export abstract class GenericListComponent<T extends ObjectWithId> implements OnInit { | export abstract class GenericListComponent<T extends ObjectWithId> implements OnInit { | ||||||
| @ -88,10 +88,13 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   openDeleteDialog(object: T) { |   openDeleteDialog(object: T) { | ||||||
|     var activeModal = this.modalService.open(DeleteDialogComponent, {backdrop: 'static'}) |     var activeModal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) | ||||||
|     activeModal.componentInstance.message = `Do you really want to delete ${this.getObjectName(object)}?` |     activeModal.componentInstance.title = "Confirm delete" | ||||||
|     activeModal.componentInstance.message2 = "Associated documents will not be deleted." |     activeModal.componentInstance.messageBold = `Do you really want to delete ${this.getObjectName(object)}?` | ||||||
|     activeModal.componentInstance.deleteClicked.subscribe(() => { |     activeModal.componentInstance.message = "Associated documents will not be deleted." | ||||||
|  |     activeModal.componentInstance.btnClass = "btn-danger" | ||||||
|  |     activeModal.componentInstance.btnCaption = "Delete" | ||||||
|  |     activeModal.componentInstance.confirmPressed.subscribe(() => { | ||||||
|       this.service.delete(object).subscribe(_ => { |       this.service.delete(object).subscribe(_ => { | ||||||
|         activeModal.close() |         activeModal.close() | ||||||
|         this.reloadData() |         this.reloadData() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user