mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-11 10:00:48 -05:00
refactored app-view service
This commit is contained in:
parent
d5601b7ec0
commit
0a7412424d
@ -1,5 +1,5 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { AppViewService } from './services/app-view.service';
|
import { SettingsService } from './services/settings.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@ -8,10 +8,10 @@ import { AppViewService } from './services/app-view.service';
|
|||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
|
|
||||||
constructor (appViewService: AppViewService) {
|
constructor (private settings: SettingsService) {
|
||||||
(window as any).pdfWorkerSrc = '/assets/js/pdf.worker.min.js';
|
let anyWindow = (window as any)
|
||||||
appViewService.updateDarkModeSettings()
|
anyWindow.pdfWorkerSrc = '/assets/js/pdf.worker.min.js';
|
||||||
|
this.settings.updateDarkModeSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ export class AppFrameComponent implements OnInit, OnDestroy {
|
|||||||
public savedViewService: SavedViewService,
|
public savedViewService: SavedViewService,
|
||||||
private meta: Meta
|
private meta: Meta
|
||||||
) {
|
) {
|
||||||
console.log(meta);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import { DocumentListViewService } from 'src/app/services/document-list-view.ser
|
|||||||
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
|
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
|
||||||
import { SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service';
|
import { 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 { AppViewService } from 'src/app/services/app-view.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-settings',
|
selector: 'app-settings',
|
||||||
@ -31,8 +30,7 @@ export class SettingsComponent implements OnInit {
|
|||||||
public savedViewService: SavedViewService,
|
public savedViewService: SavedViewService,
|
||||||
private documentListViewService: DocumentListViewService,
|
private documentListViewService: DocumentListViewService,
|
||||||
private toastService: ToastService,
|
private toastService: ToastService,
|
||||||
private settings: SettingsService,
|
private settings: SettingsService
|
||||||
private appViewService: AppViewService
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -72,7 +70,7 @@ export class SettingsComponent implements OnInit {
|
|||||||
this.settings.set(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM, this.settingsForm.value.darkModeUseSystem)
|
this.settings.set(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM, this.settingsForm.value.darkModeUseSystem)
|
||||||
this.settings.set(SETTINGS_KEYS.DARK_MODE_ENABLED, (this.settingsForm.value.darkModeEnabled == true).toString())
|
this.settings.set(SETTINGS_KEYS.DARK_MODE_ENABLED, (this.settingsForm.value.darkModeEnabled == true).toString())
|
||||||
this.documentListViewService.updatePageSize()
|
this.documentListViewService.updatePageSize()
|
||||||
this.appViewService.updateDarkModeSettings()
|
this.settings.updateDarkModeSettings()
|
||||||
this.toastService.showInfo($localize`Settings saved successfully.`)
|
this.toastService.showInfo($localize`Settings saved successfully.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,35 +0,0 @@
|
|||||||
import { Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core';
|
|
||||||
import { DOCUMENT } from '@angular/common';
|
|
||||||
import { SettingsService, SETTINGS_KEYS } from './settings.service';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class AppViewService {
|
|
||||||
private renderer: Renderer2;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private settings: SettingsService,
|
|
||||||
private rendererFactory: RendererFactory2,
|
|
||||||
@Inject(DOCUMENT) private document
|
|
||||||
) {
|
|
||||||
this.renderer = rendererFactory.createRenderer(null, null);
|
|
||||||
|
|
||||||
this.updateDarkModeSettings()
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDarkModeSettings(): void {
|
|
||||||
let darkModeUseSystem = this.settings.get(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM)
|
|
||||||
let darkModeEnabled = this.settings.get(SETTINGS_KEYS.DARK_MODE_ENABLED)
|
|
||||||
|
|
||||||
if (darkModeUseSystem) {
|
|
||||||
this.renderer.addClass(this.document.body, 'color-scheme-system')
|
|
||||||
this.renderer.removeClass(this.document.body, 'color-scheme-dark')
|
|
||||||
} else {
|
|
||||||
this.renderer.removeClass(this.document.body, 'color-scheme-system')
|
|
||||||
darkModeEnabled ? this.renderer.addClass(this.document.body, 'color-scheme-dark') : this.renderer.removeClass(this.document.body, 'color-scheme-dark')
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
import { Inject, Injectable, Renderer2, RendererFactory2 } from '@angular/core';
|
||||||
|
|
||||||
export interface PaperlessSettings {
|
export interface PaperlessSettings {
|
||||||
key: string
|
key: string
|
||||||
@ -27,7 +28,30 @@ const SETTINGS: PaperlessSettings[] = [
|
|||||||
})
|
})
|
||||||
export class SettingsService {
|
export class SettingsService {
|
||||||
|
|
||||||
constructor() { }
|
private renderer: Renderer2;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private rendererFactory: RendererFactory2,
|
||||||
|
@Inject(DOCUMENT) private document
|
||||||
|
) {
|
||||||
|
this.renderer = rendererFactory.createRenderer(null, null);
|
||||||
|
|
||||||
|
this.updateDarkModeSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDarkModeSettings(): void {
|
||||||
|
let darkModeUseSystem = this.get(SETTINGS_KEYS.DARK_MODE_USE_SYSTEM)
|
||||||
|
let darkModeEnabled = this.get(SETTINGS_KEYS.DARK_MODE_ENABLED)
|
||||||
|
|
||||||
|
if (darkModeUseSystem) {
|
||||||
|
this.renderer.addClass(this.document.body, 'color-scheme-system')
|
||||||
|
this.renderer.removeClass(this.document.body, 'color-scheme-dark')
|
||||||
|
} else {
|
||||||
|
this.renderer.removeClass(this.document.body, 'color-scheme-system')
|
||||||
|
darkModeEnabled ? this.renderer.addClass(this.document.body, 'color-scheme-dark') : this.renderer.removeClass(this.document.body, 'color-scheme-dark')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
get(key: string): any {
|
get(key: string): any {
|
||||||
let setting = SETTINGS.find(s => s.key == key)
|
let setting = SETTINGS.find(s => s.key == key)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user