mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	client support for selection data
This commit is contained in:
		@@ -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})
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -395,17 +395,18 @@ class SelectionDataView(APIView):
 | 
			
		||||
 | 
			
		||||
        ids = serializer.validated_data.get('documents')
 | 
			
		||||
 | 
			
		||||
        correspondents = Correspondent.objects.annotate(dcount=Count(Case(
 | 
			
		||||
        correspondents = Correspondent.objects.annotate(
 | 
			
		||||
            document_count=Count(Case(
 | 
			
		||||
                When(documents__id__in=ids, then=1),
 | 
			
		||||
                output_field=IntegerField()
 | 
			
		||||
            )))
 | 
			
		||||
 | 
			
		||||
        tags = Tag.objects.annotate(document_count=Count(Case(
 | 
			
		||||
            When(documents__id__in=ids, then=1),
 | 
			
		||||
            output_field=IntegerField()
 | 
			
		||||
        )))
 | 
			
		||||
 | 
			
		||||
        tags = Tag.objects.annotate(dcount=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]
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user