Merge branch 'dev' into feature-bulk-edit

This commit is contained in:
jonaswinkler
2020-12-15 03:13:22 +01:00
68 changed files with 1198 additions and 489 deletions

View File

@@ -1,5 +1,5 @@
import { HttpClient, HttpParams } from '@angular/common/http'
import { Observable, of, Subject } from 'rxjs'
import { Observable } from 'rxjs'
import { map, publishReplay, refCount } from 'rxjs/operators'
import { ObjectWithId } from 'src/app/data/object-with-id'
import { Results } from 'src/app/data/results'
@@ -22,17 +22,15 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
return url
}
private getOrderingQueryParam(sortField: string, sortDirection: string) {
if (sortField && sortDirection) {
return (sortDirection == 'des' ? '-' : '') + sortField
} else if (sortField) {
return sortField
private getOrderingQueryParam(sortField: string, sortReverse: boolean) {
if (sortField) {
return (sortReverse ? '-' : '') + sortField
} else {
return null
}
}
list(page?: number, pageSize?: number, sortField?: string, sortDirection?: string, extraParams?): Observable<Results<T>> {
list(page?: number, pageSize?: number, sortField?: string, sortReverse?: boolean, extraParams?): Observable<Results<T>> {
let httpParams = new HttpParams()
if (page) {
httpParams = httpParams.set('page', page.toString())
@@ -40,7 +38,7 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
if (pageSize) {
httpParams = httpParams.set('page_size', pageSize.toString())
}
let ordering = this.getOrderingQueryParam(sortField, sortDirection)
let ordering = this.getOrderingQueryParam(sortField, sortReverse)
if (ordering) {
httpParams = httpParams.set('ordering', ordering)
}
@@ -54,9 +52,9 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
private _listAll: Observable<Results<T>>
listAll(sortField?: string, sortDirection?: string, extraParams?): Observable<Results<T>> {
listAll(sortField?: string, sortReverse?: boolean, extraParams?): Observable<Results<T>> {
if (!this._listAll) {
this._listAll = this.list(1, 100000, sortField, sortDirection, extraParams).pipe(
this._listAll = this.list(1, 100000, sortField, sortReverse, extraParams).pipe(
publishReplay(1),
refCount()
)
@@ -94,4 +92,10 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
this._listAll = null
return this.http.put<T>(this.getResourceUrl(o.id), o)
}
patch(o: T): Observable<T> {
this._listAll = null
return this.http.patch<T>(this.getResourceUrl(o.id), o)
}
}