mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Refactor frontend data models
This commit is contained in:
@@ -12,13 +12,13 @@ import {
|
||||
FILTER_HAS_TAGS_ALL,
|
||||
FILTER_HAS_TAGS_ANY,
|
||||
} from '../data/filter-rule-type'
|
||||
import { PaperlessSavedView } from '../data/paperless-saved-view'
|
||||
import { SavedView } from '../data/saved-view'
|
||||
import { FilterRule } from '../data/filter-rule'
|
||||
import { RouterTestingModule } from '@angular/router/testing'
|
||||
import { routes } from 'src/app/app-routing.module'
|
||||
import { PermissionsGuard } from '../guards/permissions.guard'
|
||||
import { SettingsService } from './settings.service'
|
||||
import { SETTINGS_KEYS } from '../data/paperless-uisettings'
|
||||
import { SETTINGS_KEYS } from '../data/ui-settings'
|
||||
|
||||
const documents = [
|
||||
{
|
||||
@@ -69,7 +69,7 @@ const filterRules: FilterRule[] = [
|
||||
},
|
||||
]
|
||||
|
||||
const view: PaperlessSavedView = {
|
||||
const view: SavedView = {
|
||||
id: 3,
|
||||
name: 'Saved View',
|
||||
sort_field: 'added',
|
||||
|
@@ -7,9 +7,9 @@ import {
|
||||
cloneFilterRules,
|
||||
isFullTextFilterRule,
|
||||
} from '../utils/filter-rules'
|
||||
import { PaperlessDocument } from '../data/paperless-document'
|
||||
import { PaperlessSavedView } from '../data/paperless-saved-view'
|
||||
import { SETTINGS_KEYS } from '../data/paperless-uisettings'
|
||||
import { Document } from '../data/document'
|
||||
import { SavedView } from '../data/saved-view'
|
||||
import { SETTINGS_KEYS } from '../data/ui-settings'
|
||||
import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys'
|
||||
import { paramsFromViewState, paramsToViewState } from '../utils/query-params'
|
||||
import {
|
||||
@@ -31,7 +31,7 @@ export interface ListViewState {
|
||||
/**
|
||||
* Current paginated list of documents displayed.
|
||||
*/
|
||||
documents?: PaperlessDocument[]
|
||||
documents?: Document[]
|
||||
|
||||
currentPage: number
|
||||
|
||||
@@ -149,7 +149,7 @@ export class DocumentListViewService {
|
||||
this.unsubscribeNotifier.next(true)
|
||||
}
|
||||
|
||||
activateSavedView(view: PaperlessSavedView) {
|
||||
activateSavedView(view: SavedView) {
|
||||
this.rangeSelectionAnchorIndex = this.lastRangeSelectionToIndex = null
|
||||
if (view) {
|
||||
this._activeSavedViewId = view.id
|
||||
@@ -159,16 +159,13 @@ export class DocumentListViewService {
|
||||
}
|
||||
}
|
||||
|
||||
activateSavedViewWithQueryParams(
|
||||
view: PaperlessSavedView,
|
||||
queryParams: ParamMap
|
||||
) {
|
||||
activateSavedViewWithQueryParams(view: SavedView, queryParams: ParamMap) {
|
||||
const viewState = paramsToViewState(queryParams)
|
||||
this.activateSavedView(view)
|
||||
this.currentPage = viewState.currentPage
|
||||
}
|
||||
|
||||
loadSavedView(view: PaperlessSavedView, closeCurrentView: boolean = false) {
|
||||
loadSavedView(view: SavedView, closeCurrentView: boolean = false) {
|
||||
if (closeCurrentView) {
|
||||
this._activeSavedViewId = null
|
||||
}
|
||||
@@ -350,7 +347,7 @@ export class DocumentListViewService {
|
||||
this.saveDocumentListView()
|
||||
}
|
||||
|
||||
get documents(): PaperlessDocument[] {
|
||||
get documents(): Document[] {
|
||||
return this.activeListViewState.documents
|
||||
}
|
||||
|
||||
@@ -494,18 +491,18 @@ export class DocumentListViewService {
|
||||
})
|
||||
}
|
||||
|
||||
isSelected(d: PaperlessDocument) {
|
||||
isSelected(d: Document) {
|
||||
return this.selected.has(d.id)
|
||||
}
|
||||
|
||||
toggleSelected(d: PaperlessDocument): void {
|
||||
toggleSelected(d: Document): void {
|
||||
if (this.selected.has(d.id)) this.selected.delete(d.id)
|
||||
else this.selected.add(d.id)
|
||||
this.rangeSelectionAnchorIndex = this.documentIndexInCurrentView(d.id)
|
||||
this.lastRangeSelectionToIndex = null
|
||||
}
|
||||
|
||||
selectRangeTo(d: PaperlessDocument) {
|
||||
selectRangeTo(d: Document) {
|
||||
if (this.rangeSelectionAnchorIndex !== null) {
|
||||
const documentToIndex = this.documentIndexInCurrentView(d.id)
|
||||
const fromIndex = Math.min(
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessDocument } from '../data/paperless-document'
|
||||
import { Document } from '../data/document'
|
||||
import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys'
|
||||
import { DocumentService } from './rest/document.service'
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
@@ -29,7 +29,7 @@ export class OpenDocumentsService {
|
||||
}
|
||||
}
|
||||
|
||||
private openDocuments: PaperlessDocument[] = []
|
||||
private openDocuments: Document[] = []
|
||||
private dirtyDocuments: Set<number> = new Set<number>()
|
||||
|
||||
refreshDocument(id: number) {
|
||||
@@ -48,15 +48,15 @@ export class OpenDocumentsService {
|
||||
}
|
||||
}
|
||||
|
||||
getOpenDocuments(): PaperlessDocument[] {
|
||||
getOpenDocuments(): Document[] {
|
||||
return this.openDocuments
|
||||
}
|
||||
|
||||
getOpenDocument(id: number): PaperlessDocument {
|
||||
getOpenDocument(id: number): Document {
|
||||
return this.openDocuments.find((d) => d.id == id)
|
||||
}
|
||||
|
||||
openDocument(doc: PaperlessDocument): Observable<boolean> {
|
||||
openDocument(doc: Document): Observable<boolean> {
|
||||
if (this.openDocuments.find((d) => d.id == doc.id) == null) {
|
||||
if (this.openDocuments.length == this.MAX_OPEN_DOCUMENTS) {
|
||||
// at max, ensure changes arent lost
|
||||
@@ -74,13 +74,13 @@ export class OpenDocumentsService {
|
||||
return of(true)
|
||||
}
|
||||
|
||||
private finishOpenDocument(doc: PaperlessDocument) {
|
||||
private finishOpenDocument(doc: Document) {
|
||||
this.openDocuments.unshift(doc)
|
||||
this.dirtyDocuments.delete(doc.id)
|
||||
this.save()
|
||||
}
|
||||
|
||||
setDirty(doc: PaperlessDocument, dirty: boolean) {
|
||||
setDirty(doc: Document, dirty: boolean) {
|
||||
if (!this.openDocuments.find((d) => d.id == doc.id)) return
|
||||
if (dirty) this.dirtyDocuments.add(doc.id)
|
||||
else this.dirtyDocuments.delete(doc.id)
|
||||
@@ -90,7 +90,7 @@ export class OpenDocumentsService {
|
||||
return this.dirtyDocuments.size > 0
|
||||
}
|
||||
|
||||
closeDocument(doc: PaperlessDocument): Observable<boolean> {
|
||||
closeDocument(doc: Document): Observable<boolean> {
|
||||
let index = this.openDocuments.findIndex((d) => d.id == doc.id)
|
||||
if (index == -1) return of(true)
|
||||
if (!this.dirtyDocuments.has(doc.id)) {
|
||||
|
@@ -4,27 +4,27 @@ import {
|
||||
PermissionType,
|
||||
PermissionsService,
|
||||
} from './permissions.service'
|
||||
import { PaperlessDocument } from '../data/paperless-document'
|
||||
import { Document } from '../data/document'
|
||||
|
||||
describe('PermissionsService', () => {
|
||||
let permissionsService: PermissionsService
|
||||
|
||||
const docUnowned: PaperlessDocument = {
|
||||
const docUnowned: Document = {
|
||||
title: 'Doc title',
|
||||
owner: null,
|
||||
}
|
||||
|
||||
const docOwned: PaperlessDocument = {
|
||||
const docOwned: Document = {
|
||||
title: 'Doc title 2',
|
||||
owner: 1,
|
||||
}
|
||||
|
||||
const docNotOwned: PaperlessDocument = {
|
||||
const docNotOwned: Document = {
|
||||
title: 'Doc title 3',
|
||||
owner: 2,
|
||||
}
|
||||
|
||||
const docUserViewGranted: PaperlessDocument = {
|
||||
const docUserViewGranted: Document = {
|
||||
title: 'Doc title 4',
|
||||
owner: 2,
|
||||
permissions: {
|
||||
@@ -39,7 +39,7 @@ describe('PermissionsService', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const docUserEditGranted: PaperlessDocument = {
|
||||
const docUserEditGranted: Document = {
|
||||
title: 'Doc title 5',
|
||||
owner: 2,
|
||||
permissions: {
|
||||
@@ -54,7 +54,7 @@ describe('PermissionsService', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const docGroupViewGranted: PaperlessDocument = {
|
||||
const docGroupViewGranted: Document = {
|
||||
title: 'Doc title 4',
|
||||
owner: 2,
|
||||
permissions: {
|
||||
@@ -69,7 +69,7 @@ describe('PermissionsService', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const docGroupEditGranted: PaperlessDocument = {
|
||||
const docGroupEditGranted: Document = {
|
||||
title: 'Doc title 5',
|
||||
owner: 2,
|
||||
permissions: {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { ObjectWithPermissions } from '../data/object-with-permissions'
|
||||
import { PaperlessUser } from '../data/paperless-user'
|
||||
import { User } from '../data/user'
|
||||
|
||||
export enum PermissionAction {
|
||||
Add = 'add',
|
||||
@@ -34,9 +34,9 @@ export enum PermissionType {
|
||||
})
|
||||
export class PermissionsService {
|
||||
private permissions: string[]
|
||||
private currentUser: PaperlessUser
|
||||
private currentUser: User
|
||||
|
||||
public initialize(permissions: string[], currentUser: PaperlessUser) {
|
||||
public initialize(permissions: string[], currentUser: User) {
|
||||
this.permissions = permissions
|
||||
this.currentUser = currentUser
|
||||
}
|
||||
|
@@ -6,13 +6,13 @@ import { commonAbstractPaperlessServiceTests } from './abstract-paperless-servic
|
||||
import { ConsumptionTemplateService } from './consumption-template.service'
|
||||
import {
|
||||
DocumentSource,
|
||||
PaperlessConsumptionTemplate,
|
||||
} from 'src/app/data/paperless-consumption-template'
|
||||
ConsumptionTemplate,
|
||||
} from 'src/app/data/consumption-template'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: ConsumptionTemplateService
|
||||
const endpoint = 'consumption_templates'
|
||||
const templates: PaperlessConsumptionTemplate[] = [
|
||||
const templates: ConsumptionTemplate[] = [
|
||||
{
|
||||
name: 'Template 1',
|
||||
id: 1,
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { tap } from 'rxjs'
|
||||
import { PaperlessConsumptionTemplate } from 'src/app/data/paperless-consumption-template'
|
||||
import { ConsumptionTemplate } from 'src/app/data/consumption-template'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ConsumptionTemplateService extends AbstractPaperlessService<PaperlessConsumptionTemplate> {
|
||||
export class ConsumptionTemplateService extends AbstractPaperlessService<ConsumptionTemplate> {
|
||||
loading: boolean
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
@@ -22,21 +22,21 @@ export class ConsumptionTemplateService extends AbstractPaperlessService<Paperle
|
||||
})
|
||||
}
|
||||
|
||||
private templates: PaperlessConsumptionTemplate[] = []
|
||||
private templates: ConsumptionTemplate[] = []
|
||||
|
||||
public get allTemplates(): PaperlessConsumptionTemplate[] {
|
||||
public get allTemplates(): ConsumptionTemplate[] {
|
||||
return this.templates
|
||||
}
|
||||
|
||||
create(o: PaperlessConsumptionTemplate) {
|
||||
create(o: ConsumptionTemplate) {
|
||||
return super.create(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
update(o: PaperlessConsumptionTemplate) {
|
||||
update(o: ConsumptionTemplate) {
|
||||
return super.update(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
delete(o: PaperlessConsumptionTemplate) {
|
||||
delete(o: ConsumptionTemplate) {
|
||||
return super.delete(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
|
||||
import { Correspondent } from 'src/app/data/correspondent'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CorrespondentService extends AbstractNameFilterService<PaperlessCorrespondent> {
|
||||
export class CorrespondentService extends AbstractNameFilterService<Correspondent> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'correspondents')
|
||||
}
|
||||
|
@@ -2,13 +2,13 @@ import { Injectable } from '@angular/core'
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
import { Observable } from 'rxjs'
|
||||
import { PaperlessCustomField } from 'src/app/data/paperless-custom-field'
|
||||
import { PaperlessCustomFieldInstance } from 'src/app/data/paperless-custom-field-instance'
|
||||
import { CustomField } from 'src/app/data/custom-field'
|
||||
import { CustomFieldInstance } from 'src/app/data/custom-field-instance'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CustomFieldsService extends AbstractPaperlessService<PaperlessCustomField> {
|
||||
export class CustomFieldsService extends AbstractPaperlessService<CustomField> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'custom_fields')
|
||||
}
|
||||
|
@@ -3,9 +3,6 @@ import { Subscription } from 'rxjs'
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { commonAbstractPaperlessServiceTests } from './abstract-paperless-service.spec'
|
||||
import { MailFilterAttachmentType } from 'src/app/data/paperless-mail-rule'
|
||||
import { MailMetadataTitleOption } from 'src/app/data/paperless-mail-rule'
|
||||
import { MailAction } from 'src/app/data/paperless-mail-rule'
|
||||
import { DocumentNotesService } from './document-notes.service'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
|
@@ -1,35 +1,31 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { PaperlessDocumentNote } from 'src/app/data/paperless-document-note'
|
||||
import { DocumentNote } from 'src/app/data/document-note'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
import { Observable } from 'rxjs'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DocumentNotesService extends AbstractPaperlessService<PaperlessDocumentNote> {
|
||||
export class DocumentNotesService extends AbstractPaperlessService<DocumentNote> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'documents')
|
||||
}
|
||||
|
||||
getNotes(documentId: number): Observable<PaperlessDocumentNote[]> {
|
||||
return this.http.get<PaperlessDocumentNote[]>(
|
||||
getNotes(documentId: number): Observable<DocumentNote[]> {
|
||||
return this.http.get<DocumentNote[]>(
|
||||
this.getResourceUrl(documentId, 'notes')
|
||||
)
|
||||
}
|
||||
|
||||
addNote(id: number, note: string): Observable<PaperlessDocumentNote[]> {
|
||||
return this.http.post<PaperlessDocumentNote[]>(
|
||||
this.getResourceUrl(id, 'notes'),
|
||||
{ note: note }
|
||||
)
|
||||
addNote(id: number, note: string): Observable<DocumentNote[]> {
|
||||
return this.http.post<DocumentNote[]>(this.getResourceUrl(id, 'notes'), {
|
||||
note: note,
|
||||
})
|
||||
}
|
||||
|
||||
deleteNote(
|
||||
documentId: number,
|
||||
noteId: number
|
||||
): Observable<PaperlessDocumentNote[]> {
|
||||
return this.http.delete<PaperlessDocumentNote[]>(
|
||||
deleteNote(documentId: number, noteId: number): Observable<DocumentNote[]> {
|
||||
return this.http.delete<DocumentNote[]>(
|
||||
this.getResourceUrl(documentId, 'notes'),
|
||||
{ params: new HttpParams({ fromString: `id=${noteId}` }) }
|
||||
)
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
|
||||
import { DocumentType } from 'src/app/data/document-type'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DocumentTypeService extends AbstractNameFilterService<PaperlessDocumentType> {
|
||||
export class DocumentTypeService extends AbstractNameFilterService<DocumentType> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'document_types')
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessDocument } from 'src/app/data/paperless-document'
|
||||
import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata'
|
||||
import { Document } from 'src/app/data/document'
|
||||
import { DocumentMetadata } from 'src/app/data/document-metadata'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
@@ -10,7 +10,7 @@ import { map, tap } from 'rxjs/operators'
|
||||
import { CorrespondentService } from './correspondent.service'
|
||||
import { DocumentTypeService } from './document-type.service'
|
||||
import { TagService } from './tag.service'
|
||||
import { PaperlessDocumentSuggestions } from 'src/app/data/paperless-document-suggestions'
|
||||
import { DocumentSuggestions } from 'src/app/data/document-suggestions'
|
||||
import { queryParamsFromFilterRules } from '../../utils/query-params'
|
||||
import { StoragePathService } from './storage-path.service'
|
||||
|
||||
@@ -49,7 +49,7 @@ export interface SelectionData {
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class DocumentService extends AbstractPaperlessService<PaperlessDocument> {
|
||||
export class DocumentService extends AbstractPaperlessService<Document> {
|
||||
private _searchQuery: string
|
||||
|
||||
constructor(
|
||||
@@ -62,7 +62,7 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
super(http, 'documents')
|
||||
}
|
||||
|
||||
addObservablesToDocument(doc: PaperlessDocument) {
|
||||
addObservablesToDocument(doc: Document) {
|
||||
if (doc.correspondent) {
|
||||
doc.correspondent$ = this.correspondentService.getCached(
|
||||
doc.correspondent
|
||||
@@ -93,7 +93,7 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
sortReverse?: boolean,
|
||||
filterRules?: FilterRule[],
|
||||
extraParams = {}
|
||||
): Observable<Results<PaperlessDocument>> {
|
||||
): Observable<Results<Document>> {
|
||||
return this.list(
|
||||
page,
|
||||
pageSize,
|
||||
@@ -114,8 +114,8 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
}).pipe(map((response) => response.results.map((doc) => doc.id)))
|
||||
}
|
||||
|
||||
get(id: number): Observable<PaperlessDocument> {
|
||||
return this.http.get<PaperlessDocument>(this.getResourceUrl(id), {
|
||||
get(id: number): Observable<Document> {
|
||||
return this.http.get<Document>(this.getResourceUrl(id), {
|
||||
params: {
|
||||
full_perms: true,
|
||||
},
|
||||
@@ -147,7 +147,7 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
return this.http.get<number>(this.getResourceUrl(null, 'next_asn'))
|
||||
}
|
||||
|
||||
update(o: PaperlessDocument): Observable<PaperlessDocument> {
|
||||
update(o: Document): Observable<Document> {
|
||||
// we want to only set created_date
|
||||
o.created = undefined
|
||||
return super.update(o)
|
||||
@@ -161,10 +161,8 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
)
|
||||
}
|
||||
|
||||
getMetadata(id: number): Observable<PaperlessDocumentMetadata> {
|
||||
return this.http.get<PaperlessDocumentMetadata>(
|
||||
this.getResourceUrl(id, 'metadata')
|
||||
)
|
||||
getMetadata(id: number): Observable<DocumentMetadata> {
|
||||
return this.http.get<DocumentMetadata>(this.getResourceUrl(id, 'metadata'))
|
||||
}
|
||||
|
||||
bulkEdit(ids: number[], method: string, args: any) {
|
||||
@@ -182,8 +180,8 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
|
||||
)
|
||||
}
|
||||
|
||||
getSuggestions(id: number): Observable<PaperlessDocumentSuggestions> {
|
||||
return this.http.get<PaperlessDocumentSuggestions>(
|
||||
getSuggestions(id: number): Observable<DocumentSuggestions> {
|
||||
return this.http.get<DocumentSuggestions>(
|
||||
this.getResourceUrl(id, 'suggestions')
|
||||
)
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable, switchMap } from 'rxjs'
|
||||
import { PaperlessGroup } from 'src/app/data/paperless-group'
|
||||
import { Group } from 'src/app/data/group'
|
||||
import { PermissionsService } from '../permissions.service'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GroupService extends AbstractNameFilterService<PaperlessGroup> {
|
||||
export class GroupService extends AbstractNameFilterService<Group> {
|
||||
constructor(
|
||||
http: HttpClient,
|
||||
private permissionService: PermissionsService
|
||||
@@ -16,7 +16,7 @@ export class GroupService extends AbstractNameFilterService<PaperlessGroup> {
|
||||
super(http, 'groups')
|
||||
}
|
||||
|
||||
update(o: PaperlessGroup): Observable<PaperlessGroup> {
|
||||
update(o: Group): Observable<Group> {
|
||||
return this.getCached(o.id).pipe(
|
||||
switchMap((initialGroup) => {
|
||||
initialGroup.permissions?.forEach((perm) => {
|
||||
|
@@ -4,7 +4,7 @@ import { TestBed } from '@angular/core/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { commonAbstractPaperlessServiceTests } from './abstract-paperless-service.spec'
|
||||
import { MailAccountService } from './mail-account.service'
|
||||
import { IMAPSecurity } from 'src/app/data/paperless-mail-account'
|
||||
import { IMAPSecurity } from 'src/app/data/mail-account'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: MailAccountService
|
||||
|
@@ -2,13 +2,13 @@ import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { combineLatest, Observable } from 'rxjs'
|
||||
import { tap } from 'rxjs/operators'
|
||||
import { PaperlessMailAccount } from 'src/app/data/paperless-mail-account'
|
||||
import { MailAccount } from 'src/app/data/mail-account'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MailAccountService extends AbstractPaperlessService<PaperlessMailAccount> {
|
||||
export class MailAccountService extends AbstractPaperlessService<MailAccount> {
|
||||
loading: boolean
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
@@ -23,33 +23,31 @@ export class MailAccountService extends AbstractPaperlessService<PaperlessMailAc
|
||||
})
|
||||
}
|
||||
|
||||
private mailAccounts: PaperlessMailAccount[] = []
|
||||
private mailAccounts: MailAccount[] = []
|
||||
|
||||
get allAccounts() {
|
||||
return this.mailAccounts
|
||||
}
|
||||
|
||||
create(o: PaperlessMailAccount) {
|
||||
create(o: MailAccount) {
|
||||
return super.create(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
update(o: PaperlessMailAccount) {
|
||||
update(o: MailAccount) {
|
||||
return super.update(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
patchMany(
|
||||
objects: PaperlessMailAccount[]
|
||||
): Observable<PaperlessMailAccount[]> {
|
||||
patchMany(objects: MailAccount[]): Observable<MailAccount[]> {
|
||||
return combineLatest(objects.map((o) => super.patch(o))).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
}
|
||||
|
||||
delete(o: PaperlessMailAccount) {
|
||||
delete(o: MailAccount) {
|
||||
return super.delete(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
test(o: PaperlessMailAccount) {
|
||||
test(o: MailAccount) {
|
||||
const account = Object.assign({}, o)
|
||||
delete account['set_permissions']
|
||||
return this.http.post(this.getResourceUrl() + 'test/', account)
|
||||
|
@@ -4,9 +4,9 @@ import { TestBed } from '@angular/core/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { commonAbstractPaperlessServiceTests } from './abstract-paperless-service.spec'
|
||||
import { MailRuleService } from './mail-rule.service'
|
||||
import { MailFilterAttachmentType } from 'src/app/data/paperless-mail-rule'
|
||||
import { MailMetadataTitleOption } from 'src/app/data/paperless-mail-rule'
|
||||
import { MailAction } from 'src/app/data/paperless-mail-rule'
|
||||
import { MailFilterAttachmentType } from 'src/app/data/mail-rule'
|
||||
import { MailMetadataTitleOption } from 'src/app/data/mail-rule'
|
||||
import { MailAction } from 'src/app/data/mail-rule'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: MailRuleService
|
||||
|
@@ -2,13 +2,13 @@ import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { combineLatest, Observable } from 'rxjs'
|
||||
import { tap } from 'rxjs/operators'
|
||||
import { PaperlessMailRule } from 'src/app/data/paperless-mail-rule'
|
||||
import { MailRule } from 'src/app/data/mail-rule'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MailRuleService extends AbstractPaperlessService<PaperlessMailRule> {
|
||||
export class MailRuleService extends AbstractPaperlessService<MailRule> {
|
||||
loading: boolean
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
@@ -23,27 +23,27 @@ export class MailRuleService extends AbstractPaperlessService<PaperlessMailRule>
|
||||
})
|
||||
}
|
||||
|
||||
private mailRules: PaperlessMailRule[] = []
|
||||
private mailRules: MailRule[] = []
|
||||
|
||||
get allRules() {
|
||||
return this.mailRules
|
||||
}
|
||||
|
||||
create(o: PaperlessMailRule) {
|
||||
create(o: MailRule) {
|
||||
return super.create(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
update(o: PaperlessMailRule) {
|
||||
update(o: MailRule) {
|
||||
return super.update(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
patchMany(objects: PaperlessMailRule[]): Observable<PaperlessMailRule[]> {
|
||||
patchMany(objects: MailRule[]): Observable<MailRule[]> {
|
||||
return combineLatest(objects.map((o) => super.patch(o))).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
}
|
||||
|
||||
delete(o: PaperlessMailRule) {
|
||||
delete(o: MailRule) {
|
||||
return super.delete(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import { environment } from 'src/environments/environment'
|
||||
import { commonAbstractPaperlessServiceTests } from './abstract-paperless-service.spec'
|
||||
import { SavedViewService } from './saved-view.service'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: SavedViewService
|
||||
|
@@ -2,16 +2,16 @@ 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 { SavedView } from 'src/app/data/saved-view'
|
||||
import { PermissionsService } from '../permissions.service'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SavedViewService extends AbstractPaperlessService<PaperlessSavedView> {
|
||||
export class SavedViewService extends AbstractPaperlessService<SavedView> {
|
||||
loading: boolean
|
||||
|
||||
constructor(
|
||||
@@ -35,13 +35,13 @@ export class SavedViewService extends AbstractPaperlessService<PaperlessSavedVie
|
||||
})
|
||||
}
|
||||
|
||||
private savedViews: PaperlessSavedView[] = []
|
||||
private savedViews: SavedView[] = []
|
||||
|
||||
get allViews() {
|
||||
return this.savedViews
|
||||
}
|
||||
|
||||
get sidebarViews(): PaperlessSavedView[] {
|
||||
get sidebarViews(): SavedView[] {
|
||||
const sidebarViews = this.savedViews.filter((v) => v.show_in_sidebar)
|
||||
|
||||
const sorted: number[] = this.settingsService.get(
|
||||
@@ -56,7 +56,7 @@ export class SavedViewService extends AbstractPaperlessService<PaperlessSavedVie
|
||||
: [...sidebarViews]
|
||||
}
|
||||
|
||||
get dashboardViews(): PaperlessSavedView[] {
|
||||
get dashboardViews(): SavedView[] {
|
||||
const dashboardViews = this.savedViews.filter((v) => v.show_on_dashboard)
|
||||
|
||||
const sorted: number[] = this.settingsService.get(
|
||||
@@ -71,21 +71,21 @@ export class SavedViewService extends AbstractPaperlessService<PaperlessSavedVie
|
||||
: [...dashboardViews]
|
||||
}
|
||||
|
||||
create(o: PaperlessSavedView) {
|
||||
create(o: SavedView) {
|
||||
return super.create(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
update(o: PaperlessSavedView) {
|
||||
update(o: SavedView) {
|
||||
return super.update(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
|
||||
patchMany(objects: PaperlessSavedView[]): Observable<PaperlessSavedView[]> {
|
||||
patchMany(objects: SavedView[]): Observable<SavedView[]> {
|
||||
return combineLatest(objects.map((o) => super.patch(o))).pipe(
|
||||
tap(() => this.reload())
|
||||
)
|
||||
}
|
||||
|
||||
delete(o: PaperlessSavedView) {
|
||||
delete(o: SavedView) {
|
||||
return super.delete(o).pipe(tap(() => this.reload()))
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,5 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import {
|
||||
PaperlessShareLink,
|
||||
PaperlessFileVersion,
|
||||
} from 'src/app/data/paperless-share-link'
|
||||
import { ShareLink, FileVersion } from 'src/app/data/share-link'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
@@ -10,24 +7,24 @@ import { Observable } from 'rxjs'
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ShareLinkService extends AbstractNameFilterService<PaperlessShareLink> {
|
||||
export class ShareLinkService extends AbstractNameFilterService<ShareLink> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'share_links')
|
||||
}
|
||||
|
||||
getLinksForDocument(documentId: number): Observable<PaperlessShareLink[]> {
|
||||
return this.http.get<PaperlessShareLink[]>(
|
||||
getLinksForDocument(documentId: number): Observable<ShareLink[]> {
|
||||
return this.http.get<ShareLink[]>(
|
||||
`${this.baseUrl}documents/${documentId}/${this.resourceName}/`
|
||||
)
|
||||
}
|
||||
|
||||
createLinkForDocument(
|
||||
documentId: number,
|
||||
file_version: PaperlessFileVersion = PaperlessFileVersion.Archive,
|
||||
file_version: FileVersion = FileVersion.Archive,
|
||||
expiration: Date = null
|
||||
) {
|
||||
this.clearCache()
|
||||
return this.http.post<PaperlessShareLink>(this.getResourceUrl(), {
|
||||
return this.http.post<ShareLink>(this.getResourceUrl(), {
|
||||
document: documentId,
|
||||
file_version,
|
||||
expiration: expiration?.toISOString(),
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
|
||||
import { StoragePath } from 'src/app/data/storage-path'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class StoragePathService extends AbstractNameFilterService<PaperlessStoragePath> {
|
||||
export class StoragePathService extends AbstractNameFilterService<StoragePath> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'storage_paths')
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PaperlessTag } from 'src/app/data/paperless-tag'
|
||||
import { Tag } from 'src/app/data/tag'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TagService extends AbstractNameFilterService<PaperlessTag> {
|
||||
export class TagService extends AbstractNameFilterService<Tag> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'tags')
|
||||
}
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable, switchMap } from 'rxjs'
|
||||
import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
import { User } from 'src/app/data/user'
|
||||
import { PermissionsService } from '../permissions.service'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserService extends AbstractNameFilterService<PaperlessUser> {
|
||||
export class UserService extends AbstractNameFilterService<User> {
|
||||
constructor(
|
||||
http: HttpClient,
|
||||
private permissionService: PermissionsService
|
||||
@@ -16,7 +16,7 @@ export class UserService extends AbstractNameFilterService<PaperlessUser> {
|
||||
super(http, 'users')
|
||||
}
|
||||
|
||||
update(o: PaperlessUser): Observable<PaperlessUser> {
|
||||
update(o: User): Observable<User> {
|
||||
return this.getCached(o.id).pipe(
|
||||
switchMap((initialUser) => {
|
||||
initialUser.user_permissions?.forEach((perm) => {
|
||||
|
@@ -10,12 +10,9 @@ import { CookieService } from 'ngx-cookie-service'
|
||||
import { Subscription } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { AppModule } from '../app.module'
|
||||
import {
|
||||
PaperlessUiSettings,
|
||||
SETTINGS_KEYS,
|
||||
} from '../data/paperless-uisettings'
|
||||
import { UiSettings, SETTINGS_KEYS } from '../data/ui-settings'
|
||||
import { SettingsService } from './settings.service'
|
||||
import { PaperlessSavedView } from '../data/paperless-saved-view'
|
||||
import { SavedView } from '../data/saved-view'
|
||||
|
||||
describe('SettingsService', () => {
|
||||
let httpTestingController: HttpTestingController
|
||||
@@ -23,7 +20,7 @@ describe('SettingsService', () => {
|
||||
let cookieService: CookieService
|
||||
let subscription: Subscription
|
||||
|
||||
const ui_settings: PaperlessUiSettings = {
|
||||
const ui_settings: UiSettings = {
|
||||
user: {
|
||||
username: 'testuser',
|
||||
first_name: 'Test',
|
||||
@@ -285,16 +282,16 @@ describe('SettingsService', () => {
|
||||
.flush(ui_settings)
|
||||
const setSpy = jest.spyOn(settingsService, 'set')
|
||||
settingsService.updateDashboardViewsSort([
|
||||
{ id: 1 } as PaperlessSavedView,
|
||||
{ id: 4 } as PaperlessSavedView,
|
||||
{ id: 1 } as SavedView,
|
||||
{ id: 4 } as SavedView,
|
||||
])
|
||||
expect(setSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.DASHBOARD_VIEWS_SORT_ORDER,
|
||||
[1, 4]
|
||||
)
|
||||
settingsService.updateSidebarViewsSort([
|
||||
{ id: 1 } as PaperlessSavedView,
|
||||
{ id: 4 } as PaperlessSavedView,
|
||||
{ id: 1 } as SavedView,
|
||||
{ id: 4 } as SavedView,
|
||||
])
|
||||
expect(setSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER,
|
||||
|
@@ -17,15 +17,11 @@ import {
|
||||
hexToHsl,
|
||||
} from 'src/app/utils/color'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import {
|
||||
PaperlessUiSettings,
|
||||
SETTINGS,
|
||||
SETTINGS_KEYS,
|
||||
} from '../data/paperless-uisettings'
|
||||
import { PaperlessUser } from '../data/paperless-user'
|
||||
import { UiSettings, SETTINGS, SETTINGS_KEYS } from '../data/ui-settings'
|
||||
import { User } from '../data/user'
|
||||
import { PermissionsService } from './permissions.service'
|
||||
import { ToastService } from './toast.service'
|
||||
import { PaperlessSavedView } from '../data/paperless-saved-view'
|
||||
import { SavedView } from '../data/saved-view'
|
||||
|
||||
export interface LanguageOption {
|
||||
code: string
|
||||
@@ -240,7 +236,7 @@ export class SettingsService {
|
||||
protected baseUrl: string = environment.apiBaseUrl + 'ui_settings/'
|
||||
|
||||
private settings: Object = {}
|
||||
currentUser: PaperlessUser
|
||||
currentUser: User
|
||||
|
||||
public settingsSaved: EventEmitter<any> = new EventEmitter()
|
||||
|
||||
@@ -269,8 +265,8 @@ export class SettingsService {
|
||||
}
|
||||
|
||||
// this is called by the app initializer in app.module
|
||||
public initializeSettings(): Observable<PaperlessUiSettings> {
|
||||
return this.http.get<PaperlessUiSettings>(this.baseUrl).pipe(
|
||||
public initializeSettings(): Observable<UiSettings> {
|
||||
return this.http.get<UiSettings>(this.baseUrl).pipe(
|
||||
first(),
|
||||
tap((uisettings) => {
|
||||
Object.assign(this.settings, uisettings.settings)
|
||||
@@ -546,16 +542,14 @@ export class SettingsService {
|
||||
}
|
||||
}
|
||||
|
||||
updateDashboardViewsSort(
|
||||
dashboardViews: PaperlessSavedView[]
|
||||
): Observable<any> {
|
||||
updateDashboardViewsSort(dashboardViews: SavedView[]): Observable<any> {
|
||||
this.set(SETTINGS_KEYS.DASHBOARD_VIEWS_SORT_ORDER, [
|
||||
...new Set(dashboardViews.map((v) => v.id)),
|
||||
])
|
||||
return this.storeSettings()
|
||||
}
|
||||
|
||||
updateSidebarViewsSort(sidebarViews: PaperlessSavedView[]): Observable<any> {
|
||||
updateSidebarViewsSort(sidebarViews: SavedView[]): Observable<any> {
|
||||
this.set(SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER, [
|
||||
...new Set(sidebarViews.map((v) => v.id)),
|
||||
])
|
||||
|
Reference in New Issue
Block a user