1 import {Injectable} from '@angular/core';
2 import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model';
3 import {isNullOrUndefined} from "util";
4 import { Observable } from 'rxjs/Observable';
5 import 'rxjs/observable/of';
7 export let PENDING : string = "pending";
8 export let INPROGRESS : string = "inprogress";
9 export let PAUSE : string = "pause";
10 export let X_O : string = "X_o";
11 export let SUCCESS_CIRCLE : string = "success+Circle";
12 export let STOPED : string = "stoped";
16 export class InstantiationStatusComponentService {
17 generateServiceInfoDataMapping(arr: Array<ServiceInfoModel>) : { [serviceInstanceId: string]: Array<ServiceInfoModel>}{
18 let serviceInfoData: { [serviceInstanceId: string]: Array<ServiceInfoModel>; } = {};
20 if(isNullOrUndefined(serviceInfoData[item.templateId])){
21 serviceInfoData[item.templateId] = [item];
23 serviceInfoData[item.templateId].push(item);
26 return serviceInfoData;
29 convertObjectToArray(arr: Array<ServiceInfoModel>) : Observable<Array<ServiceInfoUiModel>>{
30 const obj = this.generateServiceInfoDataMapping(arr);
33 for(let item in obj) {
34 obj[item].map(item => {
35 item['serviceStatus'] = this.getStatus(item.jobStatus);
36 item['serviceIndex'] = index;
39 result = result.concat(obj[item]);
43 return Observable.of(result);
46 getStatus(status : string) : ServiceStatus {
47 switch(status.toUpperCase()) {
49 return new ServiceStatus(PENDING, '#009FDB', 'Pending: The service will automatically be sent for instantiation as soon as possible.');
51 return new ServiceStatus(INPROGRESS, '#009FDB', 'In-progress: the service is in process of instantiation.');
53 return new ServiceStatus(PAUSE, '#009FDB', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
55 return new ServiceStatus(X_O, '#D02B2B', 'Failed: Service instantiation has failed, load the service to see the error returned.');
57 return new ServiceStatus(SUCCESS_CIRCLE, '#53AD15', 'Completed successfully: Service is successfully instantiated.');
59 return new ServiceStatus(STOPED, '#D02B2B', 'Stopped: Due to previous failure, will not be instantiated.');
65 export class ServiceStatus {
66 iconClassName : string;
70 constructor(_iconClassName : string, _color : string, _tooltip : string){
71 this.iconClassName = _iconClassName;
73 this.tooltip = _tooltip;