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