rsanchez
2017-06-12 e1c16413381eb2211a69bdf4bbdfd1a87932035a
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 { Observable } from 'rxjs/Rx';
import { Injectable } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import { SeCurisResourceServices, MySearchParams } from './base';
import { LocaleService } from '../common/i18n';
var pack_example = { 
  id: 7,
  code: 'DX250000',
  status: 'AC',
  application_name: 'Doxr',
  created_by_id: 'admin',
  created_by_name: 'Administrator  (admin)',
  creation_timestamp: 1440597540000,
  end_valid_date: 2051222400000,
  init_valid_date: 1440547200000,
  license_preactivation: true,
  license_type_id: 5,
  licensetype_code: 'DXL3',
  metadata: 
   [ { key: 'max_docs',
       value: '250000',
       readonly: true,
       mandatory: true,
       pack_id: 7 } ],
  num_activations: 7,
  num_available: -2,
  num_creations: 7,
  num_licenses: 5,
  organization_id: 2,
  organization_name: 'CurisTec',
  preactivation_valid_period: 70,
  renew_valid_period: 0,
}
export type PacksFilter = {
    licenseTypeId?: number;
    organizationId?: number;
    applicationId?: number;
    name?: string;
}
export const PACK_STATUS = {
               CREATED: 'CR',
               ACTIVE: 'AC',
               ONHOLD: 'OH',
               EXPIRED: 'EX',
               CANCELLED: 'CA'
       }
export const COLORS_BY_STATUS = {
                   'CR': '#808080',
                   'AC': '#329e5a',
                   'OH': '#9047c7',
                   'EX': '#ea7824',
                   'CA': '#a21717'
           };
export const PACK_ACTIONS_BY_STATUS = {
               edit: [PACK_STATUS.CREATED, PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD, PACK_STATUS.ACTIVE],
               activate: [PACK_STATUS.CREATED, PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD],
               putonhold: [PACK_STATUS.ACTIVE],
               cancel: [PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD, PACK_STATUS.ACTIVE],
               'delete': [PACK_STATUS.CREATED, PACK_STATUS.CANCELLED]
       }
export const PACK_ACTIONS : any[] = [{
    command: 'activate',
    icon: 'play_circle_outline',
    name: 'Activate'
  },{
    command: 'putonhold',
    icon: 'pause_circle_outline',
    name: 'Put on hold'
  },{
    command: 'cancel',
    icon: 'cancel',
    name: 'Cancel'
  }]
@Injectable()
export class PacksService extends SeCurisResourceServices {
  constructor(http: Http, $L: LocaleService) {
    super($L, http, 'pack');
  }
  public get(filter?: PacksFilter | number | string) {
      if (!filter || typeof filter === "number" || typeof filter === "string") {
        return super.get(filter);
      }
      let searchParams = new MySearchParams(filter);
      let url = `${this.resource}/?${searchParams}`;
      return this.http.get(url).map(response => response.json()).catch(err => super.processErrorResponse(err));
   }
  public activate(id: number) {
           return super.action(id, "activate");
   }
  
  public cancel(id: number) {
           return super.action(id, "cancel");
   }
  public putonhold(id: number) {
           return super.action(id, "putonhold");
   }
  public nextLicCode(id: number) {
      let url = `pack/${id}/next_license_code`
      return this.http.get(url).map(response => response.text());
   }
  
     public isActionAvailable(action:string, pack:any) {
       var validStatuses = PACK_ACTIONS_BY_STATUS[action];
       return pack && validStatuses && validStatuses.indexOf(pack.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';
  }  
}