blob: 293397cc971a98d5bd4dc467d12320a3902a4add [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {Injectable} from '@angular/core';
2import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model';
3import {isNullOrUndefined} from "util";
4import { Observable } from 'rxjs/Observable';
5import 'rxjs/observable/of';
6
7export let PENDING : string = "pending";
8export let INPROGRESS : string = "inprogress";
9export let PAUSE : string = "pause";
10export let X_O : string = "X_o";
11export let SUCCESS_CIRCLE : string = "success+Circle";
12export let STOPED : string = "stoped";
13
14
15@Injectable()
16export class InstantiationStatusComponentService {
17 generateServiceInfoDataMapping(arr: Array<ServiceInfoModel>) : { [serviceInstanceId: string]: Array<ServiceInfoModel>}{
18 let serviceInfoData: { [serviceInstanceId: string]: Array<ServiceInfoModel>; } = {};
19 for(let item of arr){
20 if(isNullOrUndefined(serviceInfoData[item.templateId])){
21 serviceInfoData[item.templateId] = [item];
22 }else {
23 serviceInfoData[item.templateId].push(item);
24 }
25 }
26 return serviceInfoData;
27 }
28
29 convertObjectToArray(arr: Array<ServiceInfoModel>) : Observable<Array<ServiceInfoUiModel>>{
30 const obj = this.generateServiceInfoDataMapping(arr);
31 let index:number = 0;
32 let result = [];
33 for(let item in obj) {
34 obj[item].map(item => {
35 item['serviceStatus'] = this.getStatus(item.jobStatus);
36 item['serviceIndex'] = index;
37 });
38 index++;
39 result = result.concat(obj[item]);
40 }
41
42 console.log(result);
43 return Observable.of(result);
44 }
45
46 getStatus(status : string) : ServiceStatus {
47 switch(status.toUpperCase()) {
48 case 'PENDING' :
49 return new ServiceStatus(PENDING, '#009FDB', 'Pending: The service will automatically be sent for instantiation as soon as possible.');
50 case 'IN_PROGRESS' :
51 return new ServiceStatus(INPROGRESS, '#009FDB', 'In-progress: the service is in process of instantiation.');
52 case 'PAUSED' :
53 return new ServiceStatus(PAUSE, '#009FDB', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
54 case 'FAILED' :
55 return new ServiceStatus(X_O, '#D02B2B', 'Failed: Service instantiation has failed, load the service to see the error returned.');
56 case 'COMPLETED' :
57 return new ServiceStatus(SUCCESS_CIRCLE, '#53AD15', 'Completed successfully: Service is successfully instantiated.');
58 case 'STOPPED' :
59 return new ServiceStatus(STOPED, '#D02B2B', 'Stopped: Due to previous failure, will not be instantiated.');
60 }
61 }
62}
63
64
65export class ServiceStatus {
66 iconClassName : string;
67 color : string;
68 tooltip : string;
69
70 constructor(_iconClassName : string, _color : string, _tooltip : string){
71 this.iconClassName = _iconClassName;
72 this.color = _color;
73 this.tooltip = _tooltip;
74 }
75}