41e99aee9cd4f786ef1d3dd038c4527e1a639a3a
[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   constructor(private _serviceInfoService: ServiceInfoService, private _iframeService : IframeService,
53               private _auditInfoModalComponentService : AuditInfoModalComponentService,
54               private _featureFlagsService: FeatureFlagsService,
55               private datePipe: DatePipe,
56               private spacetoUnderscore: SpaceToUnderscorePipe,
57               private store: NgRedux<AppState>) {
58     this.auditInfoModalComponentService = this._auditInfoModalComponentService;
59     AuditInfoModalComponent.openModal.subscribe((jobData: ServiceInfoModel) => {
60       this.isALaCarteFlagOn = this.store.getState().global.flags['FLAG_A_LA_CARTE_AUDIT_INFO'];
61       this.showMoreAuditInfoLink = _featureFlagsService.getFlagState(Features.FLAG_MORE_AUDIT_INFO_LINK_ON_AUDIT_INFO);
62       this.exportMSOStatusFeatureEnabled = _featureFlagsService.getFlagState(Features.FLAG_2011_EXPORT_MSO_STATUS);
63       this.initializeProperties();
64       this.showVidStatus = true;
65       if (jobData) {
66         this.jobDataLocal = jobData;
67         this.isAlaCarte = jobData.aLaCarte;
68         this.openAuditInfoModal(jobData);
69         _iframeService.addClassOpenModal(this.parentElementClassName);
70         this.serviceModelName = jobData.serviceModelName ? jobData.serviceModelName : '';
71         this.serviceModelId = jobData.serviceModelId;
72         this.serviceInstanceId = jobData.serviceInstanceId;
73         this.jobId = jobData.jobId;
74         this.auditInfoModal.show();
75         this.serviceInstanceName = jobData.serviceInstanceName;
76         this.serviceModelVersion = jobData.serviceModelVersion;
77       } else {
78         _iframeService.removeClassCloseModal(this.parentElementClassName);
79         this.auditInfoModal.hide();
80       }
81     });
82
83     AuditInfoModalComponent.openInstanceAuditInfoModal.subscribe(({instanceId  , type ,  model, instance}) => {
84       this.showVidStatus = false;
85       this.showMoreAuditInfoLink = false;
86       this.initializeProperties();
87       this.setModalTitles(type);
88       this.serviceModelName = AuditInfoModalComponentService.getInstanceModelName(model);
89
90       if (instance.isFailed) {
91         this._serviceInfoService.getAuditStatusForRetry(instance.trackById).subscribe((res: AuditStatus) => {
92           this.msoInfoData = [res];
93         });
94       }else{
95         this._serviceInfoService.getInstanceAuditStatus(instanceId, type).subscribe((res : AuditStatus[]) =>{
96           this.msoInfoData = res;
97        });
98       }
99       this.modelInfoItems = this.auditInfoModalComponentService.getModelInfo(model, instance, instanceId);
100       _iframeService.addClassOpenModal(this.parentElementClassName);
101       this.auditInfoModal.show();
102     });
103   }
104
105   public style: object = {};
106   validate(event: ResizeEvent): boolean {
107     console.log("event : ", event);
108     if(event.rectangle.width && event.rectangle.height &&
109       ( event.rectangle.width < 800 || event.rectangle.width > 1240)
110     ){
111       return false;
112     } else{
113       return true;
114     }
115   }
116   onResizeEnd(event: ResizeEvent): void {
117     console.log('Element was resized', event);
118     this.style = {
119       position: 'fixed',
120       left: `${event.rectangle.left}px`,
121       top: `${event.rectangle.top}px`,
122       width: `${event.rectangle.width}px`,
123       height: `${event.rectangle.height}px`
124     };
125     console.log("stle : ", this.style);
126   }
127
128
129   setModalTitles(type : string) : void{
130     this.type = AuditInfoModalComponentService.setModalTitlesType(type) ;
131     this.title = AuditInfoModalComponentService.setModalTitle(type);
132   }
133
134   initializeProperties() : void {
135     this.modelInfoItems = null;
136     this.vidInfoData = [];
137     this.msoInfoData = [];
138     this.isLoading = true;
139   }
140
141   openAuditInfoModal(jobData: ServiceInfoModel): void {
142     this.modelInfoItems = AuditInfoModalComponentService.createModelInformationItemsJob(jobData);
143     this.initAuditInfoData(jobData);
144     this.auditInfoModal.onHide.subscribe(()=>{
145       this._iframeService.removeClassCloseModal(this.parentElementClassName);
146       this.initializeProperties();
147     });
148     this.auditInfoModal.show();
149   }
150
151   initAuditInfoData(jobData: ServiceInfoModel) {
152     this._serviceInfoService.getJobAuditStatus(jobData)
153       .subscribe((res: AuditStatus[][]) => {
154         this.vidInfoData = res[0];
155         this.msoInfoData = res[1];
156         this.msoInfoData.sort(this.getSortOrder("startTime"));
157         this.msoInfoData.forEach((element ) => {
158            element.instanceColumn = element.instanceName + " | " +"<br>" + element.instanceId;
159         });
160         this.isLoading = false;
161       });
162   }
163
164   exportMsoStatusTable(){
165     let currentTime = new Date();
166     let timestamp = this.datePipe.transform(currentTime, "MMMddyyyy")+'_'
167       +currentTime.getHours()+":"+currentTime.getMinutes()+":"+currentTime.getSeconds()
168     let fileName = this.spacetoUnderscore.transform(this.serviceInstanceName)+'_'+timestamp;
169     let msoStatusTableElement = document.getElementById('service-instantiation-audit-info-mso');
170     const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(msoStatusTableElement, {
171           cellDates: true,
172       raw: true
173     });
174     const wb: XLSX.WorkBook = XLSX.utils.book_new();
175     XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
176     /* save to file */
177     XLSX.writeFile(wb, fileName+'.csv');
178     this._iframeService.addClassOpenModal(this.parentElementClassName);
179   }
180
181   onCancelClick() {
182     this._iframeService.removeClassCloseModal(this.parentElementClassName);
183     this.initializeProperties();
184     this.auditInfoModal.hide();
185   }
186
187
188   onNavigate(){
189     window.open("http://ecompguide.web.att.com:8000/#ecomp_ug/c_ecomp_ops_vid.htmll#r_ecomp_ops_vid_bbglossary", "_blank");
190   }
191
192   refreshData(): void {
193     this.dataIsReady = false;
194     this.initAuditInfoData(this.jobDataLocal);
195     this.dataIsReady = true;
196
197   }
198   
199   //Comparer Function
200         getSortOrder(timestamp) {
201           return (obj1, obj2) =>{
202
203                 let firstObj = obj1[timestamp];
204                 let secondObj = obj2[timestamp];
205                 return ((secondObj < firstObj) ? -1 : ((secondObj > firstObj) ? 1 : 0));
206
207           }
208         }
209
210   readOnlyRetryUrl = (): string =>
211     `../../serviceModels.htm?more#/servicePlanning/RETRY?serviceModelId=${this.serviceModelId}&jobId=${this.jobId}`
212 }
213