Client: move menu component in core module
authorChocobozzz <florian.bigard@gmail.com>
Tue, 29 Nov 2016 20:41:11 +0000 (21:41 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Tue, 29 Nov 2016 20:41:11 +0000 (21:41 +0100)
client/src/app/app.module.ts
client/src/app/core/core.module.ts
client/src/app/core/menu/index.ts [new file with mode: 0644]
client/src/app/core/menu/menu.component.html [new file with mode: 0644]
client/src/app/core/menu/menu.component.ts [new file with mode: 0644]
client/src/app/menu.component.html [deleted file]
client/src/app/menu.component.ts [deleted file]

index 555f412e7c44f41a6ce994994a22f73dbe54050e..e9bb800f4f2dfb2a5b793e82afa7e01147e997f8 100644 (file)
@@ -16,8 +16,6 @@ import { LoginModule } from './login';
 import { SharedModule } from './shared';
 import { VideosModule } from './videos';
 
-import { MenuComponent } from './menu.component';
-
 const metaConfig: MetaConfig = {
   //Append a title suffix such as a site name to all titles
   //Defaults to false
@@ -35,8 +33,7 @@ const APP_PROVIDERS = [
 @NgModule({
   bootstrap: [ AppComponent ],
   declarations: [
-    AppComponent,
-    MenuComponent
+    AppComponent
   ],
   imports: [
     BrowserModule,
index be29b88daea9204f19a948c9931b3d411fcda766..27e6ee1fb765b2d73aa5e392db9f7001a79bcfc9 100644 (file)
@@ -1,17 +1,20 @@
 import { NgModule, Optional, SkipSelf } from '@angular/core';
 import { CommonModule } from '@angular/common';
 import { HttpModule } from '@angular/http';
+import { RouterModule } from '@angular/router';
 
 import { AuthService } from './auth';
+import { MenuComponent } from './menu';
 import { throwIfAlreadyLoaded } from './module-import-guard';
 
 @NgModule({
   imports: [
     CommonModule,
-    HttpModule
+    HttpModule,
+    RouterModule
   ],
-  declarations: [ ],
-  exports: [ ],
+  declarations: [ MenuComponent ],
+  exports: [ MenuComponent ],
   providers: [ AuthService ]
 })
 export class CoreModule {
diff --git a/client/src/app/core/menu/index.ts b/client/src/app/core/menu/index.ts
new file mode 100644 (file)
index 0000000..d07a114
--- /dev/null
@@ -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 (file)
index 0000000..1e9a532
--- /dev/null
@@ -0,0 +1,39 @@
+<menu class="col-md-2 col-sm-3 col-xs-3">
+  <div class="panel-block">
+    <div id="panel-user-login" class="panel-button">
+      <span *ngIf="!isLoggedIn" >
+        <span class="hidden-xs glyphicon glyphicon-log-in"></span>
+        <a [routerLink]="['/login']">Login</a>
+      </span>
+
+      <span *ngIf="isLoggedIn">
+        <span class="hidden-xs glyphicon glyphicon-log-out"></span>
+        <a *ngIf="isLoggedIn" (click)="logout()">Logout</a>
+      </span>
+    </div>
+
+    <div *ngIf="isLoggedIn" id="panel-user-account" class="panel-button">
+      <span class="hidden-xs glyphicon glyphicon-user"></span>
+      <a [routerLink]="['/account']">My account</a>
+    </div>
+  </div>
+
+  <div class="panel-block">
+    <div id="panel-get-videos" class="panel-button">
+      <span class="hidden-xs glyphicon glyphicon-list"></span>
+      <a [routerLink]="['/videos/list']">See videos</a>
+    </div>
+
+    <div id="panel-upload-video" class="panel-button" *ngIf="isLoggedIn">
+      <span class="hidden-xs glyphicon glyphicon-cloud-upload"></span>
+      <a [routerLink]="['/videos/add']">Upload a video</a>
+    </div>
+  </div>
+
+  <div class="panel-block" *ngIf="isUserAdmin()">
+    <div id="panel-get-videos" class="panel-button">
+      <span class="hidden-xs glyphicon glyphicon-cog"></span>
+      <a [routerLink]="['/admin']">Administration</a>
+    </div>
+  </div>
+</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 (file)
index 0000000..f1bf696
--- /dev/null
@@ -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']);
+  }
+}
diff --git a/client/src/app/menu.component.html b/client/src/app/menu.component.html
deleted file mode 100644 (file)
index 1e9a532..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<menu class="col-md-2 col-sm-3 col-xs-3">
-  <div class="panel-block">
-    <div id="panel-user-login" class="panel-button">
-      <span *ngIf="!isLoggedIn" >
-        <span class="hidden-xs glyphicon glyphicon-log-in"></span>
-        <a [routerLink]="['/login']">Login</a>
-      </span>
-
-      <span *ngIf="isLoggedIn">
-        <span class="hidden-xs glyphicon glyphicon-log-out"></span>
-        <a *ngIf="isLoggedIn" (click)="logout()">Logout</a>
-      </span>
-    </div>
-
-    <div *ngIf="isLoggedIn" id="panel-user-account" class="panel-button">
-      <span class="hidden-xs glyphicon glyphicon-user"></span>
-      <a [routerLink]="['/account']">My account</a>
-    </div>
-  </div>
-
-  <div class="panel-block">
-    <div id="panel-get-videos" class="panel-button">
-      <span class="hidden-xs glyphicon glyphicon-list"></span>
-      <a [routerLink]="['/videos/list']">See videos</a>
-    </div>
-
-    <div id="panel-upload-video" class="panel-button" *ngIf="isLoggedIn">
-      <span class="hidden-xs glyphicon glyphicon-cloud-upload"></span>
-      <a [routerLink]="['/videos/add']">Upload a video</a>
-    </div>
-  </div>
-
-  <div class="panel-block" *ngIf="isUserAdmin()">
-    <div id="panel-get-videos" class="panel-button">
-      <span class="hidden-xs glyphicon glyphicon-cog"></span>
-      <a [routerLink]="['/admin']">Administration</a>
-    </div>
-  </div>
-</menu>
diff --git a/client/src/app/menu.component.ts b/client/src/app/menu.component.ts
deleted file mode 100644 (file)
index d1a1d51..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-import { Component, OnInit } from '@angular/core';
-import { Router } from '@angular/router';
-
-import { AuthService } from './core';
-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']);
-  }
-}