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 c88a44e25..bbf5494f0 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 @@ -11,7 +11,7 @@ import { DocumentService } from 'src/app/services/rest/document.service'; import { FilterableDropdownType } from 'src/app/components/common/filterable-dropdown/filterable-dropdown.component'; import { ToggleableItem, ToggleableItemState } from 'src/app/components/common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component'; -interface ChangedItems { +export interface ChangedItems { itemsToAdd: any[], itemsToRemove: any[] } @@ -42,23 +42,14 @@ export class BulkEditorComponent { setTags = new EventEmitter() @Output() - setCorrespondent = new EventEmitter() + setCorrespondents = new EventEmitter() @Output() - setDocumentType = new EventEmitter() + setDocumentTypes = new EventEmitter() @Output() delete = new EventEmitter() - @Output() - removeTags = new EventEmitter() - - @Output() - removeCorrespondents = new EventEmitter() - - @Output() - removeDocumentTypes = new EventEmitter() - tags: PaperlessTag[] correspondents: PaperlessCorrespondent[] documentTypes: PaperlessDocumentType[] @@ -151,8 +142,7 @@ export class BulkEditorComponent { applyTags(newTagsToggleableItems: ToggleableItem[]) { let changedTags = this.checkForChangedItems(this.initialTagsToggleableItems, newTagsToggleableItems) - if (changedTags.itemsToAdd.length > 0) this.setTags.emit(changedTags.itemsToAdd) - if (changedTags.itemsToRemove.length > 0) this.removeTags.emit(changedTags.itemsToRemove) + if (changedTags.itemsToAdd.length > 0 || changedTags.itemsToRemove.length > 0) this.setTags.emit(changedTags) } removeAllTags() { @@ -161,22 +151,20 @@ export class BulkEditorComponent { applyCorrespondent(newCorrespondentsToggleableItems: ToggleableItem[]) { let changedCorrespondents = this.checkForChangedItems(this.initialCorrespondentsToggleableItems, newCorrespondentsToggleableItems) - if (changedCorrespondents.itemsToAdd.length > 0) this.setCorrespondent.emit(changedCorrespondents.itemsToAdd[0]) - else if (changedCorrespondents.itemsToRemove.length > 0) this.removeCorrespondents.emit(changedCorrespondents.itemsToRemove) + if (changedCorrespondents.itemsToAdd.length > 0 || changedCorrespondents.itemsToRemove.length > 0) this.setCorrespondents.emit(changedCorrespondents) } removeAllCorrespondents() { - this.setDocumentType.emit(null) + this.setDocumentTypes.emit(null) } applyDocumentType(newDocumentTypesToggleableItems: ToggleableItem[]) { let changedDocumentTypes = this.checkForChangedItems(this.initialDocumentTypesToggleableItems, newDocumentTypesToggleableItems) - if (changedDocumentTypes.itemsToAdd.length > 0) this.setDocumentType.emit(changedDocumentTypes.itemsToAdd[0]) - else if (changedDocumentTypes.itemsToRemove.length > 0) this.removeDocumentTypes.emit(changedDocumentTypes.itemsToRemove) + if (changedDocumentTypes.itemsToAdd.length > 0 || changedDocumentTypes.itemsToRemove.length > 0) this.setDocumentTypes.emit(changedDocumentTypes) } removeAllDocumentTypes() { - this.setDocumentType.emit(null) + this.setDocumentTypes.emit(null) } checkForChangedItems(toggleableItemsA: ToggleableItem[], toggleableItemsB: ToggleableItem[]): ChangedItems { diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.html index d685e6770..816b9b3b6 100644 --- a/src-ui/src/app/components/document-list/document-list.component.html +++ b/src-ui/src/app/components/document-list/document-list.component.html @@ -87,11 +87,8 @@ (selectAll)="list.selectAll()" (selectNone)="list.selectNone()" (setTags)="bulkSetTags($event)" - (removeTags)="bulkRemoveTags($event)" - (setCorrespondent)="bulkSetCorrespondent($event)" - (removeCorrespondents)="bulkRemoveCorrespondents($event)" - (setDocumentType)="bulkSetDocumentType($event)" - (removeDocumentTypes)="bulkRemoveDocumentTypes($event)" + (setCorrespondents)="bulkSetCorrespondents($event)" + (setDocumentTypes)="bulkSetDocumentTypes($event)" (delete)="bulkDelete()"> diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index 60d763f13..db955020e 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -19,6 +19,7 @@ import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-vi import { PaperlessTag } from 'src/app/data/paperless-tag'; import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'; import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'; +import { ChangedItems } from './bulk-editor/bulk-editor.component'; @Component({ selector: 'app-document-list', @@ -156,47 +157,71 @@ export class DocumentListComponent implements OnInit { ) } - bulkSetCorrespondent(correspondent: PaperlessCorrespondent) { + bulkSetTags(changedTags: ChangedItems) { let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) - modal.componentInstance.title = "Confirm Correspondent assignment" - let messageFragment = correspondent ? `assign the correspondent ${correspondent.name} to` : `remove all correspondents from` + modal.componentInstance.title = "Confirm Tags Assignment" + let action = 'set_tags' + let tags + let messageFragment = '' + let both = changedTags && changedTags.itemsToAdd.length > 0 && changedTags.itemsToRemove.length > 0 + if (!changedTags) { + messageFragment = `remove all tags from` + } else { + if (changedTags.itemsToAdd.length > 0) { + tags = changedTags.itemsToAdd + messageFragment = `assign the tag(s) ${changedTags.itemsToAdd.map(t => t.name).join(', ')} to` + } + if (changedTags.itemsToRemove.length > 0) { + if (!both) { + // TODO: API endpoint for remove multiple tags + action = 'remove_tags' + tags = changedTags.itemsToRemove + } else { + messageFragment += ' and ' + } + messageFragment += `remove the correspondent(s) ${changedTags.itemsToRemove.map(t => t.name).join(', ')} from` + } + } modal.componentInstance.message = `This operation will ${messageFragment} all ${this.list.selected.size} selected document(s).` modal.componentInstance.btnClass = "btn-warning" modal.componentInstance.btnCaption = "Confirm" modal.componentInstance.confirmClicked.subscribe(() => { - this.executeBulkOperation('set_correspondent', {"correspondent": correspondent ? correspondent.id : null}).subscribe( + this.executeBulkOperation(action, {"tags": tags ? tags.map(t => t.id) : null}).subscribe( response => { - modal.close() + if (!both) modal.close() + else { + this.executeBulkOperation('remove_tags', {"tags": changedTags.itemsToRemove.map(t => t.id)}).subscribe( + response => { + modal.close() + }) + } } ) }) } - bulkRemoveCorrespondents(correspondents: PaperlessCorrespondent[]) { + bulkSetCorrespondents(changedCorrespondents: ChangedItems) { let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) - modal.componentInstance.title = "Confirm Correspondent Removal" - modal.componentInstance.message = `This operation will remove the correspondent(s) ${correspondents.map(t => t.name).join(', ')} from all ${this.list.selected.size} selected document(s).` - modal.componentInstance.btnClass = "btn-warning" - modal.componentInstance.btnCaption = "Confirm" - modal.componentInstance.confirmClicked.subscribe(() => { + modal.componentInstance.title = "Confirm Correspondent Assignment" + let action = 'set_correspondent' + let correspondents + let messageFragment + if (!changedCorrespondents) { + messageFragment = `remove all correspondents from` + } else if (changedCorrespondents.itemsToAdd.length > 0) { + correspondents = changedCorrespondents.itemsToAdd[0] + messageFragment = `assign the correspondent ${correspondents.name} to` + } else { // TODO: API endpoint for remove multiple correspondents - this.executeBulkOperation('remove_correspondents', {"correspondents": correspondents.map(t => t.id)}).subscribe( - response => { - modal.close() - } - ) - }) - } - - bulkSetDocumentType(documentType: PaperlessDocumentType) { - let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) - modal.componentInstance.title = "Confirm Document Type assignment" - let messageFragment = documentType ? `assign the document type ${documentType.name} to` : `remove all document types from` + action = 'remove_correspondents' + correspondents = changedCorrespondents.itemsToRemove + messageFragment = `remove the correspondent(s) ${correspondents.map(c => c.name).join(', ')} from` + } modal.componentInstance.message = `This operation will ${messageFragment} all ${this.list.selected.size} selected document(s).` modal.componentInstance.btnClass = "btn-warning" modal.componentInstance.btnCaption = "Confirm" modal.componentInstance.confirmClicked.subscribe(() => { - this.executeBulkOperation('set_document_type', {"document_type": documentType ? documentType.id : null}).subscribe( + this.executeBulkOperation(action, {"correspondents": correspondents ? correspondents.map(c => c.id) : null}).subscribe( response => { modal.close() } @@ -204,48 +229,27 @@ export class DocumentListComponent implements OnInit { }) } - bulkRemoveDocumentTypes(documentTypes: PaperlessDocumentType[]) { + bulkSetDocumentTypes(changedDocumentTypes: ChangedItems) { let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) - modal.componentInstance.title = "Confirm Document Type Removal" - modal.componentInstance.message = `This operation will remove the document type(s) ${documentTypes.map(t => t.name).join(', ')} all ${this.list.selected.size} selected document(s).` - modal.componentInstance.btnClass = "btn-warning" - modal.componentInstance.btnCaption = "Confirm" - modal.componentInstance.confirmClicked.subscribe(() => { - // TODO: API endpoint for remove multiple document types - this.executeBulkOperation('remove_document_types', {"document_types": documentTypes.map(t => t.id)}).subscribe( - response => { - modal.close() - } - ) - }) - } - - bulkSetTags(tags: PaperlessTag[]) { - let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) - modal.componentInstance.title = "Confirm Tags assignment" - let messageFragment = tags ? `assign the tag(s) ${tags.map(t => t.name).join(', ')} to` : `remove all tags from` + let action = 'set_document_type' + let documentTypes + let messageFragment + if (!changedDocumentTypes) { + messageFragment = `remove all document types from` + } else if (changedDocumentTypes.itemsToAdd.length > 0) { + documentTypes = changedDocumentTypes.itemsToAdd[0] + messageFragment = `assign the document type ${documentTypes.name} to` + } else { + // TODO: API endpoint for remove multiple doc types + action = 'remove_document_types' + documentTypes = changedDocumentTypes.itemsToRemove + messageFragment = `remove the document type(s) ${documentTypes.map(dt => dt.name).join(', ')} from` + } modal.componentInstance.message = `This operation will ${messageFragment} all ${this.list.selected.size} selected document(s).` modal.componentInstance.btnClass = "btn-warning" modal.componentInstance.btnCaption = "Confirm" modal.componentInstance.confirmClicked.subscribe(() => { - // TODO: API endpoint for set multiple tags - this.executeBulkOperation('set_tags', {"tags": tags ? tags.map(t => t.id) : null}).subscribe( - response => { - modal.close() - } - ) - }) - } - - bulkRemoveTags(tags: PaperlessTag[]) { - let modal = this.modalService.open(ConfirmDialogComponent, {backdrop: 'static'}) - modal.componentInstance.title = "Confirm Tags Removal" - modal.componentInstance.message = `This operation will remove the tags ${tags.map(t => t.name).join(', ')} from all ${this.list.selected.size} selected document(s).` - modal.componentInstance.btnClass = "btn-warning" - modal.componentInstance.btnCaption = "Confirm" - modal.componentInstance.confirmClicked.subscribe(() => { - // TODO: API endpoint for remove multiple tags - this.executeBulkOperation('remove_tags', {"tags": tags.map(t => t.id)}).subscribe( + this.executeBulkOperation(action, {"document_types": documentTypes ? documentTypes.map(dt => dt.id) : null}).subscribe( response => { modal.close() }