1 import { Component, OnInit } from '@angular/core'
2 import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
3 import { GuardsCheckStart, NavigationEnd, Router } from '@angular/router'
4 import { AuthService, RedirectService, ServerService } from '@app/core'
5 import { is18nPath } from '../../../shared/models/i18n'
6 import { ScreenService } from '@app/shared/misc/screen.service'
10 templateUrl: './app.component.html',
11 styleUrls: [ './app.component.scss' ]
13 export class AppComponent implements OnInit {
14 notificationOptions = {
20 showProgressBar: false,
22 preventDuplicates: false,
23 preventLastDuplicates: 'visible',
27 isMenuDisplayed = true
32 private router: Router,
33 private authService: AuthService,
34 private serverService: ServerService,
35 private domSanitizer: DomSanitizer,
36 private redirectService: RedirectService,
37 private screenService: ScreenService
40 get serverVersion () {
41 return this.serverService.getConfig().serverVersion
45 return this.serverService.getConfig().instance.name
49 return RedirectService.DEFAULT_ROUTE
53 document.getElementById('incompatible-browser').className += ' browser-ok'
55 this.router.events.subscribe(e => {
56 if (e instanceof NavigationEnd) {
57 const pathname = window.location.pathname
58 if (!pathname || pathname === '/' || is18nPath(pathname)) {
59 this.redirectService.redirectToHomepage(true)
64 this.authService.loadClientCredentials()
66 if (this.isUserLoggedIn()) {
67 // The service will automatically redirect to the login page if the token is not valid anymore
68 this.authService.refreshUserInformation()
71 // Load custom data from server
72 this.serverService.loadConfig()
73 this.serverService.loadVideoCategories()
74 this.serverService.loadVideoLanguages()
75 this.serverService.loadVideoLicences()
76 this.serverService.loadVideoPrivacies()
78 // Do not display menu on small screens
79 if (this.screenService.isInSmallView()) {
80 this.isMenuDisplayed = false
83 this.router.events.subscribe(
85 // User clicked on a link in the menu, change the page
86 if (e instanceof GuardsCheckStart && this.screenService.isInSmallView()) {
87 this.isMenuDisplayed = false
92 this.serverService.configLoaded
94 const config = this.serverService.getConfig()
96 // We test customCSS if the admin removed the css
97 if (this.customCSS || config.instance.customizations.css) {
98 const styleTag = '<style>' + config.instance.customizations.css + '</style>'
99 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
102 if (config.instance.customizations.javascript) {
104 // tslint:disable:no-eval
105 eval(config.instance.customizations.javascript)
107 console.error('Cannot eval custom JavaScript.', err)
114 return this.authService.isLoggedIn()
118 this.isMenuDisplayed = !this.isMenuDisplayed