César Calvo
2017-03-15 199b9ae1c2818713bbb1a33831c46fb505e997d4
#3527 - Main menu
6 files added
6 files modified
changed files
securis/src/main/webapp/src/app/app.module.ts patch | view | blame | history
securis/src/main/webapp/src/app/app.routes.ts patch | view | blame | history
securis/src/main/webapp/src/app/footer.component.html patch | view | blame | history
securis/src/main/webapp/src/app/footer.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/home.component.html patch | view | blame | history
securis/src/main/webapp/src/app/home.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/login.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/menu.component.html patch | view | blame | history
securis/src/main/webapp/src/app/menu.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/nomenu.component.html patch | view | blame | history
securis/src/main/webapp/src/app/nomenu.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/user.service.ts patch | view | blame | history
securis/src/main/webapp/src/app/app.module.ts
....@@ -23,6 +23,10 @@
2323 import { PackListComponent } from './pack.list.component';
2424 import { HeroDetailComponent } from './detail.component';
2525 import { LoginFormComponent } from './login.form.component';
26
+import { MenuComponent } from './menu.component';
27
+import { NoMenuComponent } from './nomenu.component';
28
+import { FooterComponent } from './footer.component';
29
+
2630
2731 import { appRoutes, appRoutingProviders } from './app.routes';
2832 import { requestOptionsProvider, requestBackendProvider } from './common/default.requests.options';
....@@ -53,7 +57,10 @@
5357 LoginFormComponent,
5458 ErrorCheckerComponent,
5559 I18nDirective,
56
- HomeComponent
60
+ HomeComponent,
61
+ MenuComponent,
62
+ NoMenuComponent,
63
+ FooterComponent
5764 ],
5865 bootstrap: [ HomeComponent ],
5966 entryComponents: [ PackFormComponent ],
securis/src/main/webapp/src/app/app.routes.ts
....@@ -1,13 +1,23 @@
11 import { Routes, RouterModule } from '@angular/router';
22
33 import { HomeComponent } from './home.component';
4
+import { MenuComponent } from './menu.component';
5
+import { NoMenuComponent } from './nomenu.component';
46 import { PackListComponent } from './pack.list.component';
57 import { LoginFormComponent } from './login.form.component';
68
79 const routes: Routes = [
810 // {path: '', redirectTo: '/packs', pathMatch: 'full'},
9
- {path: 'packs', component: PackListComponent },
10
- {path: 'login', component: LoginFormComponent }
11
+ {path: 'menu', component: MenuComponent,
12
+ children: [
13
+ {path: 'packs', component: PackListComponent }
14
+ ]
15
+ },
16
+ {path: 'nomenu', component: NoMenuComponent,
17
+ children: [
18
+ {path: 'login', component: LoginFormComponent }
19
+ ]
20
+ }
1121 ];
1222 /* {path: 'product', component: DashboardProductComponent, children: [
1323 {path: '', component: ProductOverviewComponent},
securis/src/main/webapp/src/app/footer.component.html
....@@ -0,0 +1,7 @@
1
+ <td-layout-footer>
2
+ <div layout="row" layout-align="start center" flex>
3
+ <div flex layout="row" layout-align="start center">v. {{securisVersion}}</div>
4
+ <div flex layout="row" layout-align="center center"><a href="http://www.curistec.com/" target="_blank">CurisTec</a>&nbsp;©2017</div>
5
+ <div flex></div>
6
+ </div>
7
+ </td-layout-footer>
securis/src/main/webapp/src/app/footer.component.ts
....@@ -0,0 +1,28 @@
1
+import { Component } from '@angular/core';
2
+import { BaseRequestOptions, Http } from '@angular/http';
3
+
4
+
5
+@Component({
6
+ selector: 'app-footer',
7
+ templateUrl: 'src/app/footer.component.html'
8
+})
9
+export class FooterComponent {
10
+
11
+ securisVersion : string = '0.0.0';
12
+
13
+ constructor(
14
+ private http: Http,
15
+ ) {
16
+ }
17
+
18
+ ngOnInit(): void {
19
+ //TODO Move to service
20
+ this.http.get("version", /* workaround to avoid OPTIONS method request*/ new BaseRequestOptions())
21
+ .map((res) => <string>res.json().version)
22
+ .subscribe(
23
+ version => this.securisVersion = version,
24
+ err => this.securisVersion = '0.0.0'
25
+ );
26
+ }
27
+
28
+}
securis/src/main/webapp/src/app/home.component.html
....@@ -1,54 +1,2 @@
1
-<td-layout *ngIf="isLoggedIn">
2
- <td-navigation-drawer #mainMenu sidenavTitle="SeCuris">
3
- </td-navigation-drawer>
41
5
- <md-nav-list td-sidenav-content>
6
- <a routerLink="/packs" md-list-item (click)="closeMenu()">
7
- <md-icon md-list-avatar>view_compact</md-icon>
8
- <h3 md-line i18n="menu.packs"> </h3>
9
- <p md-line i18n="menu.packs.description"> </p>
10
- </a>
11
- <a routerLink="/packs" md-list-item (click)="closeMenu()">
12
- <md-icon md-list-avatar>view_compact</md-icon>
13
- <h3 md-line i18n="menu.applications"> </h3>
14
- <p md-line i18n="menu.applications.description"> </p>
15
- </a>
16
- <a routerLink="/packs" md-list-item (click)="closeMenu()">
17
- <md-icon md-list-avatar>view_compact</md-icon>
18
- <h3 md-line i18n="menu.license_types"> </h3>
19
- <p md-line i18n="menu.license_types.description"> </p>
20
- </a>
21
- <a routerLink="/packs" md-list-item (click)="closeMenu()">
22
- <md-icon md-list-avatar>view_compact</md-icon>
23
- <h3 md-line i18n="menu.organizations"> </h3>
24
- <p md-line i18n="menu.organizations.description"> </p>
25
- </a>
26
- <a routerLink="/packs" md-list-item (click)="closeMenu()">
27
- <md-icon md-list-avatar>view_compact</md-icon>
28
- <h3 md-line i18n="menu.users"> </h3>
29
- <p md-line i18n="menu.users.description"> </p>
30
- </a>
31
- </md-nav-list>
32
-
33
-<td-layout-nav toolbarTitle="SeCuris" logo="assets:logo-white">
342 <router-outlet></router-outlet>
35
- <td-layout-footer>
36
- <div layout="row" layout-align="start center" flex>
37
- <div flex layout="row" layout-align="start center">v. {{securisVersion}}</div>
38
- <div flex layout="row" layout-align="center center"><a href="http://www.curistec.com/" target="_blank">CurisTec</a>&nbsp;©2017</div>
39
- <div flex></div>
40
- </div>
41
- </td-layout-footer>
42
-</td-layout-nav>
43
-</td-layout>
44
-
45
-<td-layout-nav *ngIf="!isLoggedIn" toolbarTitle="SeCuris" logo="assets:logo-white">
46
- <router-outlet></router-outlet>
47
- <td-layout-footer>
48
- <div layout="row" layout-align="start center" flex>
49
- <div flex layout="row" layout-align="start center">v. {{securisVersion}}</div>
50
- <div flex layout="row" layout-align="center center"><a href="http://www.curistec.com/" target="_blank">CurisTec</a>&nbsp;©2017</div>
51
- <div flex></div>
52
- </div>
53
- </td-layout-footer>
54
-</td-layout-nav>
securis/src/main/webapp/src/app/home.component.ts
....@@ -28,20 +28,12 @@
2828 toaster: ToastsManager,
2929 vRef: ViewContainerRef,
3030 private router: Router,
31
- http: Http,
3231 private media: TdMediaService,
3332 private _iconRegistry: MdIconRegistry,
3433 private _domSanitizer: DomSanitizer,
3534 private store: LocalStorageService) {
3635 this.registerIcons();
3736 toaster.setRootViewContainerRef(vRef);
38
- http.get("version", /* workaround to avoid OPTIONS method request*/ new BaseRequestOptions())
39
- .map((res) => <string>res.json().version)
40
- .subscribe(
41
- version => this.securisVersion = version,
42
- err => this.securisVersion = '0.0.0'
43
- );
44
-
4537 }
4638
4739 private registerIcons() : void {
....@@ -61,11 +53,7 @@
6153 }
6254
6355 ngOnInit(): void {
64
- this.userService.isLoggedIn().subscribe(authOk => {
65
- this.isLoggedIn = true//authOk.valueOf();
66
- this.router.navigateByUrl(this.isLoggedIn ? 'packs' : 'login');
67
- } ,
68
- err => /* Show message */ this.router.navigateByUrl('login'));
56
+ this.router.navigateByUrl('nomenu/login');
6957 }
7058
7159 ngAfterViewInit(): void {
securis/src/main/webapp/src/app/login.form.component.ts
....@@ -26,7 +26,7 @@
2626 public login() {
2727 this.userService.login(this.data.username, this.data.password).subscribe(
2828 token => {
29
- this.router.navigateByUrl("packs");
29
+ this.router.navigateByUrl("menu/packs");
3030 },
3131 errMsg => this.toaster.error(errMsg, 'Login error'));
3232 }
securis/src/main/webapp/src/app/menu.component.html
....@@ -0,0 +1,38 @@
1
+<td-layout>
2
+ <td-navigation-drawer #mainMenu sidenavTitle="SeCuris">
3
+ </td-navigation-drawer>
4
+
5
+ <md-nav-list td-sidenav-content>
6
+ <a routerLink="/menu/packs" md-list-item (click)="closeMenu()">
7
+ <md-icon md-list-avatar>view_compact</md-icon>
8
+ <h3 md-line i18n="menu.packs"> </h3>
9
+ <p md-line i18n="menu.packs.description"> </p>
10
+ </a>
11
+ <a routerLink="/menu/packs" md-list-item (click)="closeMenu()">
12
+ <md-icon md-list-avatar>view_compact</md-icon>
13
+ <h3 md-line i18n="menu.applications"> </h3>
14
+ <p md-line i18n="menu.applications.description"> </p>
15
+ </a>
16
+ <a routerLink="/menu/packs" md-list-item (click)="closeMenu()">
17
+ <md-icon md-list-avatar>view_compact</md-icon>
18
+ <h3 md-line i18n="menu.license_types"> </h3>
19
+ <p md-line i18n="menu.license_types.description"> </p>
20
+ </a>
21
+ <a routerLink="/menu/packs" md-list-item (click)="closeMenu()">
22
+ <md-icon md-list-avatar>view_compact</md-icon>
23
+ <h3 md-line i18n="menu.organizations"> </h3>
24
+ <p md-line i18n="menu.organizations.description"> </p>
25
+ </a>
26
+ <a routerLink="/menu/packs" md-list-item (click)="closeMenu()">
27
+ <md-icon md-list-avatar>view_compact</md-icon>
28
+ <h3 md-line i18n="menu.users"> </h3>
29
+ <p md-line i18n="menu.users.description"> </p>
30
+ </a>
31
+ </md-nav-list>
32
+
33
+<td-layout-nav toolbarTitle="SeCuris" logo="assets:logo-white">
34
+ <router-outlet></router-outlet>
35
+ <app-footer></app-footer>
36
+</td-layout-nav>
37
+</td-layout>
38
+
securis/src/main/webapp/src/app/menu.component.ts
....@@ -0,0 +1,35 @@
1
+import { Observable } from 'rxjs/Observable';
2
+import { BaseRequestOptions, Http } from '@angular/http';
3
+import { Component, ViewChild } from '@angular/core';
4
+import { UserService } from './user.service';
5
+import { Router } from '@angular/router';
6
+import { TdNavigationDrawerComponent } from '@covalent/core'
7
+
8
+
9
+@Component({
10
+ templateUrl: 'src/app/menu.component.html'
11
+})
12
+export class MenuComponent {
13
+
14
+ @ViewChild('mainMenu') mainMenu: TdNavigationDrawerComponent;
15
+
16
+
17
+ constructor(private userService: UserService,
18
+ private router: Router) {
19
+ }
20
+
21
+ ngOnInit(): void {
22
+ this.userService.isLoggedIn().subscribe(authOk => {
23
+ let isLoggedIn = authOk.valueOf();
24
+ if (!isLoggedIn) {
25
+ this.router.navigateByUrl('nomenu/login');
26
+ }
27
+ } ,
28
+ err => /* Show message */ this.router.navigateByUrl('nomenu/login'));
29
+ }
30
+
31
+ public closeMenu() {
32
+ this.mainMenu.close();
33
+ }
34
+
35
+}
securis/src/main/webapp/src/app/nomenu.component.html
....@@ -0,0 +1,4 @@
1
+<td-layout-nav toolbarTitle="SeCuris" logo="assets:logo-white">
2
+ <router-outlet></router-outlet>
3
+ <app-footer></app-footer>
4
+</td-layout-nav>
securis/src/main/webapp/src/app/nomenu.component.ts
....@@ -0,0 +1,29 @@
1
+import { Observable } from 'rxjs/Observable';
2
+import { BaseRequestOptions, Http } from '@angular/http';
3
+import { ToastsManager } from 'ng2-toastr/ng2-toastr';
4
+import { AfterViewInit, Component, ViewContainerRef, ViewChild } from '@angular/core';
5
+import { DomSanitizer } from '@angular/platform-browser';
6
+import { MdIconRegistry } from '@angular/material';
7
+import { UserService } from './user.service';
8
+import { LocalStorageService } from 'angular-2-local-storage';
9
+import { TdMediaService } from '@covalent/core';
10
+import { Router } from '@angular/router';
11
+import { TdNavigationDrawerComponent } from '@covalent/core'
12
+
13
+// https://github.com/Teradata/covalent-quickstart/tree/develop/src/app
14
+// https://teradata.github.io/covalent-quickstart/#/
15
+
16
+@Component({
17
+ templateUrl: 'src/app/nomenu.component.html'
18
+})
19
+export class NoMenuComponent {
20
+
21
+
22
+ securisVersion : string;
23
+
24
+ constructor() {
25
+
26
+ }
27
+
28
+
29
+}
securis/src/main/webapp/src/app/user.service.ts
....@@ -12,6 +12,8 @@
1212 @Injectable()
1313 export class UserService {
1414
15
+ count : number = 0;
16
+
1517 constructor(private $L: LocaleService,
1618 private router: Router,
1719 private store: LocalStorageService,
....@@ -25,31 +27,35 @@
2527 params.append('password', password);
2628 let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
2729 return this.http.post('user/login', params.toString(), options)
28
- .map((res: Response) => {
29
- let data = res.json();
30
- this.store.set('username', username);
31
- this.store.set('token', data.token);
32
- return <string>data.token;
33
- })
34
- .catch((r) => this.handleError(r));
30
+ .map(this.mapLogin)
31
+ .catch(this.handleError);
3532 }
33
+
34
+ private mapLogin(res : Response) {
35
+ let data = res.json();
36
+ //this.store.set('username', data.username);
37
+ //this.store.set('token', data.token);
38
+ return <string>data.token;
39
+ }
3640
3741 isLoggedIn() : Observable<Boolean> {
3842 if (!this.existsToken()) {
3943 return Observable.of(false);
4044 }
4145 var token = this.store.get("token");
42
- return this.http.get('check', new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) }))
43
- .map((res: Response) => {
44
- let body = res.json();
45
- if (body.valid) {
46
- this.store.set('user', body.user);
47
- }
48
- return body.valid;
49
- })
50
- .catch((r) => this.handleError(r))
51
- .catch(() => Observable.of(false));
46
+ let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
47
+ return this.http.get('check', option)
48
+ .map(this.mapCheck)
49
+ .catch(this.handleError);
5250 }
51
+
52
+ private mapCheck(res : Response) {
53
+ let body = res.json();
54
+ if (body.valid) {
55
+ //this.store.set('user', body.user);
56
+ }
57
+ return body.valid;
58
+ }
5359
5460 existsToken() : Boolean {
5561 return this.store.get("token") !== null;
....@@ -60,6 +66,9 @@
6066 this.router.navigate(['Login']);
6167 }
6268
69
+
70
+
71
+
6372 private handleError (error: Response | any) {
6473 // In a real world app, we might use a remote logging infrastructure
6574 let errMsg: string;