Feature: Allow setting backend configuration settings via the UI (#5126)

* Saving some start on this

* At least partially working for the tesseract parser

* Problems with migration testing need to figure out

* Work around that error

* Fixes max m_pixels

* Moving the settings to main paperless application

* Starting some consumer options

* More fixes and work

* Fixes these last tests

* Fix max_length on OcrSettings.mode field

* Fix all fields on Common & Ocr settings serializers

* Umbrellla config view

* Revert "Umbrellla config view"

This reverts commit fbaf9f4be30f89afeb509099180158a3406416a5.

* Updates to use a single configuration object for all settings

* Squashed commit of the following:

commit 8a0a49dd57
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Tue Dec 19 23:02:47 2023 -0800

    Fix formatting

commit 66b2d90c50
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Tue Dec 19 22:36:35 2023 -0800

    Refactor frontend data models

commit 5723bd8dd8
Author: Adam Bogdał <adam@bogdal.pl>
Date:   Wed Dec 20 01:17:43 2023 +0100

    Fix: speed up admin panel for installs with a large number of documents (#5052)

commit 9b08ce1761
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Tue Dec 19 15:18:51 2023 -0800

    Update PULL_REQUEST_TEMPLATE.md

commit a6248bec2d
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Tue Dec 19 15:02:05 2023 -0800

    Chore: Update Angular to v17 (#4980)

commit b1f6f52486
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Tue Dec 19 13:53:56 2023 -0800

    Fix: Dont allow null custom_fields property via API (#5063)

commit 638d9970fd
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Tue Dec 19 13:43:50 2023 -0800

    Enhancement: symmetric document links (#4907)

commit 5e8de4c1da
Author: shamoon <4887959+shamoon@users.noreply.github.com>
Date:   Tue Dec 19 12:45:04 2023 -0800

    Enhancement: shared icon & shared by me filter (#4859)

commit 088bad9030
Author: Trenton H <797416+stumpylog@users.noreply.github.com>
Date:   Tue Dec 19 12:04:03 2023 -0800

    Bulk updates all the backend libraries (#5061)

* Saving some work on frontend config

* Very basic but dynamically-generated config form

* Saving work on slightly less ugly frontend config

* JSON validation for user_args field

* Fully dynamic config form

* Adds in some additional validators for a nicer error message

* Cleaning up the testing and coverage more

* Reverts unintentional change

* Adds documentation about the settings and the precedence

* Couple more commenting and style fixes

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
Trenton H
2023-12-29 15:42:56 -08:00
committed by GitHub
parent 718eaf04d4
commit c8a62715ec
41 changed files with 1570 additions and 119 deletions

View File

@@ -0,0 +1,183 @@
import { ObjectWithId } from './object-with-id'
// see /src/paperless/models.py
export enum OutputTypeConfig {
PDF = 'pdf',
PDF_A = 'pdfa',
PDF_A1 = 'pdfa-1',
PDF_A2 = 'pdfa-2',
PDF_A3 = 'pdfa-3',
}
export enum ModeConfig {
SKIP = 'skip',
REDO = 'redo',
FORCE = 'force',
SKIP_NO_ARCHIVE = 'skip_noarchive',
}
export enum ArchiveFileConfig {
NEVER = 'never',
WITH_TEXT = 'with_text',
ALWAYS = 'always',
}
export enum CleanConfig {
CLEAN = 'clean',
FINAL = 'clean-final',
NONE = 'none',
}
export enum ColorConvertConfig {
UNCHANGED = 'LeaveColorUnchanged',
RGB = 'RGB',
INDEPENDENT = 'UseDeviceIndependentColor',
GRAY = 'Gray',
CMYK = 'CMYK',
}
export enum ConfigOptionType {
String = 'string',
Number = 'number',
Select = 'select',
Boolean = 'boolean',
JSON = 'json',
}
export const ConfigCategory = {
OCR: $localize`OCR Settings`,
}
export interface ConfigOption {
key: string
title: string
type: ConfigOptionType
choices?: Array<{ id: string; name: string }>
config_key?: string
category: string
}
function mapToItems(enumObj: Object): Array<{ id: string; name: string }> {
return Object.keys(enumObj).map((key) => {
return {
id: enumObj[key],
name: enumObj[key],
}
})
}
export const PaperlessConfigOptions: ConfigOption[] = [
{
key: 'output_type',
title: $localize`Output Type`,
type: ConfigOptionType.Select,
choices: mapToItems(OutputTypeConfig),
config_key: 'PAPERLESS_OCR_OUTPUT_TYPE',
category: ConfigCategory.OCR,
},
{
key: 'language',
title: $localize`Language`,
type: ConfigOptionType.String,
config_key: 'PAPERLESS_OCR_LANGUAGE',
category: ConfigCategory.OCR,
},
{
key: 'pages',
title: $localize`Pages`,
type: ConfigOptionType.Number,
config_key: 'PAPERLESS_OCR_PAGES',
category: ConfigCategory.OCR,
},
{
key: 'mode',
title: $localize`Mode`,
type: ConfigOptionType.Select,
choices: mapToItems(ModeConfig),
config_key: 'PAPERLESS_OCR_MODE',
category: ConfigCategory.OCR,
},
{
key: 'skip_archive_file',
title: $localize`Skip Archive File`,
type: ConfigOptionType.Select,
choices: mapToItems(ArchiveFileConfig),
config_key: 'PAPERLESS_OCR_SKIP_ARCHIVE_FILE',
category: ConfigCategory.OCR,
},
{
key: 'image_dpi',
title: $localize`Image DPI`,
type: ConfigOptionType.Number,
config_key: 'PAPERLESS_OCR_IMAGE_DPI',
category: ConfigCategory.OCR,
},
{
key: 'unpaper_clean',
title: $localize`Clean`,
type: ConfigOptionType.Select,
choices: mapToItems(CleanConfig),
config_key: 'PAPERLESS_OCR_CLEAN',
category: ConfigCategory.OCR,
},
{
key: 'deskew',
title: $localize`Deskew`,
type: ConfigOptionType.Boolean,
config_key: 'PAPERLESS_OCR_DESKEW',
category: ConfigCategory.OCR,
},
{
key: 'rotate_pages',
title: $localize`Rotate Pages`,
type: ConfigOptionType.Boolean,
config_key: 'PAPERLESS_OCR_ROTATE_PAGES',
category: ConfigCategory.OCR,
},
{
key: 'rotate_pages_threshold',
title: $localize`Rotate Pages Threshold`,
type: ConfigOptionType.Number,
config_key: 'PAPERLESS_OCR_ROTATE_PAGES_THRESHOLD',
category: ConfigCategory.OCR,
},
{
key: 'max_image_pixels',
title: $localize`Max Image Pixels`,
type: ConfigOptionType.Number,
config_key: 'PAPERLESS_OCR_IMAGE_DPI',
category: ConfigCategory.OCR,
},
{
key: 'color_conversion_strategy',
title: $localize`Color Conversion Strategy`,
type: ConfigOptionType.Select,
choices: mapToItems(ColorConvertConfig),
config_key: 'PAPERLESS_OCR_COLOR_CONVERSION_STRATEGY',
category: ConfigCategory.OCR,
},
{
key: 'user_args',
title: $localize`OCR Arguments`,
type: ConfigOptionType.JSON,
config_key: 'PAPERLESS_OCR_USER_ARGS',
category: ConfigCategory.OCR,
},
]
export interface PaperlessConfig extends ObjectWithId {
output_type: OutputTypeConfig
pages: number
language: string
mode: ModeConfig
skip_archive_file: ArchiveFileConfig
image_dpi: number
unpaper_clean: CleanConfig
deskew: boolean
rotate_pages: boolean
rotate_pages_threshold: number
max_image_pixels: number
color_conversion_strategy: ColorConvertConfig
user_args: object
}