Saving work, basic frontend getting & display

This commit is contained in:
shamoon 2023-10-20 23:51:14 -07:00
parent d9526ea32f
commit 6f62da077a
11 changed files with 263 additions and 139 deletions

View File

@ -41,6 +41,9 @@ export class AbstractInputComponent<T> implements OnInit, ControlValueAccessor {
@Input() @Input()
error: string error: string
@Input()
horizontal: boolean = false
value: T value: T
ngOnInit(): void { ngOnInit(): void {

View File

@ -1,26 +1,32 @@
<div class="mb-3"> <div class="mb-3">
<label class="form-label" [for]="inputId">{{title}}</label> <div class="row">
<div class="input-group" [class.is-invalid]="error"> <div class="d-flex align-items-center" [class.col-md-3]="horizontal">
<input #inputField class="form-control" [class.is-invalid]="error" [placeholder]="placeholder" [id]="inputId" maxlength="10" <label class="form-label mb-md-0" [for]="inputId">{{title}}</label>
(dateSelect)="onChange(value)" (change)="onChange(value)" (keypress)="onKeyPress($event)" (paste)="onPaste($event)" </div>
name="dp" [(ngModel)]="value" ngbDatepicker #datePicker="ngbDatepicker" #datePickerContent="ngModel" [disabled]="disabled"> <div [class.col-md-9]="horizontal">
<button class="btn btn-outline-secondary calendar" (click)="datePicker.toggle()" type="button" [disabled]="disabled"> <div class="input-group" [class.is-invalid]="error">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar" viewBox="0 0 16 16"> <input #inputField class="form-control" [class.is-invalid]="error" [placeholder]="placeholder" [id]="inputId" maxlength="10"
<path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/> (dateSelect)="onChange(value)" (change)="onChange(value)" (keypress)="onKeyPress($event)" (paste)="onPaste($event)"
</svg> name="dp" [(ngModel)]="value" ngbDatepicker #datePicker="ngbDatepicker" #datePickerContent="ngModel" [disabled]="disabled">
</button> <button class="btn btn-outline-secondary calendar" (click)="datePicker.toggle()" type="button" [disabled]="disabled">
<button *ngIf="showFilter" class="btn btn-outline-secondary" type="button" (click)="onFilterDocuments()" [disabled]="this.value === null" title="{{ fitlerButtonTitle }}"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar" viewBox="0 0 16 16">
<svg class="buttonicon" fill="currentColor"> <path d="M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z"/>
<use xlink:href="assets/bootstrap-icons.svg#filter" /> </svg>
</svg> </button>
</button> <button *ngIf="showFilter" class="btn btn-outline-secondary" type="button" (click)="onFilterDocuments()" [disabled]="this.value === null" title="{{ fitlerButtonTitle }}">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#filter" />
</svg>
</button>
</div>
<div class="invalid-feedback" i18n>Invalid date.</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
<small *ngIf="getSuggestions().length > 0">
<span i18n>Suggestions:</span>&nbsp;
<ng-container *ngFor="let s of getSuggestions()">
<a (click)="onSuggestionClick(s)" [routerLink]="[]">{{s}}</a>&nbsp;
</ng-container>
</small>
</div>
</div> </div>
<div class="invalid-feedback" i18n>Invalid date.</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
<small *ngIf="getSuggestions().length > 0">
<span i18n>Suggestions:</span>&nbsp;
<ng-container *ngFor="let s of getSuggestions()">
<a (click)="onSuggestionClick(s)" [routerLink]="[]">{{s}}</a>&nbsp;
</ng-container>
</small>
</div> </div>

View File

@ -1,12 +1,17 @@
<div class="mb-3"> <div class="mb-3">
<label class="form-label" [for]="inputId">{{title}}</label> <div class="row">
<div class="input-group" [class.is-invalid]="error"> <div [class.col-md-3]="horizontal">
<input #inputField type="number" class="form-control" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)" [class.is-invalid]="error" [disabled]="disabled"> <label class="form-label" [for]="inputId">{{title}}</label>
<button *ngIf="showAdd" class="btn btn-outline-secondary" type="button" id="button-addon1" (click)="nextAsn()" [disabled]="disabled">+1</button> </div>
<div [class.col-md-9]="horizontal">
<div class="input-group" [class.is-invalid]="error">
<input #inputField type="number" class="form-control" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)" [class.is-invalid]="error" [disabled]="disabled">
<button *ngIf="showAdd" class="btn btn-outline-secondary" type="button" id="button-addon1" (click)="nextAsn()" [disabled]="disabled">+1</button>
</div>
<div class="invalid-feedback">
{{error}}
</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
</div>
</div> </div>
<div class="invalid-feedback">
{{error}}
</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
</div> </div>

View File

@ -1,44 +1,48 @@
<div class="mb-3 paperless-input-select" [class.disabled]="disabled"> <div class="mb-3 paperless-input-select" [class.disabled]="disabled">
<label *ngIf="title" class="form-label" [for]="inputId">{{title}}</label> <div class="row">
<div [class.input-group]="allowCreateNew || showFilter"> <div class="d-flex align-items-center" [class.col-md-3]="horizontal">
<ng-select name="inputId" [(ngModel)]="value" <label *ngIf="title" class="form-label mb-md-0" [for]="inputId">{{title}}</label>
[disabled]="disabled"
[style.color]="textColor"
[style.background]="backgroundColor"
[class.private]="isPrivate"
[clearable]="allowNull"
[items]="items"
[addTag]="allowCreateNew && addItemRef"
addTagText="Add item"
i18n-addTagText="Used for both types, correspondents, storage paths"
[placeholder]="placeholder"
[multiple]="multiple"
[bindLabel]="bindLabel"
bindValue="id"
(change)="onChange(value)"
(search)="onSearch($event)"
(focus)="clearLastSearchTerm()"
(clear)="clearLastSearchTerm()"
(blur)="onBlur()">
</ng-select>
<button *ngIf="allowCreateNew" class="btn btn-outline-secondary" type="button" (click)="addItem()" [disabled]="disabled">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#plus" />
</svg>
</button>
<button *ngIf="showFilter" class="btn btn-outline-secondary" type="button" (click)="onFilterDocuments()" [disabled]="isPrivate || this.value === null" title="{{ filterButtonTitle }}">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#filter" />
</svg>
</button>
</div> </div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small> <div [class.col-md-9]="horizontal">
<small *ngIf="getSuggestions().length > 0"> <div [class.input-group]="allowCreateNew || showFilter">
<span i18n>Suggestions:</span>&nbsp; <ng-select name="inputId" [(ngModel)]="value"
<ng-container *ngFor="let s of getSuggestions()"> [disabled]="disabled"
<a (click)="value = s.id; onChange(value)" [routerLink]="[]">{{s.name}}</a>&nbsp; [style.color]="textColor"
</ng-container> [style.background]="backgroundColor"
[class.private]="isPrivate"
[clearable]="allowNull"
</small> [items]="items"
[addTag]="allowCreateNew && addItemRef"
addTagText="Add item"
i18n-addTagText="Used for both types, correspondents, storage paths"
[placeholder]="placeholder"
[multiple]="multiple"
[bindLabel]="bindLabel"
bindValue="id"
(change)="onChange(value)"
(search)="onSearch($event)"
(focus)="clearLastSearchTerm()"
(clear)="clearLastSearchTerm()"
(blur)="onBlur()">
</ng-select>
<button *ngIf="allowCreateNew" class="btn btn-outline-secondary" type="button" (click)="addItem()" [disabled]="disabled">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#plus" />
</svg>
</button>
<button *ngIf="showFilter" class="btn btn-outline-secondary" type="button" (click)="onFilterDocuments()" [disabled]="isPrivate || this.value === null" title="{{ filterButtonTitle }}">
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#filter" />
</svg>
</button>
</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
<small *ngIf="getSuggestions().length > 0">
<span i18n>Suggestions:</span>&nbsp;
<ng-container *ngFor="let s of getSuggestions()">
<a (click)="value = s.id; onChange(value)" [routerLink]="[]">{{s.name}}</a>&nbsp;
</ng-container>
</small>
</div>
</div>
</div> </div>

View File

@ -1,51 +1,53 @@
<div class="mb-3 paperless-input-select paperless-input-tags" [class.disabled]="disabled"> <div class="mb-3 paperless-input-select paperless-input-tags" [class.disabled]="disabled">
<label class="form-label" for="tags" i18n>{{title}}</label> <div class="row">
<div class="d-flex align-items-center" [class.col-md-3]="horizontal">
<label class="form-label mb-md-0" for="tags" i18n>{{title}}</label>
</div>
<div [class.col-md-9]="horizontal">
<div class="input-group flex-nowrap">
<ng-select #tagSelect name="tags" [items]="tags" bindLabel="name" bindValue="id" [(ngModel)]="value"
[disabled]="disabled"
[multiple]="true"
[closeOnSelect]="false"
[clearSearchOnAdd]="true"
[hideSelected]="tags.length > 0"
[addTag]="allowCreate ? createTagRef : false"
addTagText="Add tag"
i18n-addTagText
(change)="onChange(value)">
<div class="input-group flex-nowrap"> <ng-template ng-label-tmp let-item="item">
<ng-select #tagSelect name="tags" [items]="tags" bindLabel="name" bindValue="id" [(ngModel)]="value" <span class="tag-wrap tag-wrap-delete" (mousedown)="removeTag($event, item.id)">
[disabled]="disabled" <svg width="1.2em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
[multiple]="true" <use xlink:href="assets/bootstrap-icons.svg#x"/>
[closeOnSelect]="false" </svg>
[clearSearchOnAdd]="true" <pngx-tag *ngIf="item.id && tags" style="background-color: none;" [tag]="getTag(item.id)"></pngx-tag>
[hideSelected]="tags.length > 0" </span>
[addTag]="allowCreate ? createTagRef : false" </ng-template>
addTagText="Add tag" <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">
i18n-addTagText <div class="tag-wrap">
(change)="onChange(value)"> <pngx-tag *ngIf="item.id && tags" class="me-2" [tag]="getTag(item.id)"></pngx-tag>
</div>
<ng-template ng-label-tmp let-item="item"> </ng-template>
<span class="tag-wrap tag-wrap-delete" (mousedown)="removeTag($event, item.id)"> </ng-select>
<svg width="1.2em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> <button *ngIf="allowCreate" class="btn btn-outline-secondary" type="button" (click)="createTag()" [disabled]="disabled">
<use xlink:href="assets/bootstrap-icons.svg#x"/> <svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#plus" />
</svg> </svg>
<pngx-tag *ngIf="item.id && tags" style="background-color: none;" [tag]="getTag(item.id)"></pngx-tag> </button>
</span> <button *ngIf="showFilter" class="btn btn-outline-secondary" type="button" (click)="onFilterDocuments()" [disabled]="hasPrivate || this.value === null" i18n-title title="Filter documents with these Tags">
</ng-template> <svg class="buttonicon" fill="currentColor">
<ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm"> <use xlink:href="assets/bootstrap-icons.svg#filter" />
<div class="tag-wrap"> </svg>
<pngx-tag *ngIf="item.id && tags" class="me-2" [tag]="getTag(item.id)"></pngx-tag> </button>
</div> </div>
</ng-template> <small class="form-text text-muted" *ngIf="hint">{{hint}}</small>
</ng-select> <small *ngIf="getSuggestions().length > 0">
<button *ngIf="allowCreate" class="btn btn-outline-secondary" type="button" (click)="createTag()" [disabled]="disabled"> <span i18n>Suggestions:</span>&nbsp;
<svg class="buttonicon" fill="currentColor"> <ng-container *ngFor="let tag of getSuggestions()">
<use xlink:href="assets/bootstrap-icons.svg#plus" /> <a (click)="addTag(tag.id)" [routerLink]="[]">{{tag.name}}</a>&nbsp;
</svg> </ng-container>
</button> </small>
<button *ngIf="showFilter" class="btn btn-outline-secondary" type="button" (click)="onFilterDocuments()" [disabled]="hasPrivate || this.value === null" i18n-title title="Filter documents with these Tags"> </div>
<svg class="buttonicon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#filter" />
</svg>
</button>
</div> </div>
<small class="form-text text-muted" *ngIf="hint">{{hint}}</small>
<small *ngIf="getSuggestions().length > 0">
<span i18n>Suggestions:</span>&nbsp;
<ng-container *ngFor="let tag of getSuggestions()">
<a (click)="addTag(tag.id)" [routerLink]="[]">{{tag.name}}</a>&nbsp;
</ng-container>
</small>
</div> </div>

View File

@ -77,6 +77,9 @@ export class TagsComponent implements OnInit, ControlValueAccessor {
@Input() @Input()
showFilter: boolean = false showFilter: boolean = false
@Input()
horizontal: boolean = false
@Output() @Output()
filterDocuments = new EventEmitter<PaperlessTag[]>() filterDocuments = new EventEmitter<PaperlessTag[]>()

View File

@ -1,8 +1,14 @@
<div class="mb-3"> <div class="mb-3">
<label class="form-label" [for]="inputId">{{title}}</label> <div class="row">
<input #inputField type="text" class="form-control" [class.is-invalid]="error" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)" [disabled]="disabled"> <div class="d-flex align-items-center" [class.col-md-3]="horizontal">
<small *ngIf="hint" class="form-text text-muted" [innerHTML]="hint | safeHtml"></small> <label class="form-label mb-md-0" [for]="inputId">{{title}}</label>
<div class="invalid-feedback"> </div>
{{error}} <div [class.col-md-9]="horizontal">
<input #inputField type="text" class="form-control" [class.is-invalid]="error" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)" [disabled]="disabled">
<small *ngIf="hint" class="form-text text-muted" [innerHTML]="hint | safeHtml"></small>
<div class="invalid-feedback">
{{error}}
</div>
</div>
</div> </div>
</div> </div>

View File

@ -81,19 +81,23 @@
<li [ngbNavItem]="DocumentDetailNavIDs.Details"> <li [ngbNavItem]="DocumentDetailNavIDs.Details">
<a ngbNavLink i18n>Details</a> <a ngbNavLink i18n>Details</a>
<ng-template ngbNavContent> <ng-template ngbNavContent>
<div class="my-3">
<pngx-input-text #inputTitle i18n-title title="Title" formControlName="title" (keyup)="titleKeyUp($event)" [error]="error?.title"></pngx-input-text> <pngx-input-text #inputTitle i18n-title title="Title" formControlName="title" [horizontal]="true" (keyup)="titleKeyUp($event)" [error]="error?.title"></pngx-input-text>
<pngx-input-number i18n-title title="Archive serial number" [error]="error?.archive_serial_number" formControlName='archive_serial_number'></pngx-input-number> <pngx-input-number i18n-title title="Archive serial number" [error]="error?.archive_serial_number" [horizontal]="true" formControlName='archive_serial_number'></pngx-input-number>
<pngx-input-date i18n-title title="Date created" formControlName="created_date" [suggestions]="suggestions?.dates" [showFilter]="true" (filterDocuments)="filterDocuments($event)" <pngx-input-date i18n-title title="Date created" formControlName="created_date" [suggestions]="suggestions?.dates" [showFilter]="true" [horizontal]="true" (filterDocuments)="filterDocuments($event)"
[error]="error?.created_date"></pngx-input-date> [error]="error?.created_date"></pngx-input-date>
<pngx-input-select [items]="correspondents" i18n-title title="Correspondent" formControlName="correspondent" [allowNull]="true" [showFilter]="true" (filterDocuments)="filterDocuments($event)" <pngx-input-select [items]="correspondents" i18n-title title="Correspondent" formControlName="correspondent" [allowNull]="true" [showFilter]="true" [horizontal]="true" (filterDocuments)="filterDocuments($event)"
(createNew)="createCorrespondent($event)" [suggestions]="suggestions?.correspondents" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Correspondent }"></pngx-input-select> (createNew)="createCorrespondent($event)" [suggestions]="suggestions?.correspondents" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Correspondent }"></pngx-input-select>
<pngx-input-select [items]="documentTypes" i18n-title title="Document type" formControlName="document_type" [allowNull]="true" [showFilter]="true" (filterDocuments)="filterDocuments($event)" <pngx-input-select [items]="documentTypes" i18n-title title="Document type" formControlName="document_type" [allowNull]="true" [showFilter]="true" [horizontal]="true" (filterDocuments)="filterDocuments($event)"
(createNew)="createDocumentType($event)" [suggestions]="suggestions?.document_types" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.DocumentType }"></pngx-input-select> (createNew)="createDocumentType($event)" [suggestions]="suggestions?.document_types" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.DocumentType }"></pngx-input-select>
<pngx-input-select [items]="storagePaths" i18n-title title="Storage path" formControlName="storage_path" [allowNull]="true" [showFilter]="true" (filterDocuments)="filterDocuments($event)" <pngx-input-select [items]="storagePaths" i18n-title title="Storage path" formControlName="storage_path" [allowNull]="true" [showFilter]="true" [horizontal]="true" (filterDocuments)="filterDocuments($event)"
(createNew)="createStoragePath($event)" [suggestions]="suggestions?.storage_paths" i18n-placeholder placeholder="Default" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.StoragePath }"></pngx-input-select> (createNew)="createStoragePath($event)" [suggestions]="suggestions?.storage_paths" i18n-placeholder placeholder="Default" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.StoragePath }"></pngx-input-select>
<pngx-input-tags formControlName="tags" [suggestions]="suggestions?.tags" [showFilter]="true" (filterDocuments)="filterDocuments($event)" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Tag }"></pngx-input-tags> <pngx-input-tags formControlName="tags" [suggestions]="suggestions?.tags" [showFilter]="true" [horizontal]="true" (filterDocuments)="filterDocuments($event)" *pngxIfPermissions="{ action: PermissionAction.View, type: PermissionType.Tag }"></pngx-input-tags>
<ng-container *ngFor="let field of customFields">
<pngx-input-text [formControlName]="'custom-field-' + field.id" *ngIf="field.type === PaperlessCustomFieldDataType.String" [title]="field.name" [horizontal]="true"></pngx-input-text>
<pngx-input-date [formControlName]="'custom-field-' + field.id" *ngIf="field.type === PaperlessCustomFieldDataType.Date" [title]="field.name" [horizontal]="true"></pngx-input-date>
</ng-container>
</div>
</ng-template> </ng-template>
</li> </li>

View File

@ -63,7 +63,11 @@ import { EditDialogMode } from '../common/edit-dialog/edit-dialog.component'
import { ObjectWithId } from 'src/app/data/object-with-id' import { ObjectWithId } from 'src/app/data/object-with-id'
import { FilterRule } from 'src/app/data/filter-rule' import { FilterRule } from 'src/app/data/filter-rule'
import { ISODateAdapter } from 'src/app/utils/ngb-iso-date-adapter' import { ISODateAdapter } from 'src/app/utils/ngb-iso-date-adapter'
import { ShareLinksDropdownComponent } from '../common/share-links-dropdown/share-links-dropdown.component' import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
import {
PaperlessCustomField,
PaperlessCustomFieldDataType,
} from 'src/app/data/paperless-custom-field'
enum DocumentDetailNavIDs { enum DocumentDetailNavIDs {
Details = 1, Details = 1,
@ -135,6 +139,9 @@ export class DocumentDetailComponent
ogDate: Date ogDate: Date
public readonly PaperlessCustomFieldDataType = PaperlessCustomFieldDataType
customFields: PaperlessCustomField[]
@ViewChild('nav') nav: NgbNav @ViewChild('nav') nav: NgbNav
@ViewChild('pdfPreview') set pdfPreview(element) { @ViewChild('pdfPreview') set pdfPreview(element) {
// this gets called when compontent added or removed from DOM // this gets called when compontent added or removed from DOM
@ -166,7 +173,8 @@ export class DocumentDetailComponent
private storagePathService: StoragePathService, private storagePathService: StoragePathService,
private permissionsService: PermissionsService, private permissionsService: PermissionsService,
private userService: UserService, private userService: UserService,
private http: HttpClient private http: HttpClient,
private customFieldsService: CustomFieldsService
) { ) {
super() super()
} }
@ -385,6 +393,28 @@ export class DocumentDetailComponent
updateComponent(doc: PaperlessDocument) { updateComponent(doc: PaperlessDocument) {
this.document = doc this.document = doc
this.requiresPassword = false this.requiresPassword = false
this.customFieldsService
.getFields(doc.id)
.pipe(first())
.subscribe({
next: (fields) => {
this.customFields = fields
this.customFields.forEach((field) => {
this.documentForm.addControl(
`custom-field-${field.id}`,
new FormControl(field.data)
)
})
this.store.next(this.documentForm.value)
console.log(fields)
},
error: (error) => {
this.toastService.showError(
$localize`Error retrieving custom fields`,
error
)
},
})
this.documentsService this.documentsService
.getMetadata(doc.id) .getMetadata(doc.id)
.pipe(first()) .pipe(first())
@ -511,6 +541,11 @@ export class DocumentDetailComponent
} }
this.title = doc.title this.title = doc.title
this.documentForm.patchValue(doc) this.documentForm.patchValue(doc)
this.customFields.forEach((field) => {
this.documentForm
.get(`custom-field-${field.id}`)
.patchValue(field.data)
})
this.openDocumentService.setDirty(doc, false) this.openDocumentService.setDirty(doc, false)
}, },
error: () => { error: () => {

View File

@ -0,0 +1,16 @@
import { ObjectWithId } from './object-with-id'
export enum PaperlessCustomFieldDataType {
String = 'string',
Url = 'url',
Date = 'date',
}
export interface PaperlessCustomField extends ObjectWithId {
type: PaperlessCustomFieldDataType
name: string
data: any
document: number // PaperlessDocument
created?: Date
user: number // PaperlessUser
}

View File

@ -0,0 +1,40 @@
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'
@Injectable({
providedIn: 'root',
})
export class CustomFieldsService extends AbstractPaperlessService<PaperlessCustomField> {
constructor(http: HttpClient) {
super(http, 'documents')
}
getFields(documentId: number): Observable<PaperlessCustomField[]> {
return this.http.get<PaperlessCustomField[]>(
this.getResourceUrl(documentId, 'custom_metadata')
)
}
addField(
documentId: number,
field: PaperlessCustomField
): Observable<PaperlessCustomField[]> {
return this.http.post<PaperlessCustomField[]>(
this.getResourceUrl(documentId, 'custom_metadata'),
field
)
}
// deleteField(
// documentId: number,
// fieldId: number
// ): Observable<PaperlessCustomField[]> {
// return this.http.delete<PaperlessCustomField[]>(
// this.getResourceUrl(documentId, 'custom_metadata'),
// { params: new HttpParams({ fromString: `id=${fieldId}` }) }
// )
// }
}