mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-04 03:27:12 -05:00 
			
		
		
		
	client support for selection data
This commit is contained in:
		
							parent
							
								
									320298e3ff
								
							
						
					
					
						commit
						802bd7fb0d
					
				@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
 | 
				
			|||||||
import { PaperlessDocument } from 'src/app/data/paperless-document';
 | 
					import { PaperlessDocument } from 'src/app/data/paperless-document';
 | 
				
			||||||
import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata';
 | 
					import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata';
 | 
				
			||||||
import { AbstractPaperlessService } from './abstract-paperless-service';
 | 
					import { AbstractPaperlessService } from './abstract-paperless-service';
 | 
				
			||||||
import { HttpClient } from '@angular/common/http';
 | 
					import { HttpClient, HttpParams } from '@angular/common/http';
 | 
				
			||||||
import { Observable } from 'rxjs';
 | 
					import { Observable } from 'rxjs';
 | 
				
			||||||
import { Results } from 'src/app/data/results';
 | 
					import { Results } from 'src/app/data/results';
 | 
				
			||||||
import { FilterRule } from 'src/app/data/filter-rule';
 | 
					import { FilterRule } from 'src/app/data/filter-rule';
 | 
				
			||||||
@ -22,6 +22,17 @@ export const DOCUMENT_SORT_FIELDS = [
 | 
				
			|||||||
  { field: 'modified', name: $localize`Modified` }
 | 
					  { field: 'modified', name: $localize`Modified` }
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface SelectionDataItem {
 | 
				
			||||||
 | 
					  id: number
 | 
				
			||||||
 | 
					  document_count: number
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface SelectionData {
 | 
				
			||||||
 | 
					  correspondents: SelectionDataItem[]
 | 
				
			||||||
 | 
					  tags: SelectionDataItem[]
 | 
				
			||||||
 | 
					  document_types: SelectionDataItem[]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Injectable({
 | 
					@Injectable({
 | 
				
			||||||
  providedIn: 'root'
 | 
					  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')
 | 
					        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),
 | 
					                When(documents__id__in=ids, then=1),
 | 
				
			||||||
                output_field=IntegerField()
 | 
					                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),
 | 
					            When(documents__id__in=ids, then=1),
 | 
				
			||||||
            output_field=IntegerField()
 | 
					            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),
 | 
					            When(documents__id__in=ids, then=1),
 | 
				
			||||||
            output_field=IntegerField()
 | 
					            output_field=IntegerField()
 | 
				
			||||||
        )))
 | 
					        )))
 | 
				
			||||||
@ -413,15 +414,15 @@ class SelectionDataView(APIView):
 | 
				
			|||||||
        r = Response({
 | 
					        r = Response({
 | 
				
			||||||
            "selected_correspondents": [{
 | 
					            "selected_correspondents": [{
 | 
				
			||||||
                "id": t.id,
 | 
					                "id": t.id,
 | 
				
			||||||
                "dcount": t.dcount
 | 
					                "document_count": t.document_count
 | 
				
			||||||
            } for t in correspondents],
 | 
					            } for t in correspondents],
 | 
				
			||||||
            "selected_tags": [{
 | 
					            "selected_tags": [{
 | 
				
			||||||
                "id": t.id,
 | 
					                "id": t.id,
 | 
				
			||||||
                "dcount": t.dcount
 | 
					                "document_count": t.document_count
 | 
				
			||||||
            } for t in tags],
 | 
					            } for t in tags],
 | 
				
			||||||
            "selected_types": [{
 | 
					            "selected_types": [{
 | 
				
			||||||
                "id": t.id,
 | 
					                "id": t.id,
 | 
				
			||||||
                "dcount": t.dcount
 | 
					                "document_count": t.document_count
 | 
				
			||||||
            } for t in types]
 | 
					            } for t in types]
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user