| .. | .. |
|---|
| 1 | 1 | import { LocaleService } from '../common/i18n'; |
|---|
| 2 | 2 | import { Observable } from 'rxjs/Rx'; |
|---|
| 3 | 3 | import { Injectable } from '@angular/core'; |
|---|
| 4 | | -import { Http, RequestOptions } from '@angular/http'; |
|---|
| 4 | +import { Http, RequestOptions, ResponseContentType, Response } from '@angular/http'; |
|---|
| 5 | 5 | 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"; |
|---|
| 24 | 7 | |
|---|
| 25 | 8 | export const LIC_STATUS = { |
|---|
| 26 | 9 | CREATED: 'CR', |
|---|
| .. | .. |
|---|
| 41 | 24 | 'CA': '#a21717' |
|---|
| 42 | 25 | }; |
|---|
| 43 | 26 | |
|---|
| 27 | + |
|---|
| 44 | 28 | /** |
|---|
| 45 | 29 | * These transitions could be get from server, class License.Status, but |
|---|
| 46 | 30 | * we copy them for simplicity, this info won't change easily |
|---|
| .. | .. |
|---|
| 56 | 40 | cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE], |
|---|
| 57 | 41 | 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED, LIC_STATUS.BLOCKED] |
|---|
| 58 | 42 | } |
|---|
| 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 | + |
|---|
| 59 | 74 | |
|---|
| 60 | 75 | @Injectable() |
|---|
| 61 | 76 | export class LicensesService extends SeCurisResourceServices { |
|---|
| .. | .. |
|---|
| 73 | 88 | return super.action(id, "activate"); |
|---|
| 74 | 89 | } |
|---|
| 75 | 90 | |
|---|
| 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 | + |
|---|
| 76 | 103 | public cancel(id: number) { |
|---|
| 77 | 104 | return super.action(id, "cancel"); |
|---|
| 78 | 105 | } |
|---|
| 79 | 106 | |
|---|
| 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)); |
|---|
| 82 | 115 | } |
|---|
| 83 | 116 | |
|---|
| 84 | 117 | public isActionAvailable(action:string, lic:any) { |
|---|
| 85 | 118 | var validStatuses = LIC_ACTIONS_BY_STATUS[action]; |
|---|
| 86 | 119 | return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1; |
|---|
| 87 | 120 | } |
|---|
| 88 | | - |
|---|
| 89 | 121 | |
|---|
| 90 | 122 | getStatusName(statusCode: string): string { |
|---|
| 91 | 123 | return this.$L.get(`pack.status.${statusCode}`, this.$L.get('Unknown')); |
|---|