From 50b0c262fd446e9f57630aa5775e1b4708bdf4cb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 29 Nov 2016 21:41:11 +0100 Subject: Client: move menu component in core module --- client/src/app/core/menu/menu.component.ts | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 client/src/app/core/menu/menu.component.ts (limited to 'client/src/app/core/menu/menu.component.ts') diff --git a/client/src/app/core/menu/menu.component.ts b/client/src/app/core/menu/menu.component.ts new file mode 100644 index 000000000..f1bf6966d --- /dev/null +++ b/client/src/app/core/menu/menu.component.ts @@ -0,0 +1,46 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { AuthService } from '../auth'; +import { AuthStatus } from '../../shared'; + +@Component({ + selector: 'my-menu', + templateUrl: './menu.component.html' +}) +export class MenuComponent implements OnInit { + isLoggedIn: boolean; + + constructor ( + private authService: AuthService, + private router: Router + ) {} + + ngOnInit() { + this.isLoggedIn = this.authService.isLoggedIn(); + + this.authService.loginChangedSource.subscribe( + status => { + if (status === AuthStatus.LoggedIn) { + this.isLoggedIn = true; + console.log('Logged in.'); + } else if (status === AuthStatus.LoggedOut) { + this.isLoggedIn = false; + console.log('Logged out.'); + } else { + console.error('Unknown auth status: ' + status); + } + } + ); + } + + isUserAdmin() { + return this.authService.isAdmin(); + } + + logout() { + this.authService.logout(); + // Redirect to home page + this.router.navigate(['/videos/list']); + } +} -- cgit v1.2.3