1 import { Component, OnInit } from '@angular/core'
2 import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
3 import { GuardsCheckStart, Router } from '@angular/router'
4 import { AuthService, ServerService } from '@app/core'
5 import { isInSmallView } from '@app/shared/misc/utils'
9 templateUrl: './app.component.html',
10 styleUrls: [ './app.component.scss' ]
12 export class AppComponent implements OnInit {
13 notificationOptions = {
19 showProgressBar: false,
21 preventDuplicates: false,
22 preventLastDuplicates: 'visible',
26 isMenuDisplayed = true
31 private router: Router,
32 private authService: AuthService,
33 private serverService: ServerService,
34 private domSanitizer: DomSanitizer
37 get serverVersion () {
38 return this.serverService.getConfig().serverVersion
42 return this.serverService.getConfig().instance.name
46 this.authService.loadClientCredentials()
48 if (this.authService.isLoggedIn()) {
49 // The service will automatically redirect to the login page if the token is not valid anymore
50 this.authService.refreshUserInformation()
53 // Load custom data from server
54 this.serverService.loadConfig()
55 this.serverService.loadVideoCategories()
56 this.serverService.loadVideoLanguages()
57 this.serverService.loadVideoLicences()
58 this.serverService.loadVideoPrivacies()
60 // Do not display menu on small screens
61 if (isInSmallView()) {
62 this.isMenuDisplayed = false
65 this.router.events.subscribe(
67 // User clicked on a link in the menu, change the page
68 if (e instanceof GuardsCheckStart && isInSmallView()) {
69 this.isMenuDisplayed = false
74 this.serverService.configLoaded
76 const config = this.serverService.getConfig()
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)
84 if (config.instance.customizations.javascript) {
86 // tslint:disable:no-eval
87 eval(config.instance.customizations.javascript)
89 console.error('Cannot eval custom JavaScript.', err)
97 this.isMenuDisplayed = !this.isMenuDisplayed
100 getMainColClasses () {
101 // Take all width is the menu is not displayed
102 if (this.isMenuDisplayed === false) return [ 'expanded' ]