aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu.component.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-12 16:52:10 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-12 16:53:32 +0200
commit602eb142bebb62f1774d6e17c211eef99ace584b (patch)
tree9410d3b225f5a904a41d7c8f3c3035375dc4268a /client/src/app/menu.component.ts
parent7da18e4420c4b71a8ecfda07f39324fbfec081c3 (diff)
downloadPeerTube-602eb142bebb62f1774d6e17c211eef99ace584b.tar.gz
PeerTube-602eb142bebb62f1774d6e17c211eef99ace584b.tar.zst
PeerTube-602eb142bebb62f1774d6e17c211eef99ace584b.zip
Client: make an admin menu and a classic menu component
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}