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, RedirectService, 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,
35 private redirectService: RedirectService
38 get serverVersion () {
39 return this.serverService.getConfig().serverVersion
43 return this.serverService.getConfig().instance.name
47 if (this.router.url === '/') {
48 this.redirectService.redirectToHomepage()
51 this.authService.loadClientCredentials()
53 if (this.authService.isLoggedIn()) {
54 // The service will automatically redirect to the login page if the token is not valid anymore
55 this.authService.refreshUserInformation()
58 // Load custom data from server
59 this.serverService.loadConfig()
60 this.serverService.loadVideoCategories()
61 this.serverService.loadVideoLanguages()
62 this.serverService.loadVideoLicences()
63 this.serverService.loadVideoPrivacies()
65 // Do not display menu on small screens
66 if (isInSmallView()) {
67 this.isMenuDisplayed = false
70 this.router.events.subscribe(
72 // User clicked on a link in the menu, change the page
73 if (e instanceof GuardsCheckStart && isInSmallView()) {
74 this.isMenuDisplayed = false
79 this.serverService.configLoaded
81 const config = this.serverService.getConfig()
83 // We test customCSS in case or the admin removed the css
84 if (this.customCSS || config.instance.customizations.css) {
85 const styleTag = '<style>' + config.instance.customizations.css + '</style>'
86 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
89 if (config.instance.customizations.javascript) {
91 // tslint:disable:no-eval
92 eval(config.instance.customizations.javascript)
94 console.error('Cannot eval custom JavaScript.', err)
101 window.scrollTo(0, 0)
102 this.isMenuDisplayed = !this.isMenuDisplayed
105 getMainColClasses () {
106 // Take all width is the menu is not displayed
107 if (this.isMenuDisplayed === false) return [ 'expanded' ]