From 6e79b771ece557cfe5792d4152019069934542dc Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+nikonratm@users.noreply.github.com> Date: Fri, 25 Dec 2020 00:58:17 -0800 Subject: [PATCH 1/2] Refactor bulk editor to be self-contained See https://github.com/jonaswinkler/paperless-ng/pull/162#issuecomment-750425915 --- .../bulk-editor/bulk-editor.component.html | 6 +- .../bulk-editor/bulk-editor.component.ts | 182 ++++++++++++++---- .../document-list.component.html | 13 +- .../document-list/document-list.component.ts | 126 +----------- 4 files changed, 148 insertions(+), 179 deletions(-) diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html index b547b8505..11d3603b2 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html @@ -1,6 +1,6 @@
- -
diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts index 19b913af0..a5732b922 100644 --- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts +++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts @@ -126,37 +126,6 @@ export class BulkEditorComponent { this.initialDocumentTypesToggleableItems = this._documentTypesToggleableItems } - applyTags(newTagsToggleableItems: ToggleableItem[]) { - let changedTags = this.checkForChangedItems(this.initialTagsToggleableItems, newTagsToggleableItems) - if (changedTags.itemsToAdd.length > 0 || changedTags.itemsToRemove.length > 0) this.bulkSetTags(changedTags) - } - - removeAllTags() { - this.bulkSetTags(null) - } - - applyCorrespondent(newCorrespondentsToggleableItems: ToggleableItem[]) { - let changedCorrespondents = this.checkForChangedItems(this.initialCorrespondentsToggleableItems, newCorrespondentsToggleableItems) - if (changedCorrespondents.itemsToAdd.length > 0 || changedCorrespondents.itemsToRemove.length > 0) this.bulkSetCorrespondents(changedCorrespondents) - } - - removeAllCorrespondents() { - this.bulkSetCorrespondents(null) - } - - applyDocumentType(newDocumentTypesToggleableItems: ToggleableItem[]) { - let changedDocumentTypes = this.checkForChangedItems(this.initialDocumentTypesToggleableItems, newDocumentTypesToggleableItems) - if (changedDocumentTypes.itemsToAdd.length > 0 || changedDocumentTypes.itemsToRemove.length > 0) this.bulkSetDocumentTypes(changedDocumentTypes) - } - - removeAllDocumentTypes() { - this.bulkSetDocumentTypes(null) - } - - applyDelete() { - this.bulkDelete() - } - private checkForChangedItems(toggleableItemsA: ToggleableItem[], toggleableItemsB: ToggleableItem[]): ChangedItems { let itemsToAdd: any[] = [] let itemsToRemove: any[] = [] @@ -181,7 +150,13 @@ export class BulkEditorComponent { ) } - private bulkSetTags(changedTags: ChangedItems) { + setTags(newTagsToggleableItems: ToggleableItem[]) { + let changedTags: ChangedItems + if (newTagsToggleableItems) { + changedTags = this.checkForChangedItems(this.initialTagsToggleableItems, newTagsToggleableItems) + if (changedTags.itemsToAdd.length == 0 && changedTags.itemsToRemove.length == 0) return + } + let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) modal.componentInstance.title = "Confirm Tags Assignment" let action = 'set_tags' @@ -224,7 +199,13 @@ export class BulkEditorComponent { }) } - private bulkSetCorrespondents(changedCorrespondents: ChangedItems) { + setCorrespondents(newCorrespondentsToggleableItems: ToggleableItem[]) { + let changedCorrespondents: ChangedItems + if (newCorrespondentsToggleableItems) { + changedCorrespondents = this.checkForChangedItems(this.initialCorrespondentsToggleableItems, newCorrespondentsToggleableItems) + if (changedCorrespondents.itemsToAdd.length == 0 && changedCorrespondents.itemsToRemove.length == 0) return + } + let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) modal.componentInstance.title = "Confirm Correspondent Assignment" let correspondent @@ -245,7 +226,13 @@ export class BulkEditorComponent { }) } - private bulkSetDocumentTypes(changedDocumentTypes: ChangedItems) { + setDocumentTypes(newDocumentTypesToggleableItems: ToggleableItem[]) { + let changedDocumentTypes: ChangedItems + if (newDocumentTypesToggleableItems) { + changedDocumentTypes = this.checkForChangedItems(this.initialDocumentTypesToggleableItems, newDocumentTypesToggleableItems) + if (changedDocumentTypes.itemsToAdd.length == 0 && changedDocumentTypes.itemsToRemove.length == 0) return + } + let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) modal.componentInstance.title = "Confirm Document Type Assignment" let documentType @@ -266,7 +253,7 @@ export class BulkEditorComponent { }) } - private bulkDelete() { + applyDelete() { let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) modal.componentInstance.delayConfirm(5) modal.componentInstance.title = "Delete confirm"