From e6961d52875e14cf1231e32016f95ba8789af18b Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+nikonratm@users.noreply.github.com> Date: Thu, 14 Jan 2021 14:10:23 -0800 Subject: [PATCH] Allow range selection with shift --- .../document-list/document-list.component.ts | 4 +-- .../services/document-list-view.service.ts | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) 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 1243e6e8a..a3ec2d664 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 @@ -160,8 +160,8 @@ export class DocumentListComponent implements OnInit { this.filterRulesModified = modified } - toggleSelected(document: PaperlessDocument, event: Event): void { - this.list.toggleSelected(document) + toggleSelected(document: PaperlessDocument, event: MouseEvent): void { + this.list.toggleSelected(document, event.shiftKey) } clickTag(tagID: number) { diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts index a852eda55..407c81572 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -27,6 +27,7 @@ export class DocumentListViewService { currentPage = 1 currentPageSize: number = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE) collectionSize: number + lastSelectedDocumentIndex: number /** * This is the current config for the document list. The service will always remember the last settings used for the document list. @@ -108,6 +109,7 @@ export class DocumentListViewService { if (onFinish) { onFinish() } + this.lastSelectedDocumentIndex = null this.isReloading = false }, error => { @@ -218,6 +220,7 @@ export class DocumentListViewService { selectNone() { this.selected.clear() + this.lastSelectedDocumentIndex = null } reduceSelectionToFilter() { @@ -249,15 +252,25 @@ export class DocumentListViewService { return this.selected.has(d.id) } - setSelected(d: PaperlessDocument, value: boolean) { - if (value) { - this.selected.add(d.id) - } else if (!value) { - this.selected.delete(d.id) - } - toggleSelected(d: PaperlessDocument): void { - if (this.selected.has(d.id)) this.selected.delete(d.id) + toggleSelected(d: PaperlessDocument, includeRange: boolean): void { + if (this.selected.has(d.id) && !includeRange) this.selected.delete(d.id) else this.selected.add(d.id) + + if (includeRange && this.lastSelectedDocumentIndex !== null) { + const toIndex = this.documentIndexInCurrentView(d.id) + console.log('select from', this.lastSelectedDocumentIndex, 'to', toIndex); + this.documents.slice(Math.min(this.lastSelectedDocumentIndex, toIndex), Math.max(this.lastSelectedDocumentIndex, toIndex)).forEach(d => { + this.selected.add(d.id) + }) + } + + if (!includeRange || (includeRange && this.lastSelectedDocumentIndex == null)) { + this.lastSelectedDocumentIndex = this.documentIndexInCurrentView(d.id) + } + } + + documentIndexInCurrentView(documentID: number): number { + return this.documents.map(d => d.id).indexOf(documentID) } constructor(private documentService: DocumentService, private settings: SettingsService, private router: Router) {