aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-11-29 21:41:11 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-11-29 21:41:11 +0100
commit50b0c262fd446e9f57630aa5775e1b4708bdf4cb (patch)
tree8e7a899cb886b2f741546bd8fc2e7084c12deb1e /client/src/app/core
parentf81bb2853cedd7e65859756a5941d5c7e8b3ca2d (diff)
downloadPeerTube-50b0c262fd446e9f57630aa5775e1b4708bdf4cb.tar.gz
PeerTube-50b0c262fd446e9f57630aa5775e1b4708bdf4cb.tar.zst
PeerTube-50b0c262fd446e9f57630aa5775e1b4708bdf4cb.zip
Client: move menu component in core module
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/core.module.ts9
-rw-r--r--client/src/app/core/menu/index.ts1
-rw-r--r--client/src/app/core/menu/menu.component.html39
-rw-r--r--client/src/app/core/menu/menu.component.ts46
4 files changed, 92 insertions, 3 deletions
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts
index be29b88da..27e6ee1fb 100644
--- a/client/src/app/core/core.module.ts
+++ b/client/src/app/core/core.module.ts
@@ -1,17 +1,20 @@
1import { NgModule, Optional, SkipSelf } from '@angular/core'; 1import { NgModule, Optional, SkipSelf } from '@angular/core';
2import { CommonModule } from '@angular/common'; 2import { CommonModule } from '@angular/common';
3import { HttpModule } from '@angular/http'; 3import { HttpModule } from '@angular/http';
4import { RouterModule } from '@angular/router';
4 5
5import { AuthService } from './auth'; 6import { AuthService } from './auth';
7import { MenuComponent } from './menu';
6import { throwIfAlreadyLoaded } from './module-import-guard'; 8import { throwIfAlreadyLoaded } from './module-import-guard';
7 9
8@NgModule({ 10@NgModule({
9 imports: [ 11 imports: [
10 CommonModule, 12 CommonModule,
11 HttpModule 13 HttpModule,
14 RouterModule
12 ], 15 ],
13 declarations: [ ], 16 declarations: [ MenuComponent ],
14 exports: [ ], 17 exports: [ MenuComponent ],
15 providers: [ AuthService ] 18 providers: [ AuthService ]
16}) 19})
17export class CoreModule { 20export class CoreModule {
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 @@
1<menu class="col-md-2 col-sm-3 col-xs-3">
2 <div class="panel-block">
3 <div id="panel-user-login" class="panel-button">
4 <span *ngIf="!isLoggedIn" >
5 <span class="hidden-xs glyphicon glyphicon-log-in"></span>
6 <a [routerLink]="['/login']">Login</a>
7 </span>
8
9 <span *ngIf="isLoggedIn">
10 <span class="hidden-xs glyphicon glyphicon-log-out"></span>
11 <a *ngIf="isLoggedIn" (click)="logout()">Logout</a>
12 </span>
13 </div>
14
15 <div *ngIf="isLoggedIn" id="panel-user-account" class="panel-button">
16 <span class="hidden-xs glyphicon glyphicon-user"></span>
17 <a [routerLink]="['/account']">My account</a>
18 </div>
19 </div>
20
21 <div class="panel-block">
22 <div id="panel-get-videos" class="panel-button">
23 <span class="hidden-xs glyphicon glyphicon-list"></span>
24 <a [routerLink]="['/videos/list']">See videos</a>
25 </div>
26
27 <div id="panel-upload-video" class="panel-button" *ngIf="isLoggedIn">
28 <span class="hidden-xs glyphicon glyphicon-cloud-upload"></span>
29 <a [routerLink]="['/videos/add']">Upload a video</a>
30 </div>
31 </div>
32
33 <div class="panel-block" *ngIf="isUserAdmin()">
34 <div id="panel-get-videos" class="panel-button">
35 <span class="hidden-xs glyphicon glyphicon-cog"></span>
36 <a [routerLink]="['/admin']">Administration</a>
37 </div>
38 </div>
39</menu>
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 @@
1import { Component, OnInit } from '@angular/core';
2import { Router } from '@angular/router';
3
4import { AuthService } from '../auth';
5import { AuthStatus } from '../../shared';
6
7@Component({
8 selector: 'my-menu',
9 templateUrl: './menu.component.html'
10})
11export class MenuComponent implements OnInit {
12 isLoggedIn: boolean;
13
14 constructor (
15 private authService: AuthService,
16 private router: Router
17 ) {}
18
19 ngOnInit() {
20 this.isLoggedIn = this.authService.isLoggedIn();
21
22 this.authService.loginChangedSource.subscribe(
23 status => {
24 if (status === AuthStatus.LoggedIn) {
25 this.isLoggedIn = true;
26 console.log('Logged in.');
27 } else if (status === AuthStatus.LoggedOut) {
28 this.isLoggedIn = false;
29 console.log('Logged out.');
30 } else {
31 console.error('Unknown auth status: ' + status);
32 }
33 }
34 );
35 }
36
37 isUserAdmin() {
38 return this.authService.isAdmin();
39 }
40
41 logout() {
42 this.authService.logout();
43 // Redirect to home page
44 this.router.navigate(['/videos/list']);
45 }
46}