rsanchez
2017-03-15 a6b5178c7295be4525ee0f607e42f72a12a2e3d6
#3527 fix - Changes on licenses list and routes
6 files modified
changed files
securis/src/main/webapp/src/app/app.module.ts patch | view | blame | history
securis/src/main/webapp/src/app/license.list.component.html patch | view | blame | history
securis/src/main/webapp/src/app/license.list.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/pack.list.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/licenses.ts patch | view | blame | history
securis/src/main/webapp/src/app/resources/packs.ts patch | view | blame | history
securis/src/main/webapp/src/app/app.module.ts
....@@ -24,6 +24,8 @@
2424 import { HeroDetailComponent } from './detail.component';
2525 import { LoginFormComponent } from './login.form.component';
2626 import { LicenseListComponent } from './license.list.component';
27
+import { LicenseFormComponent } from './forms/license.form.component';
28
+
2729
2830 import { appRoutes, appRoutingProviders } from './app.routes';
2931 import { requestOptionsProvider, requestBackendProvider } from './common/default.requests.options';
....@@ -54,17 +56,19 @@
5456 LoginFormComponent,
5557 ErrorCheckerComponent,
5658 LicenseListComponent,
59
+ LicenseFormComponent,
5760 I18nDirective,
5861 HomeComponent
5962 ],
6063 bootstrap: [ HomeComponent ],
61
- entryComponents: [ PackFormComponent ],
64
+ entryComponents: [ PackFormComponent, LicenseFormComponent ],
6265 providers: [
6366 SeCurisSession,
6467 UserService,
6568 PacksService,
6669 LicensesService,
6770 PackFormComponent,
71
+ LicenseFormComponent,
6872 ApplicationsService,
6973 OrganizationsService,
7074 LicenseTypesService,
securis/src/main/webapp/src/app/license.list.component.html
....@@ -1,46 +1,66 @@
11 <md-toolbar role="toolbar" class="mat-secondary">
22 <span class="push-left-sm">
3
- <span class="md-title" i18n>License Packs</span>
3
+ <button md-icon-button (click)="goBack" color="accent">
4
+ <md-icon class="md-36">arrow_back</md-icon>
5
+ </button>
6
+ <span class="md-title" i18n>Licenses for pack</span>: {{pack?.code}}
47 </span>
58 <span class="push-left-sm" *ngIf="filteredItems < data.length">
69 <span class="md-body-1">{{filteredItems}} of {{data.length}} packs filtered</span>
710 </span>
811 <td-search-box #searchBox class="push-right-sm" placeholder="Search here" (searchDebounce)="search($event)" flex>
912 </td-search-box>
10
- <button md-mini-fab color="accent" (click)="createPack()">
13
+ <button md-mini-fab color="accent" (click)="createLicense()">
1114 <md-icon>add</md-icon>
1215 </button>
16
+ <md-toolbar-row *ngIf="!!pack">
17
+ <md-chip-list flex="80" style="margin-left: 70px;">
18
+ <md-chip selected [mdTooltip]="$L.get('field.application_name')" color="primary">{{pack.application_name}} </md-chip>
19
+ <md-chip selected [mdTooltip]="$L.get('field.organization_id')" color="accent">{{pack.organization_name}} </md-chip>
20
+ <md-chip selected [mdTooltip]="$L.get('field.license_type_id')" color="accent">{{pack.licensetype_code}} </md-chip>
21
+ <md-chip selected [mdTooltip]="$L.get('field.num_available')" color="accent">{{pack.num_available}} </md-chip>
22
+ </md-chip-list>
23
+ </md-toolbar-row>
1324 </md-toolbar>
1425 <md-divider></md-divider>
1526 <div layout="row" layout-align="center center">
1627 <div flex="80" layout="column" layout-align="end center" >
17
-<td-data-table [data]="filteredData" [columns]="columns" style="width: 100%">
18
- <template tdDataTableTemplate="used_licenses" let-row="row">
28
+<td-data-table
29
+ [data]="filteredData"
30
+ [columns]="columns"
31
+ [sortable]="true"
32
+ [sortBy]="sortBy"
33
+ (sortChange)="sort($event)"
34
+ style="width: 100%">
35
+ <template tdDataTableTemplate="status" let-row="row">
1936 <div layout="row">
20
- <td-notification-count color="secondary" [notifications]="row['num_licenses']">
21
- </td-notification-count>
22
- <td-notification-count color="primary" [notifications]="row['num_available']">
23
- </td-notification-count>
37
+ <md-chip-list>
38
+ <md-icon [style]="'color: ' + licenses.getStatusColor(row.status)">brightness_1</md-icon>&nbsp;<span>{{licenses.getStatusName(row.status)}}</span>
39
+ </md-chip-list>
2440 </div>
2541 </template>
26
- <template tdDataTableTemplate="code" let-row="row" let-value="value">
27
- <div layout="row" layout-align="start center">
28
- <span style="white-space: nowrap">{{value}}</span>
42
+ <template tdDataTableTemplate="email" let-row="row">
43
+ <div layout="row">
44
+ <a [href]="'mailto:' + row.email + '?subject=SeCuris'">{{row.email}}</a>
2945 </div>
3046 </template>
47
+ <template tdDataTableTemplate="expiration_date" let-row="row">
48
+ <div layout="row">
49
+ <span [class]="isLicenseExpired(row) ? 'warn' : ''" >{{row.expiration_date | date: 'short'}}</span>
50
+ </div>
51
+ </template>
52
+
3153 <template tdDataTableTemplate="menu" let-row="row" let-index="index">
3254 <div layout="row" layout-align="end center">
33
- <button md-icon-button (click)="editPack(row)" color="primary"><md-icon>edit</md-icon></button>
34
- <button md-icon-button [mdMenuTriggerFor]="packMenu" aria-label="Pack menu">
55
+ <button md-icon-button (click)="editLicense(row)" color="primary"><md-icon>edit</md-icon></button>
56
+ <button md-icon-button [mdMenuTriggerFor]="licenseMenu" aria-label="License menu">
3557 <md-icon>more_vert</md-icon>
3658 </button>
37
-
38
- <md-menu #packMenu="mdMenu">
39
- <button md-menu-item *ngFor="let action of pack_menu_options" (click)="packAction(action.command, row)" [disabled]="!isActionAvailable(row)">
59
+ <md-menu #licenseMenu="mdMenu">
60
+ <button md-menu-item *ngFor="let action of license_menu_options" (click)="licenseAction(action.command, row)" [disabled]="!isActionAvailable(row)">
4061 <md-icon *ngIf="!!action.icon">{{ action.icon }}</md-icon> {{ action.name }}
4162 </button>
4263 </md-menu>
43
- <button md-icon-button (click)="showLicenses(row)" color="accent"><md-icon>arrow_forward</md-icon></button>
4464 </div>
4565 </template>
4666 </td-data-table>
securis/src/main/webapp/src/app/license.list.component.ts
....@@ -1,10 +1,13 @@
1
-import { Router } from '@angular/router';
1
+import { LocaleService } from './common/i18n';
2
+import { ActivatedRoute, Router } from '@angular/router';
23 import { MdDialog, MdDialogConfig } from '@angular/material';
34 import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
45 import { IPageChangeEvent } from '@covalent/core';
56 import { Component, AfterViewInit } from '@angular/core';
67 import { TdMediaService } from '@covalent/core';
78 import { LicensesService } from './resources/licenses';
9
+import { PacksService } from './resources/packs';
10
+
811 import { LicenseFormComponent } from './forms/license.form.component';
912
1013 var lic_example = { activation_code: '19fa8d30-29cb-4b59-81b5-3837af8204b6',
....@@ -34,12 +37,13 @@
3437 })
3538 export class LicenseListComponent implements AfterViewInit {
3639 data: any[] = [];
40
+ pack: any = null;
3741 columns: ITdDataTableColumn[] = [
38
- { name: 'code', label: 'Code', tooltip: 'License pack code' },
39
- { name: 'application_name', label: 'App name' },
40
- { name: 'licensetype_code', label: 'License type' },
41
- { name: 'organization_name', label: 'Organization' },
42
- { name: 'used_licenses', label: 'Lics', tooltip: 'Initial/Available pack licenses' },
42
+ { name: 'code', label: 'Code', tooltip: 'License code' },
43
+ { name: 'full_name', label: 'User name' },
44
+ { name: 'email', label: 'User email' },
45
+ { name: 'expiration_date', label: 'Expiration date' },
46
+ { name: 'status', label: 'Status' },
4347 { name: 'menu', label: '' }
4448 ];
4549
....@@ -50,7 +54,7 @@
5054 fromRow: number = 1;
5155 currentPage: number = 1;
5256 pageSize: number = 10;
53
- sortBy: string = 'application_name';
57
+ sortBy: string = 'expiration_date';
5458 sortOrder: TdDataTableSortingOrder = TdDataTableSortingOrder.Descending;
5559 filteredItems = this.data.length;
5660 license_menu_options : any[] = [{
....@@ -73,21 +77,36 @@
7377
7478 constructor(private _dataTableService: TdDataTableService,
7579 private media: TdMediaService,
80
+ private $L: LocaleService,
7681 private router: Router,
82
+ private route: ActivatedRoute,
7783 private dialog: MdDialog,
7884 private licenseForm: LicenseFormComponent,
79
- private licenses: LicensesService) {
80
- this.licenses.get().subscribe(
81
- list => {
82
- this.data = list;
83
- this.filter();
84
- },
85
- err => console.error(err)
86
- );
85
+ private licenses: LicensesService,
86
+ private packs: PacksService) {
8787 }
8888
8989 ngOnInit(): void {
90
- this.filter();
90
+ this.route.params.subscribe(params => {
91
+ var packId = +params['id']; // (+) converts string 'id' to a number
92
+ this.licenses.getByPack(packId).subscribe(
93
+ list => {
94
+ this.data = list;
95
+ this.filter();
96
+ },
97
+ err => console.error(err)
98
+ );
99
+ this.packs.get(packId).subscribe(
100
+ packData => {
101
+ this.pack = packData;
102
+ },
103
+ err => console.error(err)
104
+ );
105
+ });
106
+ }
107
+
108
+ isLicenseExpired(lic: any): boolean {
109
+ return lic.expiration_date < (new Date().getTime());
91110 }
92111
93112 createLicense() : void {
securis/src/main/webapp/src/app/pack.list.component.ts
....@@ -1,4 +1,4 @@
1
-import { Router } from '@angular/router';
1
+import { Router, ActivatedRoute } from '@angular/router';
22 import { MdDialog, MdDialogConfig } from '@angular/material';
33 import { TdDataTableService, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
44 import { IPageChangeEvent } from '@covalent/core';
....@@ -54,7 +54,7 @@
5454 { name: 'application_name', label: 'App name' },
5555 { name: 'licensetype_code', label: 'License type' },
5656 { name: 'organization_name', label: 'Organization' },
57
- { name: 'used_licenses', label: 'Lics', tooltip: 'Initial/Available pack licenses' },
57
+ { name: 'used_licenses', label: 'Licenses', tooltip: 'Initial/Available pack licenses' },
5858 { name: 'menu', label: '' }
5959 ];
6060
....@@ -87,6 +87,7 @@
8787 constructor(private _dataTableService: TdDataTableService,
8888 private media: TdMediaService,
8989 private router: Router,
90
+ private route: ActivatedRoute,
9091 private dialog: MdDialog,
9192 private $L: LocaleService,
9293 private packForm: PackFormComponent,
....@@ -114,7 +115,7 @@
114115 }
115116
116117 showLicenses(pack: any) : void {
117
- this.router.navigateByUrl('/licenses');
118
+ this.router.navigate([`${pack.id}/licenses`], {relativeTo: this.route});
118119 }
119120
120121 editPack(pack: any) : void {
securis/src/main/webapp/src/app/resources/licenses.ts
....@@ -1,3 +1,4 @@
1
+import { LocaleService } from '../common/i18n';
12 import { Observable } from 'rxjs/Rx';
23 import { Injectable } from '@angular/core';
34 import { Http, RequestOptions } from '@angular/http';
....@@ -21,14 +22,6 @@
2122 status: 'AC'
2223 }
2324
24
-export const PACK_STATUS = {
25
- CREATED: 'CR',
26
- ACTIVE: 'AC',
27
- ONHOLD: 'OH',
28
- EXPIRED: 'EX',
29
- CANCELLED: 'CA'
30
-}
31
-
3225 export const LIC_STATUS = {
3326 CREATED: 'CR',
3427 ACTIVE: 'AC',
....@@ -38,6 +31,15 @@
3831 BLOCKED: 'BL',
3932 CANCELLED: 'CA'
4033 }
34
+
35
+export const COLORS_BY_STATUS = {
36
+ 'CR': '#808080',
37
+ 'AC': '#329e5a',
38
+ 'RE': '#2981d4',
39
+ 'EX': '#ea7824',
40
+ 'BL': '#ff0000',
41
+ 'CA': '#a21717'
42
+};
4143
4244 /**
4345 * These transitions could be get from server, class License.Status, but
....@@ -55,11 +57,10 @@
5557 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED, LIC_STATUS.BLOCKED]
5658 }
5759
58
-
59
-
6060 @Injectable()
6161 export class LicensesService extends SeCurisResourceServices {
62
- constructor(http: Http) {
62
+ constructor(http: Http,
63
+ private $L: LocaleService) {
6364 super(http, 'license');
6465 }
6566
....@@ -84,5 +85,14 @@
8485 var validStatuses = LIC_ACTIONS_BY_STATUS[action];
8586 return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1;
8687 }
88
+
89
+
90
+ getStatusName(statusCode: string): string {
91
+ return this.$L.get(`pack.status.${statusCode}`, this.$L.get('Unknown'));
92
+ }
93
+
94
+ getStatusColor(statusCode: string): string {
95
+ return COLORS_BY_STATUS[statusCode] || '#cccccc';
96
+ }
8797 }
8898
securis/src/main/webapp/src/app/resources/packs.ts
....@@ -82,7 +82,11 @@
8282 }
8383
8484 getStatusName(statusCode: string): string {
85
- return this.$L.get(`pack.status.${statusCode}`, this.$L.get('Unknown'));
85
+ return this.$L.get(`pack.status.${statusCode}`, this.$L.get('Unknown'));
86
+ }
87
+
88
+ getStatusColor(statusCode: string): string {
89
+ return COLORS_BY_STATUS[statusCode] || '#cccccc';
8690 }
8791
8892 }