]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.component.ts
Improve playback speed style
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
CommitLineData
fd45e8f4 1import { Component, OnInit } from '@angular/core'
00b5556c 2import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
07fa4c97 3import { GuardsCheckStart, Router } from '@angular/router'
4cb6d457 4import { AuthService, ServerService } from '@app/core'
3290f37c 5import { isInSmallView } from '@app/shared/misc/utils'
e2a2d6c8 6
dc8bc31b 7@Component({
3154f382
C
8 selector: 'my-app',
9 templateUrl: './app.component.html',
10 styleUrls: [ './app.component.scss' ]
dc8bc31b 11})
e2a2d6c8 12export class AppComponent implements OnInit {
7ddd02c9 13 notificationOptions = {
35bf0c83 14 timeOut: 5000,
7ddd02c9
C
15 lastOnBottom: true,
16 clickToClose: true,
17 maxLength: 0,
18 maxStack: 7,
19 showProgressBar: false,
20 pauseOnHover: false,
21 preventDuplicates: false,
22 preventLastDuplicates: 'visible',
23 rtl: false
df98563e 24 }
7ddd02c9 25
df98563e 26 isMenuDisplayed = true
67167390 27
00b5556c
C
28 customCSS: SafeHtml
29
df98563e 30 constructor (
3154f382 31 private router: Router,
e2a2d6c8 32 private authService: AuthService,
00b5556c
C
33 private serverService: ServerService,
34 private domSanitizer: DomSanitizer
3154f382 35 ) {}
a99593ed 36
915c5bbe
C
37 get serverVersion () {
38 return this.serverService.getConfig().serverVersion
39 }
40
36f9424f
C
41 get instanceName () {
42 return this.serverService.getConfig().instance.name
43 }
44
df98563e 45 ngOnInit () {
d592e0a9
C
46 this.authService.loadClientCredentials()
47
e2a2d6c8
C
48 if (this.authService.isLoggedIn()) {
49 // The service will automatically redirect to the login page if the token is not valid anymore
bcd9f81e 50 this.authService.refreshUserInformation()
e2a2d6c8 51 }
6e07c3de 52
db7af09b
C
53 // Load custom data from server
54 this.serverService.loadConfig()
55 this.serverService.loadVideoCategories()
56 this.serverService.loadVideoLanguages()
57 this.serverService.loadVideoLicences()
fd45e8f4 58 this.serverService.loadVideoPrivacies()
3eeeb87f
C
59
60 // Do not display menu on small screens
3290f37c 61 if (isInSmallView()) {
df98563e 62 this.isMenuDisplayed = false
3eeeb87f 63 }
c8cf5952
C
64
65 this.router.events.subscribe(
66 e => {
67 // User clicked on a link in the menu, change the page
3290f37c 68 if (e instanceof GuardsCheckStart && isInSmallView()) {
c8cf5952
C
69 this.isMenuDisplayed = false
70 }
71 }
72 )
00b5556c
C
73
74 this.serverService.configLoaded
75 .subscribe(() => {
76 const config = this.serverService.getConfig()
77
78 // We test customCSS in case or the admin removed the css
79 if (this.customCSS || config.instance.customizations.css) {
80 const styleTag = '<style>' + config.instance.customizations.css + '</style>'
81 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
82 }
83
84 if (config.instance.customizations.javascript) {
85 try {
86 // tslint:disable:no-eval
87 eval(config.instance.customizations.javascript)
88 } catch (err) {
89 console.error('Cannot eval custom JavaScript.', err)
90 }
91 }
92 })
e2a2d6c8
C
93 }
94
df98563e 95 toggleMenu () {
a01f107b 96 window.scrollTo(0, 0)
df98563e 97 this.isMenuDisplayed = !this.isMenuDisplayed
67167390
C
98 }
99
df98563e 100 getMainColClasses () {
67167390 101 // Take all width is the menu is not displayed
b33f657c 102 if (this.isMenuDisplayed === false) return [ 'expanded' ]
67167390 103
b33f657c 104 return []
67167390 105 }
dc8bc31b 106}