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