]>
Commit | Line | Data |
---|---|---|
fd45e8f4 | 1 | import { Component, OnInit } from '@angular/core' |
00b5556c | 2 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
989e526a | 3 | import { GuardsCheckStart, NavigationEnd, Router } from '@angular/router' |
901637bb | 4 | import { AuthService, RedirectService, ServerService } from '@app/core' |
3290f37c | 5 | import { isInSmallView } from '@app/shared/misc/utils' |
989e526a | 6 | import { is18nPath } from '../../../shared/models/i18n' |
e2a2d6c8 | 7 | |
dc8bc31b | 8 | @Component({ |
3154f382 C |
9 | selector: 'my-app', |
10 | templateUrl: './app.component.html', | |
11 | styleUrls: [ './app.component.scss' ] | |
dc8bc31b | 12 | }) |
e2a2d6c8 | 13 | export class AppComponent implements OnInit { |
7ddd02c9 | 14 | notificationOptions = { |
35bf0c83 | 15 | timeOut: 5000, |
7ddd02c9 C |
16 | lastOnBottom: true, |
17 | clickToClose: true, | |
18 | maxLength: 0, | |
19 | maxStack: 7, | |
20 | showProgressBar: false, | |
21 | pauseOnHover: false, | |
22 | preventDuplicates: false, | |
23 | preventLastDuplicates: 'visible', | |
24 | rtl: false | |
df98563e | 25 | } |
7ddd02c9 | 26 | |
df98563e | 27 | isMenuDisplayed = true |
67167390 | 28 | |
00b5556c C |
29 | customCSS: SafeHtml |
30 | ||
df98563e | 31 | constructor ( |
3154f382 | 32 | private router: Router, |
e2a2d6c8 | 33 | private authService: AuthService, |
00b5556c | 34 | private serverService: ServerService, |
901637bb C |
35 | private domSanitizer: DomSanitizer, |
36 | private redirectService: RedirectService | |
989e526a | 37 | ) { } |
a99593ed | 38 | |
915c5bbe C |
39 | get serverVersion () { |
40 | return this.serverService.getConfig().serverVersion | |
41 | } | |
42 | ||
36f9424f C |
43 | get instanceName () { |
44 | return this.serverService.getConfig().instance.name | |
45 | } | |
46 | ||
29f9b562 C |
47 | get defaultRoute () { |
48 | return RedirectService.DEFAULT_ROUTE | |
49 | } | |
50 | ||
df98563e | 51 | ngOnInit () { |
b3eeb529 | 52 | document.getElementById('incompatible-browser').className += ' browser-ok' |
73e09f27 | 53 | |
b851dabf C |
54 | this.router.events.subscribe(e => { |
55 | if (e instanceof NavigationEnd) { | |
56 | const pathname = window.location.pathname | |
989e526a | 57 | if (!pathname || pathname === '/' || is18nPath(pathname)) { |
7cf26f43 | 58 | this.redirectService.redirectToHomepage(true) |
b851dabf C |
59 | } |
60 | } | |
61 | }) | |
901637bb | 62 | |
d592e0a9 C |
63 | this.authService.loadClientCredentials() |
64 | ||
d414207f | 65 | if (this.isUserLoggedIn()) { |
e2a2d6c8 | 66 | // The service will automatically redirect to the login page if the token is not valid anymore |
bcd9f81e | 67 | this.authService.refreshUserInformation() |
e2a2d6c8 | 68 | } |
6e07c3de | 69 | |
db7af09b C |
70 | // Load custom data from server |
71 | this.serverService.loadConfig() | |
72 | this.serverService.loadVideoCategories() | |
73 | this.serverService.loadVideoLanguages() | |
74 | this.serverService.loadVideoLicences() | |
fd45e8f4 | 75 | this.serverService.loadVideoPrivacies() |
3eeeb87f C |
76 | |
77 | // Do not display menu on small screens | |
3290f37c | 78 | if (isInSmallView()) { |
df98563e | 79 | this.isMenuDisplayed = false |
3eeeb87f | 80 | } |
c8cf5952 C |
81 | |
82 | this.router.events.subscribe( | |
83 | e => { | |
84 | // User clicked on a link in the menu, change the page | |
3290f37c | 85 | if (e instanceof GuardsCheckStart && isInSmallView()) { |
c8cf5952 C |
86 | this.isMenuDisplayed = false |
87 | } | |
88 | } | |
89 | ) | |
00b5556c C |
90 | |
91 | this.serverService.configLoaded | |
92 | .subscribe(() => { | |
93 | const config = this.serverService.getConfig() | |
94 | ||
c263f3b4 | 95 | // We test customCSS if the admin removed the css |
00b5556c C |
96 | if (this.customCSS || config.instance.customizations.css) { |
97 | const styleTag = '<style>' + config.instance.customizations.css + '</style>' | |
98 | this.customCSS = this.domSanitizer.bypassSecurityTrustHtml(styleTag) | |
99 | } | |
100 | ||
101 | if (config.instance.customizations.javascript) { | |
102 | try { | |
103 | // tslint:disable:no-eval | |
104 | eval(config.instance.customizations.javascript) | |
105 | } catch (err) { | |
106 | console.error('Cannot eval custom JavaScript.', err) | |
107 | } | |
108 | } | |
109 | }) | |
e2a2d6c8 C |
110 | } |
111 | ||
d414207f C |
112 | isUserLoggedIn () { |
113 | return this.authService.isLoggedIn() | |
114 | } | |
115 | ||
df98563e | 116 | toggleMenu () { |
a01f107b | 117 | window.scrollTo(0, 0) |
df98563e | 118 | this.isMenuDisplayed = !this.isMenuDisplayed |
67167390 | 119 | } |
dc8bc31b | 120 | } |