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