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 { isInSmallView } from '@app/shared/misc/utils'
6 import { is18nPath } from '../../../shared/models/i18n'
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
39 get serverVersion () {
40 return this.serverService.getConfig().serverVersion
44 return this.serverService.getConfig().instance.name
48 return RedirectService.DEFAULT_ROUTE
52 document.getElementById('incompatible-browser').className += ' browser-ok'
54 this.router.events.subscribe(e => {
55 if (e instanceof NavigationEnd) {
56 const pathname = window.location.pathname
57 if (!pathname || pathname === '/' || is18nPath(pathname)) {
58 this.redirectService.redirectToHomepage(true)
63 this.authService.loadClientCredentials()
65 if (this.isUserLoggedIn()) {
66 // The service will automatically redirect to the login page if the token is not valid anymore
67 this.authService.refreshUserInformation()
70 // Load custom data from server
71 this.serverService.loadConfig()
72 this.serverService.loadVideoCategories()
73 this.serverService.loadVideoLanguages()
74 this.serverService.loadVideoLicences()
75 this.serverService.loadVideoPrivacies()
77 // Do not display menu on small screens
78 if (isInSmallView()) {
79 this.isMenuDisplayed = false
82 this.router.events.subscribe(
84 // User clicked on a link in the menu, change the page
85 if (e instanceof GuardsCheckStart && isInSmallView()) {
86 this.isMenuDisplayed = false
91 this.serverService.configLoaded
93 const config = this.serverService.getConfig()
95 // We test customCSS if the admin removed the css
96 if (this.customCSS || config.instance.customizations.css) {
97 const styleTag = '<style>' + config.instance.customizations.css + '</style>'
98 this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag)
101 if (config.instance.customizations.javascript) {
103 // tslint:disable:no-eval
104 eval(config.instance.customizations.javascript)
106 console.error('Cannot eval custom JavaScript.', err)
113 return this.authService.isLoggedIn()
117 window.scrollTo(0, 0)
118 this.isMenuDisplayed = !this.isMenuDisplayed