rsanchez
2017-03-22 60c65f2110f65221bc3a71b2887667e78c53c53e
securis/src/main/webapp/src/app/resources/licenses.ts
....@@ -1,26 +1,9 @@
11 import { LocaleService } from '../common/i18n';
22 import { Observable } from 'rxjs/Rx';
33 import { Injectable } from '@angular/core';
4
-import { Http, RequestOptions } from '@angular/http';
4
+import { Http, RequestOptions, ResponseContentType, Response } from '@angular/http';
55 import { SeCurisResourceServices } from './base';
6
-
7
-var lic_example = {
8
- id: 101,
9
- activation_code: 'f3e2d27e-7f81-4ac7-87ba-b9e38b4fdbb8',
10
- code: 'CITR01-436-1',
11
- code_suffix: 1,
12
- created_by_id: '_client',
13
- creation_timestamp: 1445898088000,
14
- email: 'GQuercia@trican.ca',
15
- expiration_date: 1487523828000,
16
- full_name: 'George Quercia',
17
- licenseData: '{"appCode":"CICS","appName":"CurisIntegrity","licenseCode":"CITR01-436-1","activationCode":"f3e2d27e-7f81-4ac7-87ba-b9e38b4fdbb8","expirationDate":1487523828416,"arch":"amd64","osName":"Windows 7","macAddresses":["C4-D9-87-5D-53-72","C4-D9-87-5D-53-76","FC-15-B4-EB-70-F9"],"crcLogo":"10f6379e0e1c00ebc403160307e3c5d0aba0727c9cae0bf1ac7cd19d84fdc80f","metadata":{"a2Mode":"false","datasetPrefix":"TR","extendedMode":"false","maxConcurrentInstances":"-1","maxInstances":"3","maxUsers":"0","maxWellLifeLines":"50","timeThreshold":"0"},"signature":"cjyLYFyhXpWWsMNnG6ER9mtCREgw02aQDnXPSQQWZtiLWbu/GyHZzK+1msLhwuKMGYG6I90s5wp82HVIqhIheHOsov3JfnHgNtYzf3BdkqUinwPFuDqPqkXz5Sjb6bouWkmvTI1TN/s4U2DJOXVnYN4FnYl0/dBTcU9RP4NZlQxMu6oFuRrZSMfdMCxEJYZAU62SWgTSurkdmHhFgwRjIwsOXRWHYsr6vGT//yILI7UvMGbMc6dRCGwyJLPNi4nXwF9PRMLinB7fYK8HxKylTJx2O7bvWCZd6EOdwi6gRI/0HhOqZ7E4DzBDrqEnsHeuH4L47DfRdIMGDnA492F+mg=="}',
18
- modification_timestamp: 1484931828000,
19
- pack_code: 'CITR01',
20
- pack_id: 12,
21
- request_data: '{"appCode":"CICS","activationCode":"f3e2d27e-7f81-4ac7-87ba-b9e38b4fdbb8","arch":"amd64","osName":"Windows 7","macAddresses":["C4-D9-87-5D-53-72","C4-D9-87-5D-53-76","FC-15-B4-EB-70-F9"],"crcLogo":"10f6379e0e1c00ebc403160307e3c5d0aba0727c9cae0bf1ac7cd19d84fdc80f"}',
22
- status: 'AC'
23
-}
6
+import * as saveAsFile from "file-saver";
247
258 export const LIC_STATUS = {
269 CREATED: 'CR',
....@@ -41,6 +24,7 @@
4124 'CA': '#a21717'
4225 };
4326
27
+
4428 /**
4529 * These transitions could be get from server, class License.Status, but
4630 * we copy them for simplicity, this info won't change easily
....@@ -56,6 +40,37 @@
5640 cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE],
5741 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED, LIC_STATUS.BLOCKED]
5842 }
43
+
44
+export const LICENSE_ACTIONS : any[] = [{
45
+/* command: 'add_request',
46
+ icon: 'add_to_photos',
47
+ name: 'Add request'
48
+ },{ */
49
+ command: 'activate',
50
+ icon: 'play_circle_outline',
51
+ name: 'Activate'
52
+ },{
53
+ command: 'send',
54
+ icon: 'send',
55
+ name: 'Send'
56
+ },{
57
+ command: 'download',
58
+ icon: 'file_download',
59
+ name: 'Download'
60
+ },{
61
+ command: 'block',
62
+ icon: 'do_not_disturb_on',
63
+ name: 'Block'
64
+ },{
65
+ command: 'unblock',
66
+ icon: 'do_not_disturb_off',
67
+ name: 'Unblock'
68
+ },{
69
+ command: 'cancel',
70
+ icon: 'cancel',
71
+ name: 'Cancel'
72
+ }]
73
+
5974
6075 @Injectable()
6176 export class LicensesService extends SeCurisResourceServices {
....@@ -73,19 +88,36 @@
7388 return super.action(id, "activate");
7489 }
7590
91
+ public block(id: number) {
92
+ return super.action(id, "block");
93
+ }
94
+
95
+ public unblock(id: number) {
96
+ return super.action(id, "unblock");
97
+ }
98
+
99
+ public send(id: number) {
100
+ return super.action(id, "send");
101
+ }
102
+
76103 public cancel(id: number) {
77104 return super.action(id, "cancel");
78105 }
79106
80
- public putonhold(id: number) {
81
- return super.action(id, "putonhold");
107
+ public download(id: number) {
108
+ let url = `${this.resource}/${id}/download`;
109
+ return this.http.get(url).map((response : Response) => {
110
+ let filename = JSON.parse(response.headers.get('Content-Disposition').match(/".*"$/g)[0]);
111
+ let content = JSON.stringify(response.json(), null, 2);
112
+ saveAsFile( new Blob([ content ], { type : 'application/octet-stream' }), filename);
113
+ return Observable.of(true);
114
+ }).catch(err => super.processErrorResponse(err));
82115 }
83116
84117 public isActionAvailable(action:string, lic:any) {
85118 var validStatuses = LIC_ACTIONS_BY_STATUS[action];
86119 return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1;
87120 }
88
-
89121
90122 getStatusName(statusCode: string): string {
91123 return this.$L.get(`pack.status.${statusCode}`, this.$L.get('Unknown'));