aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/menu.component.ts')
-rw-r--r--client/src/app/menu.component.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/client/src/app/menu.component.ts b/client/src/app/menu.component.ts
new file mode 100644
index 000000000..594cd996e
--- /dev/null
+++ b/client/src/app/menu.component.ts
@@ -0,0 +1,51 @@
1import { Component, EventEmitter, OnInit, Output } from '@angular/core';
2import { Router, ROUTER_DIRECTIVES } from '@angular/router';
3
4import { AuthService, AuthStatus } from './shared';
5
6@Component({
7 selector: 'my-menu',
8 template: require('./menu.component.html'),
9 directives: [ ROUTER_DIRECTIVES ]
10})
11export class MenuComponent implements OnInit {
12 @Output() enteredInAdmin = new EventEmitter<boolean>();
13 isLoggedIn: boolean;
14
15 constructor (
16 private authService: AuthService,
17 private router: Router
18 ) {}
19
20 ngOnInit() {
21 this.isLoggedIn = this.authService.isLoggedIn();
22
23 this.authService.loginChangedSource.subscribe(
24 status => {
25 if (status === AuthStatus.LoggedIn) {
26 this.isLoggedIn = true;
27 console.log('Logged in.');
28 } else if (status === AuthStatus.LoggedOut) {
29 this.isLoggedIn = false;
30 console.log('Logged out.');
31 } else {
32 console.error('Unknown auth status: ' + status);
33 }
34 }
35 );
36 }
37
38 enterInAdmin() {
39 this.enteredInAdmin.emit(true);
40 }
41
42 isUserAdmin() {
43 return this.authService.isAdmin();
44 }
45
46 logout() {
47 this.authService.logout();
48 // Redirect to home page
49 this.router.navigate(['/videos/list']);
50 }
51}