]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Live document counts for document filtering 2704/head
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sat, 18 Feb 2023 23:44:54 +0000 (15:44 -0800)
committershamoon <4887959+shamoon@users.noreply.github.com>
Sun, 19 Feb 2023 04:07:33 +0000 (20:07 -0800)
src-ui/src/app/components/document-list/document-list.component.html
src-ui/src/app/components/document-list/filter-editor/filter-editor.component.html
src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts
src-ui/src/app/services/document-list-view.service.ts

index aa8685da90241ec78b525e8c7c60d90f0dc50de4..081c013bb7fc38d8022fc8795ddf722c42167f2e 100644 (file)
@@ -82,7 +82,7 @@
 </app-page-header>
 
 <div class="row sticky-top pt-3 pt-sm-4 pb-2 pb-lg-4 bg-body">
-  <app-filter-editor [hidden]="isBulkEditing" [(filterRules)]="list.filterRules" [unmodifiedFilterRules]="unmodifiedFilterRules" #filterEditor></app-filter-editor>
+  <app-filter-editor [hidden]="isBulkEditing" [(filterRules)]="list.filterRules" [unmodifiedFilterRules]="unmodifiedFilterRules" [selectionData]="list.selectionData" #filterEditor></app-filter-editor>
   <app-bulk-editor [hidden]="!isBulkEditing"></app-bulk-editor>
 </div>
 
index 3b78d84459e41bc8433d52c2106d93977678e6c9..f6f4a6b326feb8ab30f9eb370e1c0c78cce280a1 100644 (file)
           <app-filterable-dropdown class="flex-fill" title="Tags" icon="tag-fill" i18n-title
             filterPlaceholder="Filter tags" i18n-filterPlaceholder
             [items]="tags"
+            [multiple]="true"
             [(selectionModel)]="tagSelectionModel"
             (selectionModelChange)="updateRules()"
-            [multiple]="true"
             (opened)="onTagsDropdownOpen()"
+            [documentCounts]="tagDocumentCounts"
             [allowSelectNone]="true"></app-filterable-dropdown>
           <app-filterable-dropdown class="flex-fill" title="Correspondent" icon="person-fill" i18n-title
             filterPlaceholder="Filter correspondents" i18n-filterPlaceholder
             [(selectionModel)]="correspondentSelectionModel"
             (selectionModelChange)="updateRules()"
             (opened)="onCorrespondentDropdownOpen()"
+            [documentCounts]="correspondentDocumentCounts"
             [allowSelectNone]="true"></app-filterable-dropdown>
           <app-filterable-dropdown class="flex-fill" title="Document type" icon="file-earmark-fill" i18n-title
             filterPlaceholder="Filter document types" i18n-filterPlaceholder
             [items]="documentTypes"
             [(selectionModel)]="documentTypeSelectionModel"
-            (opened)="onDocumentTypeDropdownOpen()"
             (selectionModelChange)="updateRules()"
+            (opened)="onDocumentTypeDropdownOpen()"
+            [documentCounts]="documentTypeDocumentCounts"
             [allowSelectNone]="true"></app-filterable-dropdown>
           <app-filterable-dropdown class="me-2 flex-fill" title="Storage path" icon="folder-fill" i18n-title
             filterPlaceholder="Filter storage paths" i18n-filterPlaceholder
             [items]="storagePaths"
             [(selectionModel)]="storagePathSelectionModel"
-            (opened)="onStoragePathDropdownOpen()"
             (selectionModelChange)="updateRules()"
+            (opened)="onStoragePathDropdownOpen()"
+            [documentCounts]="storagePathDocumentCounts"
             [allowSelectNone]="true"></app-filterable-dropdown>
         </div>
         <div class="d-flex flex-wrap">
index 44f524149bc73f69080491136546baa27505f2b4..fa5e57e8e6e0ba8cf247d384a823d9919fe892f5 100644 (file)
@@ -40,7 +40,11 @@ import {
 } from 'src/app/data/filter-rule-type'
 import { FilterableDropdownSelectionModel } from '../../common/filterable-dropdown/filterable-dropdown.component'
 import { ToggleableItemState } from '../../common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component'
-import { DocumentService } from 'src/app/services/rest/document.service'
+import {
+  DocumentService,
+  SelectionData,
+  SelectionDataItem,
+} from 'src/app/services/rest/document.service'
 import { PaperlessDocument } from 'src/app/data/paperless-document'
 import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
 import { StoragePathService } from 'src/app/services/rest/storage-path.service'
@@ -144,6 +148,11 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
   documentTypes: PaperlessDocumentType[] = []
   storagePaths: PaperlessStoragePath[] = []
 
+  tagDocumentCounts: SelectionDataItem[]
+  correspondentDocumentCounts: SelectionDataItem[]
+  documentTypeDocumentCounts: SelectionDataItem[]
+  storagePathDocumentCounts: SelectionDataItem[]
+
   _textFilter = ''
   _moreLikeId: number
   _moreLikeDoc: PaperlessDocument
@@ -617,6 +626,17 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
   @Output()
   filterRulesChange = new EventEmitter<FilterRule[]>()
 
+  @Input()
+  set selectionData(selectionData: SelectionData) {
+    this.tagDocumentCounts = selectionData?.selected_tags ?? null
+    this.documentTypeDocumentCounts =
+      selectionData?.selected_document_types ?? null
+    this.correspondentDocumentCounts =
+      selectionData?.selected_correspondents ?? null
+    this.storagePathDocumentCounts =
+      selectionData?.selected_storage_paths ?? null
+  }
+
   rulesModified: boolean = false
 
   updateRules() {
@@ -692,6 +712,8 @@ export class FilterEditorComponent implements OnInit, OnDestroy {
   }
 
   onCorrespondentDropdownOpen() {
+    console.log(this.correspondentSelectionModel)
+
     this.correspondentSelectionModel.apply()
   }
 
index 3c5dbca218eff3cafbe27f3a5ad39a8136786b38..298267fca2f820147683373fcc6c0499a59daa7d 100644 (file)
@@ -12,7 +12,11 @@ import { PaperlessSavedView } from '../data/paperless-saved-view'
 import { SETTINGS_KEYS } from '../data/paperless-uisettings'
 import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys'
 import { paramsFromViewState, paramsToViewState } from '../utils/query-params'
-import { DocumentService, DOCUMENT_SORT_FIELDS } from './rest/document.service'
+import {
+  DocumentService,
+  DOCUMENT_SORT_FIELDS,
+  SelectionData,
+} from './rest/document.service'
 import { SettingsService } from './settings.service'
 
 /**
@@ -74,6 +78,8 @@ export class DocumentListViewService {
   rangeSelectionAnchorIndex: number
   lastRangeSelectionToIndex: number
 
+  selectionData?: SelectionData
+
   currentPageSize: number = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)
 
   private listViewStates: Map<number, ListViewState> = new Map()
@@ -222,6 +228,18 @@ export class DocumentListViewService {
           this.isReloading = false
           activeListViewState.collectionSize = result.count
           activeListViewState.documents = result.results
+
+          this.documentService
+            .getSelectionData(result.results.map((d) => d.id))
+            .subscribe({
+              next: (selectionData) => {
+                this.selectionData = selectionData
+              },
+              error: () => {
+                this.selectionData = null
+              },
+            })
+
           if (updateQueryParams && !this._activeSavedViewId) {
             let base = ['/documents']
             this.router.navigate(base, {
@@ -247,6 +265,7 @@ export class DocumentListViewService {
             activeListViewState.currentPage = 1
             this.reload()
           } else {
+            this.selectionData = null
             let errorMessage
             if (
               typeof error.error !== 'string' &&