aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/menu.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r--client/src/app/menu/menu.component.ts36
1 files changed, 3 insertions, 33 deletions
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts
index 22ddfad02..24cd5aa28 100644
--- a/client/src/app/menu/menu.component.ts
+++ b/client/src/app/menu/menu.component.ts
@@ -1,9 +1,8 @@
1import { Component, OnInit, ViewChild } from '@angular/core' 1import { Component, OnInit, ViewChild } from '@angular/core'
2import { UserRight } from '../../../../shared/models/users/user-right.enum' 2import { UserRight } from '../../../../shared/models/users/user-right.enum'
3import { AuthService, AuthStatus, RedirectService, ServerService } from '../core' 3import { AuthService, AuthStatus, RedirectService, ServerService, ThemeService } from '../core'
4import { User } from '../shared/users/user.model' 4import { User } from '../shared/users/user.model'
5import { LanguageChooserComponent } from '@app/menu/language-chooser.component' 5import { LanguageChooserComponent } from '@app/menu/language-chooser.component'
6import { Hotkey, HotkeysService } from 'angular2-hotkeys'
7 6
8@Component({ 7@Component({
9 selector: 'my-menu', 8 selector: 'my-menu',
@@ -16,7 +15,6 @@ export class MenuComponent implements OnInit {
16 user: User 15 user: User
17 isLoggedIn: boolean 16 isLoggedIn: boolean
18 userHasAdminAccess = false 17 userHasAdminAccess = false
19 hotkeys: Hotkey[]
20 18
21 private routesPerRight = { 19 private routesPerRight = {
22 [UserRight.MANAGE_USERS]: '/admin/users', 20 [UserRight.MANAGE_USERS]: '/admin/users',
@@ -24,14 +22,12 @@ export class MenuComponent implements OnInit {
24 [UserRight.MANAGE_VIDEO_ABUSES]: '/admin/video-abuses', 22 [UserRight.MANAGE_VIDEO_ABUSES]: '/admin/video-abuses',
25 [UserRight.MANAGE_VIDEO_BLACKLIST]: '/admin/video-blacklist' 23 [UserRight.MANAGE_VIDEO_BLACKLIST]: '/admin/video-blacklist'
26 } 24 }
27 private theme = document.querySelector('body')
28 private previousTheme = { }
29 25
30 constructor ( 26 constructor (
31 private authService: AuthService, 27 private authService: AuthService,
32 private serverService: ServerService, 28 private serverService: ServerService,
33 private redirectService: RedirectService, 29 private redirectService: RedirectService,
34 private hotkeysService: HotkeysService 30 private themeService: ThemeService
35 ) {} 31 ) {}
36 32
37 ngOnInit () { 33 ngOnInit () {
@@ -56,21 +52,6 @@ export class MenuComponent implements OnInit {
56 } 52 }
57 } 53 }
58 ) 54 )
59
60 // initialise the alternative theme with dark theme colors
61 this.previousTheme['mainBackgroundColor'] = '#111111'
62 this.previousTheme['mainForegroundColor'] = '#fff'
63 this.previousTheme['submenuColor'] = 'rgb(32,32,32)'
64 this.previousTheme['inputColor'] = 'gray'
65 this.previousTheme['inputPlaceholderColor'] = '#fff'
66
67 this.hotkeys = [
68 new Hotkey('T', (event: KeyboardEvent): boolean => {
69 this.toggleDarkTheme()
70 return false
71 }, undefined, 'Toggle Dark theme')
72 ]
73 this.hotkeysService.add(this.hotkeys)
74 } 55 }
75 56
76 isRegistrationAllowed () { 57 isRegistrationAllowed () {
@@ -117,18 +98,7 @@ export class MenuComponent implements OnInit {
117 } 98 }
118 99
119 toggleDarkTheme () { 100 toggleDarkTheme () {
120 // switch properties 101 this.themeService.toggleDarkTheme()
121 this.switchProperty('mainBackgroundColor')
122 this.switchProperty('mainForegroundColor')
123 this.switchProperty('submenuColor')
124 this.switchProperty('inputColor')
125 this.switchProperty('inputPlaceholderColor')
126 }
127
128 private switchProperty (property, newValue?) {
129 const propertyOldvalue = window.getComputedStyle(this.theme).getPropertyValue('--' + property)
130 this.theme.style.setProperty('--' + property, (newValue) ? newValue : this.previousTheme[property])
131 this.previousTheme[property] = propertyOldvalue
132 } 102 }
133 103
134 private computeIsUserHasAdminAccess () { 104 private computeIsUserHasAdminAccess () {