Feature: Implement custom fields for documents (#4502)

Adds custom fields of certain data types, attachable to documents and searchable

Co-Authored-By: Trenton H <797416+stumpylog@users.noreply.github.com>
This commit is contained in:
shamoon
2023-11-05 17:26:51 -08:00
parent 1b02046ba7
commit a792bf1ca1
67 changed files with 3199 additions and 421 deletions

View File

@@ -46,6 +46,8 @@ export const FILTER_OWNER_ANY = 33
export const FILTER_OWNER_ISNULL = 34
export const FILTER_OWNER_DOES_NOT_INCLUDE = 35
export const FILTER_CUSTOM_FIELDS = 36
export const FILTER_RULE_TYPES: FilterRuleType[] = [
{
id: FILTER_TITLE,
@@ -271,6 +273,12 @@ export const FILTER_RULE_TYPES: FilterRuleType[] = [
datatype: 'number',
multi: true,
},
{
id: FILTER_CUSTOM_FIELDS,
filtervar: 'custom_fields__icontains',
datatype: 'string',
multi: false,
},
]
export interface FilterRuleType {

View File

@@ -0,0 +1,9 @@
import { ObjectWithId } from './object-with-id'
import { PaperlessCustomField } from './paperless-custom-field'
export interface PaperlessCustomFieldInstance extends ObjectWithId {
document: number // PaperlessDocument
field: number // PaperlessCustomField
created: Date
value?: any
}

View File

@@ -0,0 +1,48 @@
import { ObjectWithId } from './object-with-id'
export enum PaperlessCustomFieldDataType {
String = 'string',
Url = 'url',
Date = 'date',
Boolean = 'boolean',
Integer = 'integer',
Float = 'float',
Monetary = 'monetary',
}
export const DATA_TYPE_LABELS = [
{
id: PaperlessCustomFieldDataType.Boolean,
name: $localize`Boolean`,
},
{
id: PaperlessCustomFieldDataType.Date,
name: $localize`Date`,
},
{
id: PaperlessCustomFieldDataType.Integer,
name: $localize`Integer`,
},
{
id: PaperlessCustomFieldDataType.Float,
name: $localize`Number`,
},
{
id: PaperlessCustomFieldDataType.Monetary,
name: $localize`Monetary`,
},
{
id: PaperlessCustomFieldDataType.String,
name: $localize`Text`,
},
{
id: PaperlessCustomFieldDataType.Url,
name: $localize`Url`,
},
]
export interface PaperlessCustomField extends ObjectWithId {
data_type: PaperlessCustomFieldDataType
name: string
created?: Date
}

View File

@@ -5,6 +5,7 @@ import { Observable } from 'rxjs'
import { PaperlessStoragePath } from './paperless-storage-path'
import { ObjectWithPermissions } from './object-with-permissions'
import { PaperlessDocumentNote } from './paperless-document-note'
import { PaperlessCustomFieldInstance } from './paperless-custom-field-instance'
export interface SearchHit {
score?: number
@@ -58,4 +59,6 @@ export interface PaperlessDocument extends ObjectWithPermissions {
notes?: PaperlessDocumentNote[]
__search_hit__?: SearchHit
custom_fields?: PaperlessCustomFieldInstance[]
}