57bf64f69d8455e1336d0fcad9e204420778ef43
[oweals/peertube.git] / client / src / app / app.component.ts
1 import { Component, OnInit, ViewContainerRef } from '@angular/core'
2 import { Router } from '@angular/router'
3
4 import { AuthService, ConfigService } from './core'
5 import { VideoService } from './videos'
6 import { UserService } from './shared'
7
8 @Component({
9   selector: 'my-app',
10   templateUrl: './app.component.html',
11   styleUrls: [ './app.component.scss' ]
12 })
13 export class AppComponent implements OnInit {
14   notificationOptions = {
15     timeOut: 3000,
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
25   }
26
27   isMenuDisplayed = true
28
29   constructor (
30     private router: Router,
31     private authService: AuthService,
32     private configService: ConfigService,
33     private userService: UserService,
34     private videoService: VideoService,
35     viewContainerRef: ViewContainerRef
36   ) {}
37
38   ngOnInit () {
39     this.authService.loadClientCredentials()
40
41     if (this.authService.isLoggedIn()) {
42       // The service will automatically redirect to the login page if the token is not valid anymore
43       this.userService.checkTokenValidity()
44     }
45
46     this.configService.loadConfig()
47     this.videoService.loadVideoCategories()
48     this.videoService.loadVideoLicences()
49     this.videoService.loadVideoLanguages()
50
51     // Do not display menu on small screens
52     if (window.innerWidth < 600) {
53       this.isMenuDisplayed = false
54     }
55   }
56
57   isInAdmin () {
58     return this.router.url.indexOf('/admin/') !== -1
59   }
60
61   toggleMenu () {
62     this.isMenuDisplayed = !this.isMenuDisplayed
63   }
64
65   getMainColClasses () {
66     const colSizes = {
67       md: 10,
68       sm: 9,
69       xs: 9
70     }
71
72     // Take all width is the menu is not displayed
73     if (this.isMenuDisplayed === false) {
74       Object.keys(colSizes).forEach(col => colSizes[col] = 12)
75     }
76
77     const classes = [ 'main-col' ]
78     Object.keys(colSizes).forEach(col => classes.push(`col-${col}-${colSizes[col]}`))
79
80     return classes
81   }
82 }