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 const pathname = window.location.pathname
48 if (!pathname || pathname === '/') {
49 this.redirectService.redirectToHomepage()
52 this.authService.loadClientCredentials()
54 if (this.authService.isLoggedIn()) {
55 // The service will automatically redirect to the login page if the token is not valid anymore
56 this.authService.refreshUserInformation()
59 // Load custom data from server
60 this.serverService.loadConfig()
61 this.serverService.loadVideoCategories()
62 this.serverService.loadVideoLanguages()
63 this.serverService.loadVideoLicences()
64 this.serverService.loadVideoPrivacies()
66 // Do not display menu on small screens
67 if (isInSmallView()) {
68 this.isMenuDisplayed = false
71 this.router.events.subscribe(
73 // User clicked on a link in the menu, change the page
74 if (e instanceof GuardsCheckStart && isInSmallView()) {
75 this.isMenuDisplayed = false
80 this.serverService.configLoaded
82 const config = this.serverService.getConfig()
84 // We test customCSS in case or the admin removed the css
85 if (this.customCSS || config.instance.customizations.css) {
86 const styleTag = '<style>' + config.instance.customizations.css + '</style>'
87 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
90 if (config.instance.customizations.javascript) {
92 // tslint:disable:no-eval
93 eval(config.instance.customizations.javascript)
95 console.error('Cannot eval custom JavaScript.', err)
102 window.scrollTo(0, 0)
103 this.isMenuDisplayed = !this.isMenuDisplayed
106 getMainColClasses () {
107 // Take all width is the menu is not displayed
108 if (this.isMenuDisplayed === false) return [ 'expanded' ]