From fd6bfd02ce92f8a060c4b2239dd943a4e0a60994 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+nikonratm@users.noreply.github.com> Date: Sat, 19 Dec 2020 21:45:53 -0800 Subject: [PATCH] SelectableItem dropdowns refactoring --- .../bulk-editor/bulk-editor.component.ts | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) 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 54ecb6d0a..7ba134e15 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 @@ -48,9 +48,9 @@ export class BulkEditorComponent { correspondents: PaperlessCorrespondent[] documentTypes: PaperlessDocumentType[] - private _initialTagsSelectableItems: SelectableItem[] - private _initialCorrespondentsSelectableItems: SelectableItem[] - private _initialDocumentTypesSelectableItems: SelectableItem[] + private initiallySelectedTagsSelectableItems: SelectableItem[] + private initiallySelectedCorrespondentsSelectableItems: SelectableItem[] + private initiallySelectedDocumentTypesSelectableItems: SelectableItem[] dropdownTypes = FilterableDropdownType @@ -109,36 +109,33 @@ export class BulkEditorComponent { } tagsDropdownOpen() { - this._initialTagsSelectableItems = this.tagsSelectableItems + this.initiallySelectedTagsSelectableItems = this.tagsSelectableItems.filter(tsi => tsi.state == SelectableItemState.Selected) } correspondentsDropdownOpen() { - this._initialCorrespondentsSelectableItems = this.correspondentsSelectableItems + this.initiallySelectedCorrespondentsSelectableItems = this.correspondentsSelectableItems.filter(csi => csi.state == SelectableItemState.Selected) } documentTypesDropdownOpen() { - this._initialDocumentTypesSelectableItems = this.documentTypesSelectableItems + this.initiallySelectedDocumentTypesSelectableItems = this.documentTypesSelectableItems.filter(dtsi => dtsi.state == SelectableItemState.Selected) } applyTags(selectedTags: PaperlessTag[]) { - let initiallySelectedSelectableTags = this._initialTagsSelectableItems.filter(tsi => tsi.state == SelectableItemState.Selected) - let unchanged = this.equateItemsToSelectableItems(selectedTags, initiallySelectedSelectableTags) + let unchanged = this.equateItemsToSelectableItems(selectedTags, this.initiallySelectedTagsSelectableItems) if (!unchanged) this.setTags.emit(selectedTags) - this._initialTagsSelectableItems = null + this.initiallySelectedTagsSelectableItems = null } applyCorrespondent(selectedCorrespondents: PaperlessCorrespondent[]) { - let initiallySelectedSelectableCorrespondents = this._initialCorrespondentsSelectableItems.filter(csi => csi.state == SelectableItemState.Selected) - let unchanged = this.equateItemsToSelectableItems(selectedCorrespondents, initiallySelectedSelectableCorrespondents) + let unchanged = this.equateItemsToSelectableItems(selectedCorrespondents, this.initiallySelectedCorrespondentsSelectableItems) if (!unchanged) this.setCorrespondent.emit(selectedCorrespondents?.length > 0 ? selectedCorrespondents.shift() : null) - this._initialCorrespondentsSelectableItems = null + this.initiallySelectedCorrespondentsSelectableItems = null } applyDocumentType(selectedDocumentTypes: PaperlessDocumentType[]) { - let initiallySelectedSelectableDocumentTypes = this._initialDocumentTypesSelectableItems.filter(dtsi => dtsi.state == SelectableItemState.Selected) - let unchanged = this.equateItemsToSelectableItems(selectedDocumentTypes, initiallySelectedSelectableDocumentTypes) + let unchanged = this.equateItemsToSelectableItems(selectedDocumentTypes, this.initiallySelectedDocumentTypesSelectableItems) if (!unchanged) this.setDocumentType.emit(selectedDocumentTypes.length > 0 ? selectedDocumentTypes.shift() : null) - this._initialDocumentTypesSelectableItems = null + this.initiallySelectedDocumentTypesSelectableItems = null } equateItemsToSelectableItems(items: ObjectWithId[], selectableItems: SelectableItem[]): boolean {