Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

client support for selection data

jonaswinkler802bd7fb0dc8
diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts
index ff17e972e..9caaecdb2 100644
--- a/src-ui/src/app/services/rest/document.service.ts
+++ b/src-ui/src/app/services/rest/document.service.ts
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { PaperlessDocument } from 'src/app/data/paperless-document';
import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata';
import { AbstractPaperlessService } from './abstract-paperless-service';
-import { HttpClient } from '@angular/common/http';
+import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Results } from 'src/app/data/results';
import { FilterRule } from 'src/app/data/filter-rule';
@@ -22,6 +22,17 @@ export const DOCUMENT_SORT_FIELDS = [
{ field: 'modified', name: $localize`Modified` }
]
+export interface SelectionDataItem {
+ id: number
+ document_count: number
+}
+
+export interface SelectionData {
+ correspondents: SelectionDataItem[]
+ tags: SelectionDataItem[]
+ document_types: SelectionDataItem[]
+}
+
@Injectable({
providedIn: 'root'
})
@@ -114,4 +125,9 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
})
}
+ selectionData(ids: number[]): Observable<SelectionData> {
+ console.log(ids)
+ return this.http.post<SelectionData>(this.getResourceUrl(null, 'selection_data'), {"documents": ids})
+ }
+
}
diff --git a/src/documents/views.py b/src/documents/views.py
index d4d7b7123..a50896057 100755
--- a/src/documents/views.py
+++ b/src/documents/views.py
@@ -395,17 +395,18 @@ class SelectionDataView(APIView):
ids = serializer.validated_data.get('documents')
- correspondents = Correspondent.objects.annotate(dcount=Count(Case(
- When(documents__id__in=ids, then=1),
- output_field=IntegerField()
- )))
+ correspondents = Correspondent.objects.annotate(
+ document_count=Count(Case(
+ When(documents__id__in=ids, then=1),
+ output_field=IntegerField()
+ )))
- tags = Tag.objects.annotate(dcount=Count(Case(
+ tags = Tag.objects.annotate(document_count=Count(Case(
When(documents__id__in=ids, then=1),
output_field=IntegerField()
)))
- types = DocumentType.objects.annotate(dcount=Count(Case(
+ types = DocumentType.objects.annotate(document_count=Count(Case(
When(documents__id__in=ids, then=1),
output_field=IntegerField()
)))
@@ -413,15 +414,15 @@ class SelectionDataView(APIView):
r = Response({
"selected_correspondents": [{
"id": t.id,
- "dcount": t.dcount
+ "document_count": t.document_count
} for t in correspondents],
"selected_tags": [{
"id": t.id,
- "dcount": t.dcount
+ "document_count": t.document_count
} for t in tags],
"selected_types": [{
"id": t.id,
- "dcount": t.dcount
+ "document_count": t.document_count
} for t in types]
})