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

export class InstantiationTemplatesRowModel {
  readonly jobId: string;
  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) {
    this.jobId = data.jobId;
    this.userId = !_.isNil(data.created) ? 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 = null;
    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;
  }
}