mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
@@ -1,14 +1,20 @@
|
||||
import { ObjectWithId } from 'src/app/data/object-with-id'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
|
||||
export abstract class AbstractNameFilterService<T extends ObjectWithId> extends AbstractPaperlessService<T> {
|
||||
|
||||
listFiltered(page?: number, pageSize?: number, sortField?: string, sortReverse?: boolean, nameFilter?: string) {
|
||||
export abstract class AbstractNameFilterService<
|
||||
T extends ObjectWithId
|
||||
> extends AbstractPaperlessService<T> {
|
||||
listFiltered(
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
sortField?: string,
|
||||
sortReverse?: boolean,
|
||||
nameFilter?: string
|
||||
) {
|
||||
let params = {}
|
||||
if (nameFilter) {
|
||||
params = {'name__icontains': nameFilter}
|
||||
params = { name__icontains: nameFilter }
|
||||
}
|
||||
return this.list(page, pageSize, sortField, sortReverse, params)
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service';
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
|
||||
describe('AbstractPaperlessService', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new AbstractPaperlessService()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(new AbstractPaperlessService()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -6,10 +6,9 @@ import { Results } from 'src/app/data/results'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
||||
|
||||
protected baseUrl: string = environment.apiBaseUrl
|
||||
|
||||
constructor(protected http: HttpClient, private resourceName: string) { }
|
||||
constructor(protected http: HttpClient, private resourceName: string) {}
|
||||
|
||||
protected getResourceUrl(id?: number, action?: string): string {
|
||||
let url = `${this.baseUrl}${this.resourceName}/`
|
||||
@@ -30,7 +29,13 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
||||
}
|
||||
}
|
||||
|
||||
list(page?: number, pageSize?: number, sortField?: string, sortReverse?: boolean, 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())
|
||||
@@ -47,30 +52,39 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
||||
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
|
||||
}
|
||||
}
|
||||
return this.http.get<Results<T>>(this.getResourceUrl(), {params: httpParams})
|
||||
return this.http.get<Results<T>>(this.getResourceUrl(), {
|
||||
params: httpParams,
|
||||
})
|
||||
}
|
||||
|
||||
private _listAll: Observable<Results<T>>
|
||||
|
||||
listAll(sortField?: string, sortReverse?: boolean, extraParams?): Observable<Results<T>> {
|
||||
listAll(
|
||||
sortField?: string,
|
||||
sortReverse?: boolean,
|
||||
extraParams?
|
||||
): Observable<Results<T>> {
|
||||
if (!this._listAll) {
|
||||
this._listAll = this.list(1, 100000, sortField, sortReverse, extraParams).pipe(
|
||||
publishReplay(1),
|
||||
refCount()
|
||||
)
|
||||
this._listAll = this.list(
|
||||
1,
|
||||
100000,
|
||||
sortField,
|
||||
sortReverse,
|
||||
extraParams
|
||||
).pipe(publishReplay(1), refCount())
|
||||
}
|
||||
return this._listAll
|
||||
}
|
||||
|
||||
getCached(id: number): Observable<T> {
|
||||
return this.listAll().pipe(
|
||||
map(list => list.results.find(o => o.id == id))
|
||||
map((list) => list.results.find((o) => o.id == id))
|
||||
)
|
||||
}
|
||||
|
||||
getCachedMany(ids: number[]): Observable<T[]> {
|
||||
return this.listAll().pipe(
|
||||
map(list => ids.map(id => list.results.find(o => o.id == id)))
|
||||
map((list) => ids.map((id) => list.results.find((o) => o.id == id)))
|
||||
)
|
||||
}
|
||||
|
||||
@@ -101,5 +115,4 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
||||
this.clearCache()
|
||||
return this.http.patch<T>(this.getResourceUrl(o.id), o)
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { CorrespondentService } from './correspondent.service';
|
||||
import { CorrespondentService } from './correspondent.service'
|
||||
|
||||
describe('CorrespondentService', () => {
|
||||
let service: CorrespondentService;
|
||||
let service: CorrespondentService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(CorrespondentService);
|
||||
});
|
||||
TestBed.configureTestingModule({})
|
||||
service = TestBed.inject(CorrespondentService)
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(service).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,15 +1,13 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent';
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service';
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CorrespondentService extends AbstractNameFilterService<PaperlessCorrespondent> {
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'correspondents')
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { DocumentTypeService } from './document-type.service';
|
||||
import { DocumentTypeService } from './document-type.service'
|
||||
|
||||
describe('DocumentTypeService', () => {
|
||||
let service: DocumentTypeService;
|
||||
let service: DocumentTypeService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DocumentTypeService);
|
||||
});
|
||||
TestBed.configureTestingModule({})
|
||||
service = TestBed.inject(DocumentTypeService)
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(service).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,13 +1,12 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type';
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service';
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DocumentTypeService extends AbstractNameFilterService<PaperlessDocumentType> {
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'document_types')
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { DocumentService } from './document.service';
|
||||
import { DocumentService } from './document.service'
|
||||
|
||||
describe('DocumentService', () => {
|
||||
let service: DocumentService;
|
||||
let service: DocumentService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DocumentService);
|
||||
});
|
||||
TestBed.configureTestingModule({})
|
||||
service = TestBed.inject(DocumentService)
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(service).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,31 +1,34 @@
|
||||
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, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Results } from 'src/app/data/results';
|
||||
import { FilterRule } from 'src/app/data/filter-rule';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { CorrespondentService } from './correspondent.service';
|
||||
import { DocumentTypeService } from './document-type.service';
|
||||
import { TagService } from './tag.service';
|
||||
import { FILTER_RULE_TYPES } from 'src/app/data/filter-rule-type';
|
||||
import { PaperlessDocumentSuggestions } from 'src/app/data/paperless-document-suggestions';
|
||||
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, HttpParams } from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
import { Results } from 'src/app/data/results'
|
||||
import { FilterRule } from 'src/app/data/filter-rule'
|
||||
import { map } from 'rxjs/operators'
|
||||
import { CorrespondentService } from './correspondent.service'
|
||||
import { DocumentTypeService } from './document-type.service'
|
||||
import { TagService } from './tag.service'
|
||||
import { FILTER_RULE_TYPES } from 'src/app/data/filter-rule-type'
|
||||
import { PaperlessDocumentSuggestions } from 'src/app/data/paperless-document-suggestions'
|
||||
|
||||
export const DOCUMENT_SORT_FIELDS = [
|
||||
{ field: 'archive_serial_number', name: $localize`ASN` },
|
||||
{ field: "correspondent__name", name: $localize`Correspondent` },
|
||||
{ field: 'correspondent__name', name: $localize`Correspondent` },
|
||||
{ field: 'title', name: $localize`Title` },
|
||||
{ field: "document_type__name", name: $localize`Document type` },
|
||||
{ field: 'document_type__name', name: $localize`Document type` },
|
||||
{ field: 'created', name: $localize`Created` },
|
||||
{ field: 'added', name: $localize`Added` },
|
||||
{ field: 'modified', name: $localize`Modified` }
|
||||
{ field: 'modified', name: $localize`Modified` },
|
||||
]
|
||||
|
||||
export const DOCUMENT_SORT_FIELDS_FULLTEXT = [
|
||||
...DOCUMENT_SORT_FIELDS,
|
||||
{ field: 'score', name: $localize`:Score is a value returned by the full text search engine and specifies how well a result matches the given query:Search score` }
|
||||
{
|
||||
field: 'score',
|
||||
name: $localize`:Score is a value returned by the full text search engine and specifies how well a result matches the given query:Search score`,
|
||||
},
|
||||
]
|
||||
|
||||
export interface SelectionDataItem {
|
||||
@@ -40,13 +43,17 @@ export interface SelectionData {
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DocumentService extends AbstractPaperlessService<PaperlessDocument> {
|
||||
|
||||
private _searchQuery: string
|
||||
|
||||
constructor(http: HttpClient, private correspondentService: CorrespondentService, private documentTypeService: DocumentTypeService, private tagService: TagService) {
|
||||
constructor(
|
||||
http: HttpClient,
|
||||
private correspondentService: CorrespondentService,
|
||||
private documentTypeService: DocumentTypeService,
|
||||
private tagService: TagService
|
||||
) {
|
||||
super(http, 'documents')
|
||||
}
|
||||
|
||||
@@ -54,9 +61,11 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
if (filterRules) {
|
||||
let params = {}
|
||||
for (let rule of filterRules) {
|
||||
let ruleType = FILTER_RULE_TYPES.find(t => t.id == rule.rule_type)
|
||||
let ruleType = FILTER_RULE_TYPES.find((t) => t.id == rule.rule_type)
|
||||
if (ruleType.multi) {
|
||||
params[ruleType.filtervar] = params[ruleType.filtervar] ? params[ruleType.filtervar] + "," + rule.value : rule.value
|
||||
params[ruleType.filtervar] = params[ruleType.filtervar]
|
||||
? params[ruleType.filtervar] + ',' + rule.value
|
||||
: rule.value
|
||||
} else if (ruleType.isnull_filtervar && rule.value == null) {
|
||||
params[ruleType.isnull_filtervar] = true
|
||||
} else {
|
||||
@@ -71,7 +80,9 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
|
||||
addObservablesToDocument(doc: PaperlessDocument) {
|
||||
if (doc.correspondent) {
|
||||
doc.correspondent$ = this.correspondentService.getCached(doc.correspondent)
|
||||
doc.correspondent$ = this.correspondentService.getCached(
|
||||
doc.correspondent
|
||||
)
|
||||
}
|
||||
if (doc.document_type) {
|
||||
doc.document_type$ = this.documentTypeService.getCached(doc.document_type)
|
||||
@@ -82,26 +93,39 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
return doc
|
||||
}
|
||||
|
||||
listFiltered(page?: number, pageSize?: number, sortField?: string, sortReverse?: boolean, filterRules?: FilterRule[], extraParams = {}): Observable<Results<PaperlessDocument>> {
|
||||
return this.list(page, pageSize, sortField, sortReverse, Object.assign(extraParams, this.filterRulesToQueryParams(filterRules))).pipe(
|
||||
map(results => {
|
||||
results.results.forEach(doc => this.addObservablesToDocument(doc))
|
||||
listFiltered(
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
sortField?: string,
|
||||
sortReverse?: boolean,
|
||||
filterRules?: FilterRule[],
|
||||
extraParams = {}
|
||||
): Observable<Results<PaperlessDocument>> {
|
||||
return this.list(
|
||||
page,
|
||||
pageSize,
|
||||
sortField,
|
||||
sortReverse,
|
||||
Object.assign(extraParams, this.filterRulesToQueryParams(filterRules))
|
||||
).pipe(
|
||||
map((results) => {
|
||||
results.results.forEach((doc) => this.addObservablesToDocument(doc))
|
||||
return results
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
listAllFilteredIds(filterRules?: FilterRule[]): Observable<number[]> {
|
||||
return this.listFiltered(1, 100000, null, null, filterRules, {"fields": "id"}).pipe(
|
||||
map(response => response.results.map(doc => doc.id))
|
||||
)
|
||||
return this.listFiltered(1, 100000, null, null, filterRules, {
|
||||
fields: 'id',
|
||||
}).pipe(map((response) => response.results.map((doc) => doc.id)))
|
||||
}
|
||||
|
||||
getPreviewUrl(id: number, original: boolean = false): string {
|
||||
let url = this.getResourceUrl(id, 'preview')
|
||||
if (this._searchQuery) url += `#search="${this._searchQuery}"`
|
||||
if (original) {
|
||||
url += "?original=true"
|
||||
url += '?original=true'
|
||||
}
|
||||
return url
|
||||
}
|
||||
@@ -113,41 +137,55 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
getDownloadUrl(id: number, original: boolean = false): string {
|
||||
let url = this.getResourceUrl(id, 'download')
|
||||
if (original) {
|
||||
url += "?original=true"
|
||||
url += '?original=true'
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
uploadDocument(formData) {
|
||||
return this.http.post(this.getResourceUrl(null, 'post_document'), formData, {reportProgress: true, observe: "events"})
|
||||
return this.http.post(
|
||||
this.getResourceUrl(null, 'post_document'),
|
||||
formData,
|
||||
{ reportProgress: true, observe: 'events' }
|
||||
)
|
||||
}
|
||||
|
||||
getMetadata(id: number): Observable<PaperlessDocumentMetadata> {
|
||||
return this.http.get<PaperlessDocumentMetadata>(this.getResourceUrl(id, 'metadata'))
|
||||
return this.http.get<PaperlessDocumentMetadata>(
|
||||
this.getResourceUrl(id, 'metadata')
|
||||
)
|
||||
}
|
||||
|
||||
bulkEdit(ids: number[], method: string, args: any) {
|
||||
return this.http.post(this.getResourceUrl(null, 'bulk_edit'), {
|
||||
'documents': ids,
|
||||
'method': method,
|
||||
'parameters': args
|
||||
documents: ids,
|
||||
method: method,
|
||||
parameters: args,
|
||||
})
|
||||
}
|
||||
|
||||
getSelectionData(ids: number[]): Observable<SelectionData> {
|
||||
return this.http.post<SelectionData>(this.getResourceUrl(null, 'selection_data'), {"documents": ids})
|
||||
return this.http.post<SelectionData>(
|
||||
this.getResourceUrl(null, 'selection_data'),
|
||||
{ documents: ids }
|
||||
)
|
||||
}
|
||||
|
||||
getSuggestions(id: number): Observable<PaperlessDocumentSuggestions> {
|
||||
return this.http.get<PaperlessDocumentSuggestions>(this.getResourceUrl(id, 'suggestions'))
|
||||
return this.http.get<PaperlessDocumentSuggestions>(
|
||||
this.getResourceUrl(id, 'suggestions')
|
||||
)
|
||||
}
|
||||
|
||||
bulkDownload(ids: number[], content="both") {
|
||||
return this.http.post(this.getResourceUrl(null, 'bulk_download'), {"documents": ids, "content": content}, { responseType: 'blob' })
|
||||
bulkDownload(ids: number[], content = 'both') {
|
||||
return this.http.post(
|
||||
this.getResourceUrl(null, 'bulk_download'),
|
||||
{ documents: ids, content: content },
|
||||
{ responseType: 'blob' }
|
||||
)
|
||||
}
|
||||
|
||||
public set searchQuery(query: string) {
|
||||
this._searchQuery = query
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { LogService } from './log.service';
|
||||
import { LogService } from './log.service'
|
||||
|
||||
describe('LogService', () => {
|
||||
let service: LogService;
|
||||
let service: LogService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(LogService);
|
||||
});
|
||||
TestBed.configureTestingModule({})
|
||||
service = TestBed.inject(LogService)
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(service).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,15 +1,13 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class LogService {
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
list(): Observable<string[]> {
|
||||
return this.http.get<string[]>(`${environment.apiBaseUrl}logs/`)
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { SavedViewService } from './saved-view.service';
|
||||
import { SavedViewService } from './saved-view.service'
|
||||
|
||||
describe('SavedViewService', () => {
|
||||
let service: SavedViewService;
|
||||
let service: SavedViewService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(SavedViewService);
|
||||
});
|
||||
TestBed.configureTestingModule({})
|
||||
service = TestBed.inject(SavedViewService)
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(service).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,22 +1,21 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { combineLatest, Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service';
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { combineLatest, Observable } from 'rxjs'
|
||||
import { tap } from 'rxjs/operators'
|
||||
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SavedViewService extends AbstractPaperlessService<PaperlessSavedView> {
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'saved_views')
|
||||
this.reload()
|
||||
}
|
||||
|
||||
private reload() {
|
||||
this.listAll().subscribe(r => this.savedViews = r.results)
|
||||
this.listAll().subscribe((r) => (this.savedViews = r.results))
|
||||
}
|
||||
|
||||
private savedViews: PaperlessSavedView[] = []
|
||||
@@ -26,34 +25,28 @@ export class SavedViewService extends AbstractPaperlessService<PaperlessSavedVie
|
||||
}
|
||||
|
||||
get sidebarViews() {
|
||||
return this.savedViews.filter(v => v.show_in_sidebar)
|
||||
return this.savedViews.filter((v) => v.show_in_sidebar)
|
||||
}
|
||||
|
||||
get dashboardViews() {
|
||||
return this.savedViews.filter(v => v.show_on_dashboard)
|
||||
return this.savedViews.filter((v) => v.show_on_dashboard)
|
||||
}
|
||||
|
||||
create(o: PaperlessSavedView) {
|
||||
return super.create(o).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
return super.create(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
update(o: PaperlessSavedView) {
|
||||
return super.update(o).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
return super.update(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
patchMany(objects: PaperlessSavedView[]): Observable<PaperlessSavedView[]> {
|
||||
return combineLatest(objects.map(o => super.patch(o))).pipe(
|
||||
return combineLatest(objects.map((o) => super.patch(o))).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
}
|
||||
|
||||
delete(o: PaperlessSavedView) {
|
||||
return super.delete(o).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
return super.delete(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { SearchService } from './search.service';
|
||||
import { SearchService } from './search.service'
|
||||
|
||||
describe('SearchService', () => {
|
||||
let service: SearchService;
|
||||
let service: SearchService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(SearchService);
|
||||
});
|
||||
TestBed.configureTestingModule({})
|
||||
service = TestBed.inject(SearchService)
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(service).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,19 +1,20 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { DocumentService } from './document.service';
|
||||
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { DocumentService } from './document.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SearchService {
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
autocomplete(term: string): Observable<string[]> {
|
||||
return this.http.get<string[]>(`${environment.apiBaseUrl}search/autocomplete/`, {params: new HttpParams().set('term', term)})
|
||||
return this.http.get<string[]>(
|
||||
`${environment.apiBaseUrl}search/autocomplete/`,
|
||||
{ params: new HttpParams().set('term', term) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { TagService } from './tag.service';
|
||||
import { TagService } from './tag.service'
|
||||
|
||||
describe('TagService', () => {
|
||||
let service: TagService;
|
||||
let service: TagService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(TagService);
|
||||
});
|
||||
TestBed.configureTestingModule({})
|
||||
service = TestBed.inject(TagService)
|
||||
})
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
expect(service).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -1,13 +1,12 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { PaperlessTag } from 'src/app/data/paperless-tag';
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service';
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessTag } from 'src/app/data/paperless-tag'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TagService extends AbstractNameFilterService<PaperlessTag> {
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'tags')
|
||||
}
|
||||
|
Reference in New Issue
Block a user