PaperlessUiSettings data object

This commit is contained in:
Michael Shamoon 2022-05-09 11:01:45 -07:00
parent de89f75707
commit 96f86adfb8
10 changed files with 143 additions and 133 deletions

View File

@ -1,4 +1,5 @@
import { SettingsService, SETTINGS_KEYS } from './services/settings.service' import { SettingsService } from './services/settings.service'
import { SETTINGS_KEYS } from './data/paperless-uisettings'
import { Component, OnDestroy, OnInit } from '@angular/core' import { Component, OnDestroy, OnInit } from '@angular/core'
import { Router } from '@angular/router' import { Router } from '@angular/router'
import { Subscription } from 'rxjs' import { Subscription } from 'rxjs'

View File

@ -18,10 +18,7 @@ import { DocumentTypeEditDialogComponent } from '../common/edit-dialog/document-
import { PDFDocumentProxy } from 'ng2-pdf-viewer' import { PDFDocumentProxy } from 'ng2-pdf-viewer'
import { ToastService } from 'src/app/services/toast.service' import { ToastService } from 'src/app/services/toast.service'
import { TextComponent } from '../common/input/text/text.component' import { TextComponent } from '../common/input/text/text.component'
import { import { SettingsService } from 'src/app/services/settings.service'
SettingsService,
SETTINGS_KEYS,
} from 'src/app/services/settings.service'
import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms' import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms'
import { Observable, Subject, BehaviorSubject } from 'rxjs' import { Observable, Subject, BehaviorSubject } from 'rxjs'
import { import {
@ -36,6 +33,7 @@ import { PaperlessDocumentSuggestions } from 'src/app/data/paperless-document-su
import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type' import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type'
import { normalizeDateStr } from 'src/app/utils/date' import { normalizeDateStr } from 'src/app/utils/date'
import { QueryParamsService } from 'src/app/services/query-params.service' import { QueryParamsService } from 'src/app/services/query-params.service'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
@Component({ @Component({
selector: 'app-document-detail', selector: 'app-document-detail',

View File

@ -19,12 +19,10 @@ import {
} from '../../common/filterable-dropdown/filterable-dropdown.component' } from '../../common/filterable-dropdown/filterable-dropdown.component'
import { ToggleableItemState } from '../../common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component' import { ToggleableItemState } from '../../common/filterable-dropdown/toggleable-dropdown-button/toggleable-dropdown-button.component'
import { MatchingModel } from 'src/app/data/matching-model' import { MatchingModel } from 'src/app/data/matching-model'
import { import { SettingsService } from 'src/app/services/settings.service'
SettingsService,
SETTINGS_KEYS,
} from 'src/app/services/settings.service'
import { ToastService } from 'src/app/services/toast.service' import { ToastService } from 'src/app/services/toast.service'
import { saveAs } from 'file-saver' import { saveAs } from 'file-saver'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
@Component({ @Component({
selector: 'app-bulk-editor', selector: 'app-bulk-editor',

View File

@ -8,12 +8,12 @@ import {
} from '@angular/core' } from '@angular/core'
import { PaperlessDocument } from 'src/app/data/paperless-document' import { PaperlessDocument } from 'src/app/data/paperless-document'
import { DocumentService } from 'src/app/services/rest/document.service' import { DocumentService } from 'src/app/services/rest/document.service'
import { import { SettingsService } from 'src/app/services/settings.service'
SettingsService,
SETTINGS_KEYS,
} from 'src/app/services/settings.service'
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' import { NgbPopover } from '@ng-bootstrap/ng-bootstrap'
import { OpenDocumentsService } from 'src/app/services/open-documents.service' import { OpenDocumentsService } from 'src/app/services/open-documents.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { FILTER_FULLTEXT_MORELIKE } from 'src/app/data/filter-rule-type'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
@Component({ @Component({
selector: 'app-document-card-large', selector: 'app-document-card-large',

View File

@ -9,12 +9,10 @@ import {
import { map } from 'rxjs/operators' import { map } from 'rxjs/operators'
import { PaperlessDocument } from 'src/app/data/paperless-document' import { PaperlessDocument } from 'src/app/data/paperless-document'
import { DocumentService } from 'src/app/services/rest/document.service' import { DocumentService } from 'src/app/services/rest/document.service'
import { import { SettingsService } from 'src/app/services/settings.service'
SettingsService,
SETTINGS_KEYS,
} from 'src/app/services/settings.service'
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' import { NgbPopover } from '@ng-bootstrap/ng-bootstrap'
import { OpenDocumentsService } from 'src/app/services/open-documents.service' import { OpenDocumentsService } from 'src/app/services/open-documents.service'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
@Component({ @Component({
selector: 'app-document-card-small', selector: 'app-document-card-small',

View File

@ -13,11 +13,11 @@ import { SavedViewService } from 'src/app/services/rest/saved-view.service'
import { import {
LanguageOption, LanguageOption,
SettingsService, SettingsService,
SETTINGS_KEYS,
} from 'src/app/services/settings.service' } from 'src/app/services/settings.service'
import { ToastService } from 'src/app/services/toast.service' import { ToastService } from 'src/app/services/toast.service'
import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms' import { dirtyCheck, DirtyComponent } from '@ngneat/dirty-check-forms'
import { Observable, Subscription, BehaviorSubject, first } from 'rxjs' import { Observable, Subscription, BehaviorSubject, first } from 'rxjs'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',

View File

@ -0,0 +1,117 @@
export interface PaperlessUiSettings {
user_id: number
username: string
display_name: string
settings: Object
}
export interface PaperlessUiSetting {
key: string
type: string
default: any
}
export const SETTINGS_KEYS = {
LANGUAGE: 'language',
// maintain old general-settings: for backwards compatibility
BULK_EDIT_CONFIRMATION_DIALOGS:
'general-settings:bulk-edit:confirmation-dialogs',
BULK_EDIT_APPLY_ON_CLOSE: 'general-settings:bulk-edit:apply-on-close',
DOCUMENT_LIST_SIZE: 'general-settings:documentListSize',
DARK_MODE_USE_SYSTEM: 'general-settings:dark-mode:use-system',
DARK_MODE_ENABLED: 'general-settings:dark-mode:enabled',
DARK_MODE_THUMB_INVERTED: 'general-settings:dark-mode:thumb-inverted',
THEME_COLOR: 'general-settings:theme:color',
USE_NATIVE_PDF_VIEWER: 'general-settings:document-details:native-pdf-viewer',
DATE_LOCALE: 'general-settings:date-display:date-locale',
DATE_FORMAT: 'general-settings:date-display:date-format',
NOTIFICATIONS_CONSUMER_NEW_DOCUMENT:
'general-settings:notifications:consumer-new-documents',
NOTIFICATIONS_CONSUMER_SUCCESS:
'general-settings:notifications:consumer-success',
NOTIFICATIONS_CONSUMER_FAILED:
'general-settings:notifications:consumer-failed',
NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD:
'general-settings:notifications:consumer-suppress-on-dashboard',
}
export const SETTINGS: PaperlessUiSetting[] = [
{
key: SETTINGS_KEYS.LANGUAGE,
type: 'string',
default: '',
},
{
key: SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE,
type: 'boolean',
default: false,
},
{
key: SETTINGS_KEYS.DOCUMENT_LIST_SIZE,
type: 'number',
default: 50,
},
{
key: SETTINGS_KEYS.DARK_MODE_USE_SYSTEM,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.DARK_MODE_ENABLED,
type: 'boolean',
default: false,
},
{
key: SETTINGS_KEYS.DARK_MODE_THUMB_INVERTED,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.THEME_COLOR,
type: 'string',
default: '',
},
{
key: SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER,
type: 'boolean',
default: false,
},
{
key: SETTINGS_KEYS.DATE_LOCALE,
type: 'string',
default: '',
},
{
key: SETTINGS_KEYS.DATE_FORMAT,
type: 'string',
default: 'mediumDate',
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_FAILED,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD,
type: 'boolean',
default: true,
},
]

View File

@ -1,6 +1,7 @@
import { DatePipe } from '@angular/common' import { DatePipe } from '@angular/common'
import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core' import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core'
import { SettingsService, SETTINGS_KEYS } from '../services/settings.service' import { SETTINGS_KEYS } from '../data/paperless-uisettings'
import { SettingsService } from '../services/settings.service'
import { normalizeDateStr } from '../utils/date' import { normalizeDateStr } from '../utils/date'
const FORMAT_TO_ISO_FORMAT = { const FORMAT_TO_ISO_FORMAT = {

View File

@ -8,9 +8,10 @@ import {
} from '../data/filter-rule' } from '../data/filter-rule'
import { PaperlessDocument } from '../data/paperless-document' import { PaperlessDocument } from '../data/paperless-document'
import { PaperlessSavedView } from '../data/paperless-saved-view' import { PaperlessSavedView } from '../data/paperless-saved-view'
import { SETTINGS_KEYS } from '../data/paperless-uisettings'
import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys' import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys'
import { DocumentService, DOCUMENT_SORT_FIELDS } from './rest/document.service' import { DocumentService, DOCUMENT_SORT_FIELDS } from './rest/document.service'
import { SettingsService, SETTINGS_KEYS } from './settings.service' import { SettingsService } from './settings.service'
/** /**
* Captures the current state of the list view. * Captures the current state of the list view.

View File

@ -17,15 +17,13 @@ import {
hexToHsl, hexToHsl,
} from 'src/app/utils/color' } from 'src/app/utils/color'
import { environment } from 'src/environments/environment' import { environment } from 'src/environments/environment'
import { Results } from '../data/results' import {
PaperlessUiSettings,
SETTINGS,
SETTINGS_KEYS,
} from '../data/paperless-uisettings'
import { ToastService } from './toast.service' import { ToastService } from './toast.service'
export interface PaperlessSettings {
key: string
type: string
default: any
}
export interface LanguageOption { export interface LanguageOption {
code: string code: string
name: string name: string
@ -37,108 +35,6 @@ export interface LanguageOption {
dateInputFormat?: string dateInputFormat?: string
} }
export const SETTINGS_KEYS = {
LANGUAGE: 'language',
// maintain old general-settings: for backwards compatibility
BULK_EDIT_CONFIRMATION_DIALOGS:
'general-settings:bulk-edit:confirmation-dialogs',
BULK_EDIT_APPLY_ON_CLOSE: 'general-settings:bulk-edit:apply-on-close',
DOCUMENT_LIST_SIZE: 'general-settings:documentListSize',
DARK_MODE_USE_SYSTEM: 'general-settings:dark-mode:use-system',
DARK_MODE_ENABLED: 'general-settings:dark-mode:enabled',
DARK_MODE_THUMB_INVERTED: 'general-settings:dark-mode:thumb-inverted',
THEME_COLOR: 'general-settings:theme:color',
USE_NATIVE_PDF_VIEWER: 'general-settings:document-details:native-pdf-viewer',
DATE_LOCALE: 'general-settings:date-display:date-locale',
DATE_FORMAT: 'general-settings:date-display:date-format',
NOTIFICATIONS_CONSUMER_NEW_DOCUMENT:
'general-settings:notifications:consumer-new-documents',
NOTIFICATIONS_CONSUMER_SUCCESS:
'general-settings:notifications:consumer-success',
NOTIFICATIONS_CONSUMER_FAILED:
'general-settings:notifications:consumer-failed',
NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD:
'general-settings:notifications:consumer-suppress-on-dashboard',
}
const SETTINGS: PaperlessSettings[] = [
{
key: SETTINGS_KEYS.LANGUAGE,
type: 'string',
default: '',
},
{
key: SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE,
type: 'boolean',
default: false,
},
{
key: SETTINGS_KEYS.DOCUMENT_LIST_SIZE,
type: 'number',
default: 50,
},
{
key: SETTINGS_KEYS.DARK_MODE_USE_SYSTEM,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.DARK_MODE_ENABLED,
type: 'boolean',
default: false,
},
{
key: SETTINGS_KEYS.DARK_MODE_THUMB_INVERTED,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.THEME_COLOR,
type: 'string',
default: '',
},
{
key: SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER,
type: 'boolean',
default: false,
},
{
key: SETTINGS_KEYS.DATE_LOCALE,
type: 'string',
default: '',
},
{
key: SETTINGS_KEYS.DATE_FORMAT,
type: 'string',
default: 'mediumDate',
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_FAILED,
type: 'boolean',
default: true,
},
{
key: SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUPPRESS_ON_DASHBOARD,
type: 'boolean',
default: true,
},
]
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
@ -161,10 +57,10 @@ export class SettingsService {
} }
// this is called by the app initializer in app.module // this is called by the app initializer in app.module
public initializeSettings(): Observable<Results<any>> { public initializeSettings(): Observable<PaperlessUiSettings> {
let settings$ = this.http.get<Results<any>>(this.baseUrl) let settings$ = this.http.get<PaperlessUiSettings>(this.baseUrl)
settings$.pipe(first()).subscribe((response) => { settings$.pipe(first()).subscribe((uisettings) => {
Object.assign(this.settings, response['settings']) Object.assign(this.settings, uisettings.settings)
this.maybeMigrateSettings() this.maybeMigrateSettings()
}) })
return settings$ return settings$