mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-20 00:56:26 +00:00
refactored document rest api
This commit is contained in:
@@ -2,8 +2,24 @@ import { Injectable } from '@angular/core';
|
||||
import { PaperlessDocument } from 'src/app/data/paperless-document';
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AuthService } from '../auth.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Results } from 'src/app/data/results';
|
||||
import { FilterRule } from 'src/app/data/filter-rule';
|
||||
|
||||
|
||||
export const DOCUMENT_SORT_FIELDS = [
|
||||
{ field: "correspondent__name", name: "Correspondent" },
|
||||
{ field: 'title', name: 'Title' },
|
||||
{ field: 'archive_serial_number', name: 'ASN' },
|
||||
{ field: 'created', name: 'Created' },
|
||||
{ field: 'added', name: 'Added' },
|
||||
{ field: 'modified', name: 'Modified' }
|
||||
]
|
||||
|
||||
export const SORT_DIRECTION_ASCENDING = "asc"
|
||||
export const SORT_DIRECTION_DESCENDING = "des"
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -14,6 +30,30 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
super(http, 'documents')
|
||||
}
|
||||
|
||||
private filterRulesToQueryParams(filterRules: FilterRule[]) {
|
||||
if (filterRules) {
|
||||
let params = {}
|
||||
for (let rule of filterRules) {
|
||||
params[rule.type.filtervar] = rule.value
|
||||
}
|
||||
return params
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private getOrderingQueryParam(sortField: string, sortDirection: string) {
|
||||
if (DOCUMENT_SORT_FIELDS.find(f => f.field == sortField)) {
|
||||
return (sortDirection == SORT_DIRECTION_DESCENDING ? '-' : '') + sortField
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
list(page?: number, pageSize?: number, sortField?: string, sortDirection?: string, filterRules?: FilterRule[]): Observable<Results<PaperlessDocument>> {
|
||||
return super.list(page, pageSize, this.getOrderingQueryParam(sortField, sortDirection), this.filterRulesToQueryParams(filterRules))
|
||||
}
|
||||
|
||||
getPreviewUrl(id: number): string {
|
||||
return this.getResourceUrl(id, 'preview') + `?auth_token=${this.auth.getToken()}`
|
||||
}
|
||||
|
Reference in New Issue
Block a user