aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/genericFormPopup/instantiationTemplatesModal/instantiation.templates.row.model.ts
blob: f2eda9df36e4d7f00d85093cd6c146c937b95aa6 (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
import * as moment from 'moment';
import * as _ from 'lodash';
import {InstantiationBase} from "../../../models/InstantiationBase";

export class InstantiationTemplatesRowModel extends InstantiationBase{
  readonly userId ?: string;
  readonly createDate ?: string;
  readonly instanceName ?: string;
  readonly instantiationStatus?: string;
  readonly summary?: string;
  readonly region?: string;
  readonly tenant?: string;
  readonly aicZone?: string;

  constructor(data) {
    super(data);
    this.userId = !_.isNil(data.userId) ? data.userId : null;
    this.createDate = !_.isNil(data.created) ? moment(data.created).format("YYYY-MM-DD HH:mm:ss") : null;
    this.instanceName = this.getInstanceName(data.serviceInstanceName);
    this.instantiationStatus = !_.isNil(data.jobStatus) ? data.jobStatus : null;
    this.summary = this.convertRequestSummaryFromMapToString(data.requestSummary);
    this.region = this.getRegion(data.regionId, data.owningEntityName);
    this.tenant = !_.isNil(data.tenantName) ? data.tenantName : null;
    this.aicZone = !_.isNil(data.aicZoneName) ? data.aicZoneName : null;
  }


  /**************************************************************************************************
   return the LCP region and in brackets the cloud owner removing the “att-“ with capital letters.
   **************************************************************************************************/
  getCloudOwner = (owningEntityName: string): string => {
    const splitByAtt: string[] = owningEntityName.split('att-');
    let owning: string = splitByAtt[splitByAtt.length - 1];
    return owning.toUpperCase();
  };

  getRegion = (regionId: string, owningEntityName: string): string => {
    const convertOwning = !_.isNil(owningEntityName) ? `(${this.getCloudOwner(owningEntityName)})` : '';
    return `${regionId} ${convertOwning}`.trim();
  };


  getInstanceName = (instanceName?: string): string => {
    if (_.isNil(instanceName)) {
      return '<Automatically generated>';
    }
    return instanceName;
  };

  convertRequestSummaryFromMapToString = (requestSummary: Map<string, number>): string => {
    let values: string[] = _.map(requestSummary, (count: number, instanceType: string) => instanceType + ": " + count);
    return _.join(values, ", ");
  }

}