Merge "Load template button in new template modal"
[vid.git] / vid-webpack-master / src / app / shared / components / genericFormPopup / instantiationTemplatesModal / instantiation.templates.row.model.ts
1 import * as moment from 'moment';
2 import * as _ from 'lodash';
3 import {InstantiationBase} from "../../../models/serviceBase";
4
5 export class InstantiationTemplatesRowModel extends InstantiationBase{
6   readonly userId ?: string;
7   readonly createDate ?: string;
8   readonly instanceName ?: string;
9   readonly instantiationStatus?: string;
10   readonly summary?: string;
11   readonly region?: string;
12   readonly tenant?: string;
13   readonly aicZone?: string;
14
15   constructor(data) {
16     super(data);
17     this.userId = !_.isNil(data.created) ? data.userId : null;
18     this.createDate = !_.isNil(data.created) ? moment(data.created).format("YYYY-MM-DD HH:mm:ss") : null;
19     this.instanceName = this.getInstanceName(data.serviceInstanceName);
20     this.instantiationStatus = !_.isNil(data.jobStatus) ? data.jobStatus : null;
21     this.summary = null;
22     this.region = this.getRegion(data.regionId, data.owningEntityName);
23     this.tenant = !_.isNil(data.tenantName) ? data.tenantName : null;
24     this.aicZone = !_.isNil(data.aicZoneName) ? data.aicZoneName : null;
25   }
26
27
28   /**************************************************************************************************
29    return the LCP region and in brackets the cloud owner removing the “att-“ with capital letters.
30    **************************************************************************************************/
31   getCloudOwner = (owningEntityName: string): string => {
32     const splitByAtt: string[] = owningEntityName.split('att-');
33     let owning: string = splitByAtt[splitByAtt.length - 1];
34     return owning.toUpperCase();
35   };
36
37   getRegion = (regionId: string, owningEntityName: string): string => {
38     const convertOwning = !_.isNil(owningEntityName) ? `(${this.getCloudOwner(owningEntityName)})` : '';
39     return `${regionId} ${convertOwning}`.trim();
40   };
41
42
43   getInstanceName = (instanceName?: string): string => {
44     if (_.isNil(instanceName)) {
45       return '<Automatically generated>';
46     }
47     return instanceName;
48   }
49 }
50