mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	refactored app-view service
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| import { Component } from '@angular/core'; | ||||
| import { AppViewService } from './services/app-view.service'; | ||||
| import { SettingsService } from './services/settings.service'; | ||||
|  | ||||
| @Component({ | ||||
|   selector: 'app-root', | ||||
| @@ -8,10 +8,10 @@ import { AppViewService } from './services/app-view.service'; | ||||
| }) | ||||
| export class AppComponent { | ||||
|  | ||||
|   constructor (appViewService: AppViewService) { | ||||
|     (window as any).pdfWorkerSrc = '/assets/js/pdf.worker.min.js'; | ||||
|     appViewService.updateDarkModeSettings() | ||||
|   constructor (private settings: SettingsService) { | ||||
|     let anyWindow = (window as any) | ||||
|     anyWindow.pdfWorkerSrc = '/assets/js/pdf.worker.min.js'; | ||||
|     this.settings.updateDarkModeSettings() | ||||
|   } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -26,7 +26,6 @@ export class AppFrameComponent implements OnInit, OnDestroy { | ||||
|     public savedViewService: SavedViewService, | ||||
|     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 { SettingsService, SETTINGS_KEYS } from 'src/app/services/settings.service'; | ||||
| import { ToastService } from 'src/app/services/toast.service'; | ||||
| import { AppViewService } from 'src/app/services/app-view.service'; | ||||
|  | ||||
| @Component({ | ||||
|   selector: 'app-settings', | ||||
| @@ -31,8 +30,7 @@ export class SettingsComponent implements OnInit { | ||||
|     public savedViewService: SavedViewService, | ||||
|     private documentListViewService: DocumentListViewService, | ||||
|     private toastService: ToastService, | ||||
|     private settings: SettingsService, | ||||
|     private appViewService: AppViewService | ||||
|     private settings: SettingsService | ||||
|   ) { } | ||||
|  | ||||
|   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_ENABLED, (this.settingsForm.value.darkModeEnabled == true).toString()) | ||||
|     this.documentListViewService.updatePageSize() | ||||
|     this.appViewService.updateDarkModeSettings() | ||||
|     this.settings.updateDarkModeSettings() | ||||
|     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 { | ||||
|   key: string | ||||
| @@ -27,7 +28,30 @@ const SETTINGS: PaperlessSettings[] = [ | ||||
| }) | ||||
| 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 { | ||||
|     let setting = SETTINGS.find(s => s.key == key) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler