summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/instantiationStatus/instantiationStatus.component.service.ts
blob: 293397cc971a98d5bd4dc467d12320a3902a4add (plain)
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
import {Injectable} from '@angular/core';
import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model';
import {isNullOrUndefined} from "util";
import { Observable } from 'rxjs/Observable';
import 'rxjs/observable/of';

export let PENDING : string = "pending";
export let INPROGRESS : string = "inprogress";
export let PAUSE : string = "pause";
export let X_O : string = "X_o";
export let SUCCESS_CIRCLE : string = "success+Circle";
export let STOPED : string = "stoped";


@Injectable()
export class InstantiationStatusComponentService {
  generateServiceInfoDataMapping(arr: Array<ServiceInfoModel>) : { [serviceInstanceId: string]: Array<ServiceInfoModel>}{
    let serviceInfoData: { [serviceInstanceId: string]: Array<ServiceInfoModel>; } = {};
    for(let item of arr){
      if(isNullOrUndefined(serviceInfoData[item.templateId])){
        serviceInfoData[item.templateId] = [item];
      }else {
        serviceInfoData[item.templateId].push(item);
      }
    }
    return serviceInfoData;
  }

  convertObjectToArray(arr: Array<ServiceInfoModel>) : Observable<Array<ServiceInfoUiModel>>{
    const obj = this.generateServiceInfoDataMapping(arr);
    let index:number = 0;
    let result = [];
    for(let item in obj) {
      obj[item].map(item => {
        item['serviceStatus'] = this.getStatus(item.jobStatus);
        item['serviceIndex'] = index;
      });
      index++;
      result = result.concat(obj[item]);
    }

    console.log(result);
    return Observable.of(result);
  }

  getStatus(status : string) : ServiceStatus {
    switch(status.toUpperCase()) {
      case  'PENDING' :
        return new ServiceStatus(PENDING, '#009FDB', 'Pending: The service will automatically be sent for instantiation as soon as possible.');
      case  'IN_PROGRESS' :
        return new ServiceStatus(INPROGRESS, '#009FDB', 'In-progress: the service is in process of instantiation.');
      case  'PAUSED' :
        return new ServiceStatus(PAUSE, '#009FDB', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
      case  'FAILED' :
        return new ServiceStatus(X_O, '#D02B2B', 'Failed: Service instantiation has failed, load the service to see the error returned.');
      case  'COMPLETED' :
        return new ServiceStatus(SUCCESS_CIRCLE, '#53AD15', 'Completed successfully: Service is successfully instantiated.');
      case  'STOPPED' :
        return new ServiceStatus(STOPED, '#D02B2B', 'Stopped: Due to previous failure, will not be instantiated.');
    }
  }
}


export class ServiceStatus {
  iconClassName : string;
  color : string;
  tooltip : string;

  constructor(_iconClassName : string, _color : string, _tooltip : string){
    this.iconClassName = _iconClassName;
    this.color = _color;
    this.tooltip = _tooltip;
  }
}