1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
| | import { LocaleService } from '../common/i18n';
| | import { Observable } from 'rxjs/Rx';
| | import { Injectable } from '@angular/core';
| | import { Http, RequestOptions, ResponseContentType, Response } from '@angular/http';
| | import { SeCurisResourceServices } from './base';
| | import * as saveAsFile from "file-saver";
| |
| | export const LIC_STATUS = {
| | CREATED: 'CR',
| | ACTIVE: 'AC',
| | REQUESTED: 'RE',
| | PREACTIVE: 'PA',
| | EXPIRED: 'EX',
| | BLOCKED: 'BL',
| | CANCELLED: 'CA'
| | }
| |
| | export const COLORS_BY_STATUS = {
| | 'CR': '#808080',
| | 'AC': '#329e5a',
| | 'RE': '#2981d4',
| | 'EX': '#ea7824',
| | 'BL': '#ff0000',
| | 'CA': '#a21717'
| | };
| |
| |
| | /**
| | * These transitions could be get from server, class License.Status, but
| | * we copy them for simplicity, this info won't change easily
| | */
| | export const LIC_ACTIONS_BY_STATUS = {
| | edit: [LIC_STATUS.REQUESTED, LIC_STATUS.CREATED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE, LIC_STATUS.CANCELLED, LIC_STATUS.BLOCKED],
| | add_request: [LIC_STATUS.CREATED],
| | activate: [LIC_STATUS.CREATED, LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE],
| | send: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
| | download: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
| | block: [LIC_STATUS.CANCELLED],
| | unblock: [LIC_STATUS.BLOCKED],
| | cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE],
| | 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED, LIC_STATUS.BLOCKED]
| | }
| |
| | export const LICENSE_ACTIONS : any[] = [{
| | /* command: 'add_request',
| | icon: 'add_to_photos',
| | name: 'Add request'
| | },{ */
| | command: 'activate',
| | icon: 'play_circle_outline',
| | name: 'Activate'
| | },{
| | command: 'send',
| | icon: 'send',
| | name: 'Send'
| | },{
| | command: 'download',
| | icon: 'file_download',
| | name: 'Download'
| | },{
| | command: 'block',
| | icon: 'do_not_disturb_on',
| | name: 'Block'
| | },{
| | command: 'unblock',
| | icon: 'do_not_disturb_off',
| | name: 'Unblock'
| | },{
| | command: 'cancel',
| | icon: 'cancel',
| | name: 'Cancel'
| | }]
| |
| |
| | @Injectable()
| | export class LicensesService extends SeCurisResourceServices {
| | constructor(http: Http,
| | $L: LocaleService) {
| | super($L, http, 'license');
| | }
| |
| | public getByPack(packId: number) {
| | let url = `${this.resource}?packId=${packId}`;
| | return this.http.get(url).map(response => response.json());
| | }
| |
| | public activate(id: number) {
| | return super.action(id, "activate");
| | }
| |
| | public block(id: number) {
| | return super.action(id, "block");
| | }
| |
| | public unblock(id: number) {
| | return super.action(id, "unblock");
| | }
| |
| | public send(id: number) {
| | return super.action(id, "send");
| | }
| |
| | public cancel(id: number) {
| | return super.action(id, "cancel");
| | }
| |
| | public download(id: number) {
| | let url = `${this.resource}/${id}/download`;
| | return this.http.get(url).map((response : Response) => {
| | let filename = JSON.parse(response.headers.get('Content-Disposition').match(/".*"$/g)[0]);
| | let content = JSON.stringify(response.json(), null, 2);
| | saveAsFile( new Blob([ content ], { type : 'application/octet-stream' }), filename);
| | return Observable.of(true);
| | }).catch(err => super.processErrorResponse(err));
| | }
| |
| | public isActionAvailable(action:string, lic:any) {
| | var validStatuses = LIC_ACTIONS_BY_STATUS[action];
| | return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1;
| | }
| |
| | getStatusName(statusCode: string): string {
| | return this.$L.get(`pack.status.${statusCode}`, this.$L.get('Unknown'));
| | }
| |
| | getStatusColor(statusCode: string): string {
| | return COLORS_BY_STATUS[statusCode] || '#cccccc';
| | }
| | }
|
|