mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-20 00:56:26 +00:00
added paperless ui
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service';
|
||||
|
||||
describe('AbstractPaperlessService', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new AbstractPaperlessService()).toBeTruthy();
|
||||
});
|
||||
});
|
58
src-ui/src/app/services/rest/abstract-paperless-service.ts
Normal file
58
src-ui/src/app/services/rest/abstract-paperless-service.ts
Normal 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)
|
||||
}
|
||||
}
|
16
src-ui/src/app/services/rest/correspondent.service.spec.ts
Normal file
16
src-ui/src/app/services/rest/correspondent.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
15
src-ui/src/app/services/rest/correspondent.service.ts
Normal file
15
src-ui/src/app/services/rest/correspondent.service.ts
Normal 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')
|
||||
}
|
||||
|
||||
}
|
16
src-ui/src/app/services/rest/document-type.service.spec.ts
Normal file
16
src-ui/src/app/services/rest/document-type.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
14
src-ui/src/app/services/rest/document-type.service.ts
Normal file
14
src-ui/src/app/services/rest/document-type.service.ts
Normal 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')
|
||||
}
|
||||
}
|
16
src-ui/src/app/services/rest/document.service.spec.ts
Normal file
16
src-ui/src/app/services/rest/document.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
29
src-ui/src/app/services/rest/document.service.ts
Normal file
29
src-ui/src/app/services/rest/document.service.ts
Normal 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()}`
|
||||
}
|
||||
|
||||
}
|
16
src-ui/src/app/services/rest/search.service.spec.ts
Normal file
16
src-ui/src/app/services/rest/search.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
37
src-ui/src/app/services/rest/search.service.ts
Normal file
37
src-ui/src/app/services/rest/search.service.ts
Normal 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)})
|
||||
}
|
||||
}
|
16
src-ui/src/app/services/rest/tag.service.spec.ts
Normal file
16
src-ui/src/app/services/rest/tag.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
14
src-ui/src/app/services/rest/tag.service.ts
Normal file
14
src-ui/src/app/services/rest/tag.service.ts
Normal 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')
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user