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/index.ts | 1 + client/src/app/core/menu/menu.component.html | 39 +++++++++++++++++++++++ client/src/app/core/menu/menu.component.ts | 46 ++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 client/src/app/core/menu/index.ts create mode 100644 client/src/app/core/menu/menu.component.html create mode 100644 client/src/app/core/menu/menu.component.ts (limited to 'client/src/app/core/menu') diff --git a/client/src/app/core/menu/index.ts b/client/src/app/core/menu/index.ts new file mode 100644 index 000000000..d07a1144c --- /dev/null +++ b/client/src/app/core/menu/index.ts @@ -0,0 +1 @@ +export * from './menu.component'; diff --git a/client/src/app/core/menu/menu.component.html b/client/src/app/core/menu/menu.component.html new file mode 100644 index 000000000..1e9a53246 --- /dev/null +++ b/client/src/app/core/menu/menu.component.html @@ -0,0 +1,39 @@ + +
+
+ + + Login + + + + + Logout + +
+ +
+ + My account +
+
+ +
+
+ + See videos +
+ + +
+ +
+ +
+
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