added paperless ui

This commit is contained in:
Jonas Winkler
2020-10-27 01:10:18 +01:00
parent e24baf5811
commit 8693bee4ac
173 changed files with 18693 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
import { AbstractPaperlessService } from './abstract-paperless-service';
describe('AbstractPaperlessService', () => {
it('should create an instance', () => {
expect(new AbstractPaperlessService()).toBeTruthy();
});
});

View File

@@ -0,0 +1,58 @@
import { HttpClient, HttpParams } from '@angular/common/http'
import { Observable } from 'rxjs'
import { ObjectWithId } from 'src/app/data/object-with-id'
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) { }
protected getResourceUrl(id?: number, action?: string): string {
let url = `${this.baseUrl}${this.resourceName}/`
if (id) {
url += `${id}/`
if (action) {
url += `${action}/`
}
}
return url
}
list(page?: number, pageSize?: number, ordering?: string, extraParams?): Observable<Results<T>> {
let httpParams = new HttpParams()
if (page) {
httpParams = httpParams.set('page', page.toString())
}
if (pageSize) {
httpParams = httpParams.set('page_size', pageSize.toString())
}
if (ordering) {
httpParams = httpParams.set('ordering', ordering)
}
for (let extraParamKey in extraParams) {
if (extraParams[extraParamKey]) {
httpParams = httpParams.set(extraParamKey, extraParams[extraParamKey])
}
}
return this.http.get<Results<T>>(this.getResourceUrl(), {params: httpParams})
}
get(id: number): Observable<T> {
return this.http.get<T>(this.getResourceUrl(id))
}
create(o: T): Observable<T> {
return this.http.post<T>(this.getResourceUrl(), o)
}
delete(o: T): Observable<any> {
return this.http.delete(this.getResourceUrl(o.id))
}
update(o: T): Observable<T> {
return this.http.put<T>(this.getResourceUrl(o.id), o)
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { CorrespondentService } from './correspondent.service';
describe('CorrespondentService', () => {
let service: CorrespondentService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CorrespondentService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,15 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent';
import { AbstractPaperlessService } from './abstract-paperless-service';
@Injectable({
providedIn: 'root'
})
export class CorrespondentService extends AbstractPaperlessService<PaperlessCorrespondent> {
constructor(http: HttpClient) {
super(http, 'correspondents')
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { DocumentTypeService } from './document-type.service';
describe('DocumentTypeService', () => {
let service: DocumentTypeService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(DocumentTypeService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,14 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type';
import { AbstractPaperlessService } from './abstract-paperless-service';
@Injectable({
providedIn: 'root'
})
export class DocumentTypeService extends AbstractPaperlessService<PaperlessDocumentType> {
constructor(http: HttpClient) {
super(http, 'document_types')
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { DocumentService } from './document.service';
describe('DocumentService', () => {
let service: DocumentService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(DocumentService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,29 @@
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';
@Injectable({
providedIn: 'root'
})
export class DocumentService extends AbstractPaperlessService<PaperlessDocument> {
constructor(http: HttpClient, private auth: AuthService) {
super(http, 'documents')
}
getPreviewUrl(id: number): string {
return this.getResourceUrl(id, 'preview') + `?auth_token=${this.auth.getToken()}`
}
getThumbUrl(id: number): string {
return this.getResourceUrl(id, 'thumb') + `?auth_token=${this.auth.getToken()}`
}
getDownloadUrl(id: number): string {
return this.getResourceUrl(id, 'download') + `?auth_token=${this.auth.getToken()}`
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { SearchService } from './search.service';
describe('SearchService', () => {
let service: SearchService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SearchService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,37 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { PaperlessDocument } from 'src/app/data/paperless-document';
import { environment } from 'src/environments/environment';
export class SearchResultHighlightedText {
text?: string
term?: number
toString(): string {
return this.text
}
}
export class SearchResult {
id?: number
title?: string
content?: string
score?: number
highlights?: SearchResultHighlightedText[][]
document?: PaperlessDocument
}
@Injectable({
providedIn: 'root'
})
export class SearchService {
constructor(private http: HttpClient) { }
search(query: string): Observable<SearchResult[]> {
return this.http.get<SearchResult[]>(`${environment.apiBaseUrl}search/`, {params: new HttpParams().set('query', query)})
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TagService } from './tag.service';
describe('TagService', () => {
let service: TagService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TagService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,14 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { PaperlessTag } from 'src/app/data/paperless-tag';
import { AbstractPaperlessService } from './abstract-paperless-service';
@Injectable({
providedIn: 'root'
})
export class TagService extends AbstractPaperlessService<PaperlessTag> {
constructor(http: HttpClient) {
super(http, 'tags')
}
}