27593cabf34d5bdab6a5d74f96990fafb0c5cb55
[vid.git] / vid-webpack-master / src / app / shared / components / auditInfoModal / auditInfoModal.component.ts
1 import {Component, ViewChild} from '@angular/core';
2 import {Subject} from 'rxjs/Subject';
3 import {ModalDirective} from 'ngx-bootstrap'
4 import {ModelInformationItem} from '../model-information/model-information.component';
5 import {ServiceModel} from '../../models/serviceModel';
6 import {ServiceInfoService} from '../../server/serviceInfo/serviceInfo.service';
7 import {ServiceInfoModel} from '../../server/serviceInfo/serviceInfo.model';
8 import {AuditStatus} from '../../server/serviceInfo/AuditStatus.model';
9 import {IframeService} from "../../utils/iframe.service";
10 import {NgRedux} from "@angular-redux/store";
11 import {AppState} from "../../store/reducers";
12 import {AuditInfoModalComponentService} from "./auditInfoModal.component.service";
13 import {FeatureFlagsService, Features} from "../../services/featureFlag/feature-flags.service";
14 import * as XLSX from 'xlsx';
15 import {DatePipe} from "@angular/common";
16 import {SpaceToUnderscorePipe} from "../../pipes/spaceToUnderscore/space-to-underscore.pipe";
17 import {ResizeEvent} from "angular-resizable-element";
18
19 @Component({
20   selector: 'audit-info-modal',
21   templateUrl: './auditInfoModal.component.html',
22   styleUrls: ['./auditInfoModal.component.scss']
23 })
24 export class AuditInfoModalComponent {
25   static openModal: Subject<ServiceInfoModel> = new Subject<ServiceInfoModel>();
26   static openInstanceAuditInfoModal: Subject<{instanceId , type, model, instance}> = new Subject<{instanceId , type, model, instance}>();
27   @ViewChild('auditInfoModal', {static: false}) public auditInfoModal: ModalDirective;
28   title: string = 'Service Information';
29   modelInfoItems: ModelInformationItem[] = [];
30   serviceModel: ServiceModel;
31   serviceModelName: string;
32   serviceModelId: string;
33   jobId: string;
34   vidInfoData: AuditStatus[] = [];
35   msoInfoData : any= [];
36   isAlaCarte: boolean;
37   parentElementClassName = 'content';
38   isLoading = true;
39   model: any;
40   instanceId: string;
41   isALaCarteFlagOn: boolean;
42   showMoreAuditInfoLink: boolean;
43   type : string = "Service";
44   showVidStatus : boolean = true;
45   auditInfoModalComponentService : AuditInfoModalComponentService;
46   serviceInstanceName : string;
47   serviceModelVersion : any;
48   serviceInstanceId : any;
49   exportMSOStatusFeatureEnabled: boolean;
50   dataIsReady : boolean = false;
51   jobDataLocal : any;
52   isDrawingBoard :boolean = false;
53   serviceInstanceObject :any;
54   typeFromDrawingBoard: any;
55   constructor(private _serviceInfoService: ServiceInfoService, private _iframeService : IframeService,
56               private _auditInfoModalComponentService : AuditInfoModalComponentService,
57               private _featureFlagsService: FeatureFlagsService,
58               private datePipe: DatePipe,
59               private spacetoUnderscore: SpaceToUnderscorePipe,
60               private store: NgRedux<AppState>) {
61     this.auditInfoModalComponentService = this._auditInfoModalComponentService;
62     this.exportMSOStatusFeatureEnabled = _featureFlagsService.getFlagState(Features.FLAG_2011_EXPORT_MSO_STATUS);
63     AuditInfoModalComponent.openModal.subscribe((jobData: ServiceInfoModel) => {
64       this.isALaCarteFlagOn = this.store.getState().global.flags['FLAG_A_LA_CARTE_AUDIT_INFO'];
65       this.showMoreAuditInfoLink = _featureFlagsService.getFlagState(Features.FLAG_MORE_AUDIT_INFO_LINK_ON_AUDIT_INFO);
66       
67       this.initializeProperties();
68       this.showVidStatus = true;
69       if (jobData) {
70         this.jobDataLocal = jobData;
71         this.isAlaCarte = jobData.aLaCarte;
72         this.openAuditInfoModal(jobData);
73         _iframeService.addClassOpenModal(this.parentElementClassName);
74         this.serviceModelName = jobData.serviceModelName ? jobData.serviceModelName : '';
75         this.serviceModelId = jobData.serviceModelId;
76         this.serviceInstanceId = jobData.serviceInstanceId;
77         this.jobId = jobData.jobId;
78         this.auditInfoModal.show();
79         this.serviceInstanceName = jobData.serviceInstanceName;
80         this.serviceModelVersion = jobData.serviceModelVersion;
81       } else {
82         _iframeService.removeClassCloseModal(this.parentElementClassName);
83         this.auditInfoModal.hide();
84       }
85     });
86
87     AuditInfoModalComponent.openInstanceAuditInfoModal.subscribe(({instanceId  , type ,  model, instance}) => {
88       this.showVidStatus = false;
89       this.showMoreAuditInfoLink = false;
90       this.isDrawingBoard = true;
91       this.initializeProperties();
92       this.setModalTitles(type);
93       this.serviceModelName = AuditInfoModalComponentService.getInstanceModelName(model);
94       this.serviceInstanceObject = instance;
95       this.typeFromDrawingBoard = type;
96
97       this.callApi(instance, type);
98       
99       if(this.msoInfoData && Array.isArray(this.msoInfoData)) {
100         this.sortMsoInfo();
101       }
102       
103       
104       this.modelInfoItems = this.auditInfoModalComponentService.getModelInfo(model, instance, instanceId);
105       _iframeService.addClassOpenModal(this.parentElementClassName);
106       this.auditInfoModal.show();
107     });
108   }
109
110   public style: object = {};
111   validate(event: ResizeEvent): boolean {
112     console.log("event : ", event);
113     if(event.rectangle.width && event.rectangle.height &&
114       ( event.rectangle.width < 600 || event.rectangle.width > 1412)
115     ){
116       return false;
117     } else{
118       return true;
119     }
120   }
121   onResizeEnd(event: ResizeEvent): void {
122     console.log('Element was resized', event);
123     this.style = {
124       position: 'relative',
125       left: `${event.rectangle.left}px`,
126       top: `${event.rectangle.top}px`,
127       width: `${event.rectangle.width}px`,
128       height: `${event.rectangle.height}px`
129     };
130     console.log("stle : ", this.style);
131   }
132
133
134   setModalTitles(type : string) : void{
135     this.type = AuditInfoModalComponentService.setModalTitlesType(type) ;
136     this.title = AuditInfoModalComponentService.setModalTitle(type);
137   }
138
139   initializeProperties() : void {
140     this.modelInfoItems = null;
141     this.vidInfoData = [];
142     this.msoInfoData = [];
143     this.isLoading = true;
144   }
145
146   openAuditInfoModal(jobData: ServiceInfoModel): void {
147     this.modelInfoItems = AuditInfoModalComponentService.createModelInformationItemsJob(jobData);
148     this.initAuditInfoData(jobData);
149     this.auditInfoModal.onHide.subscribe(()=>{
150       this._iframeService.removeClassCloseModal(this.parentElementClassName);
151       this.initializeProperties();
152     });
153     this.auditInfoModal.show();
154   }
155
156   initAuditInfoData(jobData: ServiceInfoModel) {
157     this._serviceInfoService.getJobAuditStatus(jobData)
158       .subscribe((res: AuditStatus[][]) => {
159         this.vidInfoData = res[0];
160         this.msoInfoData = res[1];
161         this.sortMsoInfo();
162         this.isLoading = false;
163       });
164   }
165
166   exportMsoStatusTable(){
167     let currentTime = new Date();
168     let timestamp = this.datePipe.transform(currentTime, "MMMddyyyy")+'_'
169       +currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds()
170     let fileName = this.spacetoUnderscore.transform(this.serviceInstanceName)+'_'+timestamp;
171     let msoStatusTableElement = document.getElementById('service-instantiation-audit-info-mso');
172     const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(msoStatusTableElement);
173     const wb: XLSX.WorkBook = XLSX.utils.book_new();
174     XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
175     /* save to file */
176     XLSX.writeFile(wb, fileName+'.csv');
177     this._iframeService.addClassOpenModal(this.parentElementClassName);
178   }
179
180   onCancelClick() {
181     this._iframeService.removeClassCloseModal(this.parentElementClassName);
182     this.initializeProperties();
183     this.auditInfoModal.hide();
184   }
185
186
187   onNavigate(){
188     window.open("http://ecompguide.web.att.com:8000/#ecomp_ug/c_ecomp_ops_vid.htmll#r_ecomp_ops_vid_bbglossary", "_blank");
189   }
190
191   refreshData(): void {
192     this.dataIsReady = false;
193     if(this.isDrawingBoard) {
194       this.callApi(this.serviceInstanceObject, this.typeFromDrawingBoard);
195     } else {
196       this.initAuditInfoData(this.jobDataLocal);
197     }
198     this.dataIsReady = true;
199
200   }
201   
202   //Comparer Function
203         getSortOrder(timestamp) {
204           return (obj1, obj2) =>{
205
206       let firstObj = obj1[timestamp];
207       let secondObj = obj2[timestamp];
208       return ((secondObj < firstObj) ? -1 : ((secondObj > firstObj) ? 1 : 0));
209
210           }
211   }
212
213   sortMsoInfo() {
214     this.msoInfoData.sort(this.getSortOrder("startTime"));
215     this.msoInfoData.forEach((element ) => {
216        element.instanceColumn = element.instanceName + " | " +"<br>" + element.instanceId;
217     });
218   }
219   
220   callApi(instance, type) {
221     if (instance.isFailed) {
222       this._serviceInfoService.getAuditStatusForRetry(instance.trackById).subscribe((res: AuditStatus) => {
223         this.msoInfoData = [res];
224       });
225     }else{
226       this._serviceInfoService.getInstanceAuditStatus(instance.instanceId, type).subscribe((res : AuditStatus[]) =>{
227         this.msoInfoData = res;
228      });
229     }
230   }
231
232   readOnlyRetryUrl = (): string =>
233     `../../serviceModels.htm?more#/servicePlanning/RETRY?serviceModelId=${this.serviceModelId}&jobId=${this.jobId}`
234 }