From abaf75fb294a796fc6c99904ab3b47a2367a3792 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 16 Mar 2017 09:03:22 +0000
Subject: [PATCH] #3527 fix - Added logout button and routing refactoring 

---
 securis/src/main/webapp/src/app/login.form.component.ts     |    2 
 securis/src/main/webapp/src/app/menu.component.ts           |   10 ++++-
 securis/src/main/webapp/src/app/pack.list.component.html    |    2 
 securis/src/main/webapp/src/app/license.list.component.html |    2 
 securis/src/main/webapp/src/app/nomenu.component.html       |    4 +
 securis/src/main/webapp/src/app/footer.component.html       |    3 -
 securis/src/main/webapp/src/app/menu.component.html         |   10 ++++
 securis/src/main/webapp/src/app/home.component.ts           |    1 
 securis/src/main/webapp/src/app/user.service.ts             |   24 +++++------
 securis/src/main/webapp/src/app/app.routes.ts               |   11 ++---
 10 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/securis/src/main/webapp/src/app/app.routes.ts b/securis/src/main/webapp/src/app/app.routes.ts
index 060a1ff..f77e03c 100644
--- a/securis/src/main/webapp/src/app/app.routes.ts
+++ b/securis/src/main/webapp/src/app/app.routes.ts
@@ -8,8 +8,10 @@
 import { LoginFormComponent } from './login.form.component';
 
 const routes: Routes = [
- // {path: '', redirectTo: '/packs', pathMatch: 'full'}, 
-  {path: 'menu', component: MenuComponent,
+  {path: 'public',  component: NoMenuComponent, children: [
+    {path: 'login', component: LoginFormComponent },
+  },
+  {path: '', component: MenuComponent,
     children: [
         {path: 'packs', children: [
           {path: '', component: PackListComponent },
@@ -17,11 +19,6 @@
         ]}
     ]
   },
-  {path: 'nomenu', component: NoMenuComponent,
-    children: [
-      {path: 'login', component: LoginFormComponent }
-    ]
-  }
 
 ];
 /*    {path: 'product', component: DashboardProductComponent, children: [
diff --git a/securis/src/main/webapp/src/app/footer.component.html b/securis/src/main/webapp/src/app/footer.component.html
index 73b77de..66f815b 100644
--- a/securis/src/main/webapp/src/app/footer.component.html
+++ b/securis/src/main/webapp/src/app/footer.component.html
@@ -1,7 +1,6 @@
-  <td-layout-footer>
 	<div layout="row" layout-align="start center" flex>
 		<div flex layout="row" layout-align="start center">v.  {{securisVersion}}</div>
 		<div flex layout="row" layout-align="center center"><a href="http://www.curistec.com/" target="_blank">CurisTec</a>&nbsp;©2017</div>
 		<div flex></div>
 	</div>
-  </td-layout-footer>
\ No newline at end of file
+  
\ No newline at end of file
diff --git a/securis/src/main/webapp/src/app/home.component.ts b/securis/src/main/webapp/src/app/home.component.ts
index de7dfb2..984e1ae 100644
--- a/securis/src/main/webapp/src/app/home.component.ts
+++ b/securis/src/main/webapp/src/app/home.component.ts
@@ -53,7 +53,6 @@
   }
 
   ngOnInit(): void {
-      this.router.navigateByUrl('nomenu/login');
   }
 
   ngAfterViewInit(): void {
diff --git a/securis/src/main/webapp/src/app/license.list.component.html b/securis/src/main/webapp/src/app/license.list.component.html
index 9bab9a4..7a33cfd 100644
--- a/securis/src/main/webapp/src/app/license.list.component.html
+++ b/securis/src/main/webapp/src/app/license.list.component.html
@@ -66,7 +66,7 @@
         </div>
       </template>
     </td-data-table>
-    <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= pagingBar.pageSize" >
+    <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= 10" >
       <span i18n td-paging-bar-label hide-xs>Rows per page:</span> {{pagingBar.range}} <span hide-xs>of {{pagingBar.total}}</span>
     </td-paging-bar>
   </div>
diff --git a/securis/src/main/webapp/src/app/login.form.component.ts b/securis/src/main/webapp/src/app/login.form.component.ts
index c89259b..972ac97 100644
--- a/securis/src/main/webapp/src/app/login.form.component.ts
+++ b/securis/src/main/webapp/src/app/login.form.component.ts
@@ -26,7 +26,7 @@
   public login() {
     this.userService.login(this.data.username, this.data.password).subscribe(
       token => {
-        this.router.navigateByUrl("menu/packs");
+        this.router.navigateByUrl("packs");
       },
       errMsg => this.toaster.error(errMsg, 'Login error'));
   }
diff --git a/securis/src/main/webapp/src/app/menu.component.html b/securis/src/main/webapp/src/app/menu.component.html
index 074ca74..6cc9d20 100644
--- a/securis/src/main/webapp/src/app/menu.component.html
+++ b/securis/src/main/webapp/src/app/menu.component.html
@@ -31,8 +31,16 @@
   </md-nav-list>
 
 <td-layout-nav toolbarTitle="SeCuris" logo="assets:logo-white">
+  <div td-toolbar-content layout="row" layout-align="start center" flex>
+    <span flex ></span>
+    <button md-icon-button (click)="logout()">
+        <md-icon color="white">exit_to_app</md-icon>
+    </button>
+  </div>
 	<router-outlet></router-outlet>
-  <app-footer></app-footer>
+  <td-layout-footer>
+    <app-footer></app-footer>
+  </td-layout-footer>
 </td-layout-nav>
 </td-layout>
 
diff --git a/securis/src/main/webapp/src/app/menu.component.ts b/securis/src/main/webapp/src/app/menu.component.ts
index ab65248..0e5cd83 100644
--- a/securis/src/main/webapp/src/app/menu.component.ts
+++ b/securis/src/main/webapp/src/app/menu.component.ts
@@ -22,10 +22,16 @@
       this.userService.isLoggedIn().subscribe(authOk => {
         let isLoggedIn = authOk.valueOf();
         if (!isLoggedIn) {
-          this.router.navigateByUrl('nomenu/login');
+          this.router.navigateByUrl('public/login');
+        } else {
+          this.router.navigate(['packs']);
         }
       }  , 
-      err => /* Show message */ this.router.navigateByUrl('nomenu/login'));  
+      err => /* Show message */ this.router.navigateByUrl('public/login'));  
+  }
+
+  public logout() {
+    this.userService.logout();
   }
 
   public closeMenu() {
diff --git a/securis/src/main/webapp/src/app/nomenu.component.html b/securis/src/main/webapp/src/app/nomenu.component.html
index 59ed3ce..59873b8 100644
--- a/securis/src/main/webapp/src/app/nomenu.component.html
+++ b/securis/src/main/webapp/src/app/nomenu.component.html
@@ -1,4 +1,6 @@
 <td-layout-nav toolbarTitle="SeCuris" logo="assets:logo-white">
 	<router-outlet></router-outlet>
-  <app-footer></app-footer>
+	<td-layout-footer>
+		<app-footer></app-footer>
+	</td-layout-footer>
 </td-layout-nav>
diff --git a/securis/src/main/webapp/src/app/pack.list.component.html b/securis/src/main/webapp/src/app/pack.list.component.html
index 710e5b9..7e2a344 100644
--- a/securis/src/main/webapp/src/app/pack.list.component.html
+++ b/securis/src/main/webapp/src/app/pack.list.component.html
@@ -49,7 +49,7 @@
         </div>
       </template>
     </td-data-table>
-    <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= pagingBar.pageSize">
+    <td-paging-bar #pagingBar [pageSizes]="[10, 20, 40]" [total]="filteredTotal" (change)="page($event)" [hidden]="pagingBar.total <= 10">
       <span td-paging-bar-label hide-xs>Rows per page:</span> {{pagingBar.range}} <span hide-xs>of {{pagingBar.total}}</span>
     </td-paging-bar>
   </div>
diff --git a/securis/src/main/webapp/src/app/user.service.ts b/securis/src/main/webapp/src/app/user.service.ts
index 1d7e3e6..e4dac43 100644
--- a/securis/src/main/webapp/src/app/user.service.ts
+++ b/securis/src/main/webapp/src/app/user.service.ts
@@ -27,14 +27,14 @@
     params.append('password', password);
     let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
     return this.http.post('user/login', params.toString(), options)
-                    .map(this.mapLogin)
+                    .map((resp) => this.mapLogin(resp))
                     .catch(this.handleError);
   }
 
-  private mapLogin(res : Response) {
+  private mapLogin(res : Response) : string {
     let data = res.json();
-    //this.store.set('username', data.username);
-		//this.store.set('token', data.token);
+    this.store.set('username', data.username);
+		this.store.set('token', data.token);
     return <string>data.token;
   }    
 
@@ -45,16 +45,16 @@
     var token = this.store.get("token");
     let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
     return this.http.get('check', option)
-                    .map(this.mapCheck)
+                    .map((resp) => this.mapCheck(resp))
                     .catch(this.handleError);
   }
 
-  private mapCheck(res : Response) {
-    let body = res.json();
-    if (body.valid) {
-      //this.store.set('user', body.user);
+  private mapCheck(res : Response) : boolean {
+    let data = res.json();
+    if (data.valid) {
+      this.store.set('user', data.user);
     }
-    return body.valid;
+    return data.valid;
   }  
 
   existsToken() : Boolean {
@@ -63,10 +63,8 @@
 
   logout() : void {
     this.store.remove('user', 'token');
-    this.router.navigate(['Login']);
+    this.router.navigate(['public/login']);
   }
-
-
 
 
   private handleError (error: Response | any) {

--
Gitblit v1.3.2