Use typescript standard and lint all files
[oweals/peertube.git] / client / src / app / core / menu / menu.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3
4 import { AuthService, AuthStatus } from '../auth'
5 import { ConfigService } from '../config'
6
7 @Component({
8   selector: 'my-menu',
9   templateUrl: './menu.component.html',
10   styleUrls: [ './menu.component.scss' ]
11 })
12 export class MenuComponent implements OnInit {
13   isLoggedIn: boolean
14
15   constructor (
16     private authService: AuthService,
17     private configService: ConfigService,
18     private router: Router
19   ) {}
20
21   ngOnInit () {
22     this.isLoggedIn = this.authService.isLoggedIn()
23
24     this.authService.loginChangedSource.subscribe(
25       status => {
26         if (status === AuthStatus.LoggedIn) {
27           this.isLoggedIn = true
28           console.log('Logged in.')
29         } else if (status === AuthStatus.LoggedOut) {
30           this.isLoggedIn = false
31           console.log('Logged out.')
32         } else {
33           console.error('Unknown auth status: ' + status)
34         }
35       }
36     )
37   }
38
39   isRegistrationEnabled () {
40     return this.configService.getConfig().signup.enabled
41   }
42
43   isUserAdmin () {
44     return this.authService.isAdmin()
45   }
46
47   logout () {
48     this.authService.logout()
49     // Redirect to home page
50     this.router.navigate(['/videos/list'])
51   }
52 }