From 75c8cd9967970a562d6e8fd41bedf39df1c5de94 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+nikonratm@users.noreply.github.com> Date: Sun, 27 Dec 2020 23:05:19 -0800 Subject: [PATCH 01/38] Dark mode settings logic --- src-ui/src/app/app.component.ts | 6 ++-- .../manage/settings/settings.component.html | 27 ++++++++++++----- .../manage/settings/settings.component.ts | 27 ++++++++++++++--- src-ui/src/app/data/storage-keys.ts | 8 +++-- .../src/app/services/app-view.service.spec.ts | 16 ++++++++++ src-ui/src/app/services/app-view.service.ts | 29 +++++++++++++++++++ 6 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 src-ui/src/app/services/app-view.service.spec.ts create mode 100644 src-ui/src/app/services/app-view.service.ts diff --git a/src-ui/src/app/app.component.ts b/src-ui/src/app/app.component.ts index 84c173a18..9cd9fb3ec 100644 --- a/src-ui/src/app/app.component.ts +++ b/src-ui/src/app/app.component.ts @@ -1,4 +1,5 @@ import { Component } from '@angular/core'; +import { AppViewService } from './services/app-view.service'; @Component({ selector: 'app-root', @@ -6,8 +7,9 @@ import { Component } from '@angular/core'; styleUrls: ['./app.component.scss'] }) export class AppComponent { - - constructor () { + + constructor (appViewService: AppViewService) { + appViewService.updateDarkModeSettings() } diff --git a/src-ui/src/app/components/manage/settings/settings.component.html b/src-ui/src/app/components/manage/settings/settings.component.html index 6c16cfaa8..9b999c0dc 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.html +++ b/src-ui/src/app/components/manage/settings/settings.component.html @@ -10,21 +10,34 @@ General settings -

Document list

- +

Appearance

+
Items per page
- + - + +
+
+ +
+
+ Dark mode +
+
+ +
+ + +
@@ -35,7 +48,7 @@
- +
@@ -61,7 +74,7 @@
No saved views defined.
- +
@@ -71,4 +84,4 @@
- \ No newline at end of file + diff --git a/src-ui/src/app/components/manage/settings/settings.component.ts b/src-ui/src/app/components/manage/settings/settings.component.ts index bec85e039..acb456f1c 100644 --- a/src-ui/src/app/components/manage/settings/settings.component.ts +++ b/src-ui/src/app/components/manage/settings/settings.component.ts @@ -1,10 +1,11 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, Renderer2 } from '@angular/core'; import { FormControl, FormGroup } from '@angular/forms'; import { PaperlessSavedView } from 'src/app/data/paperless-saved-view'; import { GENERAL_SETTINGS } from 'src/app/data/storage-keys'; import { DocumentListViewService } from 'src/app/services/document-list-view.service'; import { SavedViewService } from 'src/app/services/rest/saved-view.service'; import { Toast, ToastService } from 'src/app/services/toast.service'; +import { AppViewService } from 'src/app/services/app-view.service'; @Component({ selector: 'app-settings', @@ -17,17 +18,24 @@ export class SettingsComponent implements OnInit { settingsForm = new FormGroup({ 'documentListItemPerPage': new FormControl(+localStorage.getItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE) || GENERAL_SETTINGS.DOCUMENT_LIST_SIZE_DEFAULT), + 'darkModeUseSystem': new FormControl( + localStorage.getItem(GENERAL_SETTINGS.DARK_MODE_USE_SYSTEM) == undefined ? GENERAL_SETTINGS.DARK_MODE_USE_SYSTEM_DEFAULT : JSON.parse(localStorage.getItem(GENERAL_SETTINGS.DARK_MODE_USE_SYSTEM)) + ), + 'darkModeEnabled': new FormControl( + localStorage.getItem(GENERAL_SETTINGS.DARK_MODE_ENABLED) == undefined ? GENERAL_SETTINGS.DARK_MODE_ENABLED_DEFAULT : JSON.parse(localStorage.getItem(GENERAL_SETTINGS.DARK_MODE_ENABLED)) + ), 'savedViews': this.savedViewGroup }) + savedViews: PaperlessSavedView[] + constructor( public savedViewService: SavedViewService, private documentListViewService: DocumentListViewService, - private toastService: ToastService + private toastService: ToastService, + private appViewService: AppViewService ) { } - savedViews: PaperlessSavedView[] - ngOnInit() { this.savedViewService.listAll().subscribe(r => { this.savedViews = r.results @@ -50,9 +58,20 @@ export class SettingsComponent implements OnInit { }) } + toggleDarkModeSetting() { + if (this.settingsForm.value.darkModeUseSystem) { + (this.settingsForm.controls.darkModeEnabled as FormControl).disable() + } else { + (this.settingsForm.controls.darkModeEnabled as FormControl).enable() + } + } + private saveLocalSettings() { localStorage.setItem(GENERAL_SETTINGS.DOCUMENT_LIST_SIZE, this.settingsForm.value.documentListItemPerPage) + localStorage.setItem(GENERAL_SETTINGS.DARK_MODE_USE_SYSTEM, this.settingsForm.value.darkModeUseSystem) + localStorage.setItem(GENERAL_SETTINGS.DARK_MODE_ENABLED, (this.settingsForm.value.darkModeEnabled == true).toString()) this.documentListViewService.updatePageSize() + this.appViewService.updateDarkModeSettings() this.toastService.showToast(Toast.make("Information", $localize`Settings saved successfully.`)) } diff --git a/src-ui/src/app/data/storage-keys.ts b/src-ui/src/app/data/storage-keys.ts index 13b41d4a7..057d68d70 100644 --- a/src-ui/src/app/data/storage-keys.ts +++ b/src-ui/src/app/data/storage-keys.ts @@ -8,5 +8,9 @@ export const DOCUMENT_LIST_SERVICE = { export const GENERAL_SETTINGS = { DOCUMENT_LIST_SIZE: 'general-settings:documentListSize', - DOCUMENT_LIST_SIZE_DEFAULT: 50 -} \ No newline at end of file + DOCUMENT_LIST_SIZE_DEFAULT: 50, + DARK_MODE_USE_SYSTEM: 'general-settings:darkModeUseSystem', + DARK_MODE_USE_SYSTEM_DEFAULT: true, + DARK_MODE_ENABLED: 'general-settings:darkModeEnabled', + DARK_MODE_ENABLED_DEFAULT: false +} diff --git a/src-ui/src/app/services/app-view.service.spec.ts b/src-ui/src/app/services/app-view.service.spec.ts new file mode 100644 index 000000000..fc44ed3a4 --- /dev/null +++ b/src-ui/src/app/services/app-view.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { AppViewService } from './app-view.service'; + +describe('AppViewService', () => { + let service: AppViewService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(AppViewService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src-ui/src/app/services/app-view.service.ts b/src-ui/src/app/services/app-view.service.ts new file mode 100644 index 000000000..c6faa5603 --- /dev/null +++ b/src-ui/src/app/services/app-view.service.ts @@ -0,0 +1,29 @@ +import { Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core'; +import { DOCUMENT } from '@angular/common'; +import { GENERAL_SETTINGS } from 'src/app/data/storage-keys'; + +@Injectable({ + providedIn: 'root' +}) +export class AppViewService { + private renderer: Renderer2; + + constructor(rendererFactory: RendererFactory2, @Inject(DOCUMENT) private document) { + this.renderer = rendererFactory.createRenderer(null, null); + } + + updateDarkModeSettings() { + let darkModeUseSystem = JSON.parse(localStorage.getItem(GENERAL_SETTINGS.DARK_MODE_USE_SYSTEM)) && GENERAL_SETTINGS.DARK_MODE_USE_SYSTEM_DEFAULT + let darkModeEnabled = JSON.parse(localStorage.getItem(GENERAL_SETTINGS.DARK_MODE_ENABLED)) || GENERAL_SETTINGS.DARK_MODE_ENABLED_DEFAULT + + if (darkModeUseSystem) { + this.renderer.addClass(this.document.body, 'dark-mode-preferred') + this.renderer.removeClass(this.document.body, 'dark-mode') + } else { + this.renderer.removeClass(this.document.body, 'dark-mode-preferred') + darkModeEnabled ? this.renderer.addClass(this.document.body, 'dark-mode') : this.renderer.removeClass(this.document.body, 'dark-mode') + } + + } + +} From 28b7c3c20867e97eae9a3d9ff4fc04a66d1cef7a Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+nikonratm@users.noreply.github.com> Date: Sun, 27 Dec 2020 23:05:34 -0800 Subject: [PATCH 02/38] Logo svg inline --- .../app-frame/app-frame.component.html | 4 +- src-ui/src/assets/logo-dark-notext.svg | 86 ++++--------------- src-ui/src/assets/logo-white-notext.svg | 69 +++++++++++++++ 3 files changed, 90 insertions(+), 69 deletions(-) create mode 100644 src-ui/src/assets/logo-white-notext.svg 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 d191ec0de..6fd2a579e 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 @@ -1,6 +1,8 @@