Add ability to download a video from direct link or torrent file
[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, 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     private userService: UserService
33   ) {}
34
35   ngOnInit () {
36     this.authService.loadClientCredentials()
37
38     if (this.authService.isLoggedIn()) {
39       // The service will automatically redirect to the login page if the token is not valid anymore
40       this.userService.checkTokenValidity()
41     }
42
43     // Load custom data from server
44     this.serverService.loadConfig()
45     this.serverService.loadVideoCategories()
46     this.serverService.loadVideoLanguages()
47     this.serverService.loadVideoLicences()
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     this.isMenuDisplayed = !this.isMenuDisplayed
61   }
62
63   getMainColClasses () {
64     const colSizes = {
65       md: 10,
66       sm: 9,
67       xs: 9
68     }
69
70     // Take all width is the menu is not displayed
71     if (this.isMenuDisplayed === false) {
72       Object.keys(colSizes).forEach(col => colSizes[col] = 12)
73     }
74
75     const classes = [ 'main-col' ]
76     Object.keys(colSizes).forEach(col => classes.push(`col-${col}-${colSizes[col]}`))
77
78     return classes
79   }
80 }