From 2cd993204c05160af5409759ec1b9096f72c2adf Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 7 Jan 2024 00:20:50 -0800 Subject: [PATCH] Save work on app title --- docs/configuration.md | 12 ++++--- .../app-frame/app-frame.component.html | 16 ++++++++-- .../app-frame/app-frame.component.scss | 11 +++++-- .../app-frame/app-frame.component.ts | 4 +++ src-ui/src/app/data/paperless-config.ts | 9 ++++++ src-ui/src/app/data/ui-settings.ts | 6 ++++ src/documents/views.py | 9 ++++++ src/paperless/config.py | 32 ++++++++++++++++--- ...0002_applicationconfiguration_app_title.py | 23 +++++++++++++ src/paperless/models.py | 7 ++++ src/paperless/settings.py | 2 ++ 11 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 src/paperless/migrations/0002_applicationconfiguration_app_title.py diff --git a/docs/configuration.md b/docs/configuration.md index 5ca6bf701..ff2cdcf3b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -4,9 +4,9 @@ Paperless provides a wide range of customizations. Depending on how you run paperless, these settings have to be defined in different places. Certain configuration options may be set via the UI. This currently includes -common [OCR](#ocr) related settings. If set, these will take preference over the -settings via environment variables. If not set, the environment setting or applicable -default will be utilized instead. +common [OCR](#ocr) related settings and some frontend settings. If set, these will take +preference over the settings via environment variables. If not set, the environment setting +or applicable default will be utilized instead. - If you run paperless on docker, `paperless.conf` is not used. Rather, configure paperless by copying necessary options to @@ -1329,7 +1329,11 @@ started by the container. You can read more about this in the [advanced documentation](advanced_usage.md#celery-monitoring). -## Update Checking {#update-checking} +## Frontend Settings + +#### [`PAPERLESS_APP_TITLE=`](#PAPERLESS_APP_TITLE) {#PAPERLESS_APP_TITLE} + +: If set, overrides the default name "Paperless-ngx" #### [`PAPERLESS_ENABLE_UPDATE_CHECK=`](#PAPERLESS_ENABLE_UPDATE_CHECK) {#PAPERLESS_ENABLE_UPDATE_CHECK} diff --git a/src-ui/src/app/components/app-frame/app-frame.component.html b/src-ui/src/app/components/app-frame/app-frame.component.html index 32241333e..ba21c8bac 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.html +++ b/src-ui/src/app/components/app-frame/app-frame.component.html @@ -4,15 +4,25 @@ (click)="isMenuCollapsed = !isMenuCollapsed"> - - Paperless-ngx +
+ @if (customAppTitle?.length) { +
+ {{customAppTitle}} + +
+ } @else { + Paperless-ngx + } +
diff --git a/src-ui/src/app/components/app-frame/app-frame.component.scss b/src-ui/src/app/components/app-frame/app-frame.component.scss index f8a32ecfb..5dcac760f 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.scss +++ b/src-ui/src/app/components/app-frame/app-frame.component.scss @@ -217,9 +217,16 @@ main { */ .navbar-brand { - padding-top: 0.75rem; - padding-bottom: 0.75rem; font-size: 1rem; + + .flex-column { + padding: 0.15rem 0; + } + + .byline { + font-size: 0.5rem; + letter-spacing: 0.1rem; + } } @media screen and (min-width: 768px) { diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts index 0e877b7ce..cfc9740a4 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.ts @@ -102,6 +102,10 @@ export class AppFrameComponent }, 200) // slightly longer than css animation for slim sidebar } + get customAppTitle(): string { + return this.settingsService.get(SETTINGS_KEYS.APP_TITLE) + } + get slimSidebarEnabled(): boolean { return this.settingsService.get(SETTINGS_KEYS.SLIM_SIDEBAR) } diff --git a/src-ui/src/app/data/paperless-config.ts b/src-ui/src/app/data/paperless-config.ts index dd9dfdb33..4f4515f0b 100644 --- a/src-ui/src/app/data/paperless-config.ts +++ b/src-ui/src/app/data/paperless-config.ts @@ -47,6 +47,7 @@ export enum ConfigOptionType { export const ConfigCategory = { OCR: $localize`OCR Settings`, + Frontend: $localize`Frontend Settings`, } export interface ConfigOption { @@ -164,6 +165,13 @@ export const PaperlessConfigOptions: ConfigOption[] = [ config_key: 'PAPERLESS_OCR_USER_ARGS', category: ConfigCategory.OCR, }, + { + key: 'app_title', + title: $localize`Application Title`, + type: ConfigOptionType.String, + config_key: 'PAPERLESS_APP_TITLE', + category: ConfigCategory.Frontend, + }, ] export interface PaperlessConfig extends ObjectWithId { @@ -180,4 +188,5 @@ export interface PaperlessConfig extends ObjectWithId { max_image_pixels: number color_conversion_strategy: ColorConvertConfig user_args: object + app_title: string } diff --git a/src-ui/src/app/data/ui-settings.ts b/src-ui/src/app/data/ui-settings.ts index 329fc6aa0..f5403acee 100644 --- a/src-ui/src/app/data/ui-settings.ts +++ b/src-ui/src/app/data/ui-settings.ts @@ -14,6 +14,7 @@ export interface UiSetting { export const SETTINGS_KEYS = { LANGUAGE: 'language', + APP_TITLE: 'app_title', // maintain old general-settings: for backwards compatibility BULK_EDIT_CONFIRMATION_DIALOGS: 'general-settings:bulk-edit:confirmation-dialogs', @@ -194,4 +195,9 @@ export const SETTINGS: UiSetting[] = [ type: 'array', default: [], }, + { + key: SETTINGS_KEYS.APP_TITLE, + type: 'string', + default: '', + }, ] diff --git a/src/documents/views.py b/src/documents/views.py index d6b90cbfd..b7dbe610f 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -120,6 +120,7 @@ from documents.serialisers import WorkflowTriggerSerializer from documents.signals import document_updated from documents.tasks import consume_file from paperless import version +from paperless.config import FrontendConfig from paperless.db import GnuPG from paperless.views import StandardPagination @@ -1164,6 +1165,14 @@ class UiSettingsView(GenericAPIView): ui_settings["update_checking"] = { "backend_setting": settings.ENABLE_UPDATE_CHECK, } + + frontend_config = FrontendConfig() + + if settings.APP_TITLE is not None: + ui_settings["app_title"] = settings.APP_TITLE + if frontend_config.app_title is not None and len(frontend_config.app_title) > 0: + ui_settings["app_title"] = frontend_config.app_title + user_resp = { "id": user.id, "username": user.username, diff --git a/src/paperless/config.py b/src/paperless/config.py index 55d6dc3d3..98668d56f 100644 --- a/src/paperless/config.py +++ b/src/paperless/config.py @@ -8,13 +8,11 @@ from paperless.models import ApplicationConfiguration @dataclasses.dataclass -class OutputTypeConfig: +class BaseConfig: """ Almost all parsers care about the chosen PDF output format """ - output_type: str = dataclasses.field(init=False) - @staticmethod def _get_config_instance() -> ApplicationConfiguration: app_config = ApplicationConfiguration.objects.all().first() @@ -25,7 +23,19 @@ class OutputTypeConfig: return app_config def __post_init__(self) -> None: - app_config = self._get_config_instance() + return self._get_config_instance() + + +@dataclasses.dataclass +class OutputTypeConfig(BaseConfig): + """ + Almost all parsers care about the chosen PDF output format + """ + + output_type: str = dataclasses.field(init=False) + + def __post_init__(self) -> None: + app_config = super.__post_init__() self.output_type = app_config.output_type or settings.OCR_OUTPUT_TYPE @@ -86,3 +96,17 @@ class OcrConfig(OutputTypeConfig): user_args = {} self.user_args = user_args + + +@dataclasses.dataclass +class FrontendConfig(BaseConfig): + """ + Frontend application settings that require global scope + """ + + app_title: str = dataclasses.field(init=False) + + def __post_init__(self) -> None: + app_config = super().__post_init__() + + self.app_title = app_config.app_title or None diff --git a/src/paperless/migrations/0002_applicationconfiguration_app_title.py b/src/paperless/migrations/0002_applicationconfiguration_app_title.py new file mode 100644 index 000000000..09f8885c9 --- /dev/null +++ b/src/paperless/migrations/0002_applicationconfiguration_app_title.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.8 on 2024-01-07 07:31 + +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + dependencies = [ + ("paperless", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="applicationconfiguration", + name="app_title", + field=models.CharField( + blank=True, + max_length=48, + null=True, + verbose_name="Application Title", + ), + ), + ] diff --git a/src/paperless/models.py b/src/paperless/models.py index 133668dd6..d7bf14f0b 100644 --- a/src/paperless/models.py +++ b/src/paperless/models.py @@ -166,6 +166,13 @@ class ApplicationConfiguration(AbstractSingletonModel): null=True, ) + app_title = models.CharField( + verbose_name=_("Application Title"), + null=True, + blank=True, + max_length=48, + ) + class Meta: verbose_name = _("paperless application settings") diff --git a/src/paperless/settings.py b/src/paperless/settings.py index e13518ce3..cddaf4c27 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -999,6 +999,8 @@ ENABLE_UPDATE_CHECK = os.getenv("PAPERLESS_ENABLE_UPDATE_CHECK", "default") if ENABLE_UPDATE_CHECK != "default": ENABLE_UPDATE_CHECK = __get_boolean("PAPERLESS_ENABLE_UPDATE_CHECK") +APP_TITLE = os.getenv("PAPERLESS_APP_TITLE", None) + ############################################################################### # Machine Learning # ###############################################################################