cc5203804c3265abc345a77192459787782e4528
[portal/sdk.git] /
1 import { AfterViewInit, Component, OnInit, ViewChild, Input, SimpleChange, SimpleChanges, ChangeDetectorRef, Inject } from '@angular/core';
2 import { MatPaginator } from '@angular/material/paginator';
3 import { MatSort } from '@angular/material/sort';
4 import { MatTable, MatTableDataSource } from '@angular/material/table';
5 import { RunReportDataSource, RunReportFinalTableItem } from './run-report-datasource';
6 import { ActivatedRoute, Router } from '@angular/router';
7 import { HttpClient } from '@angular/common/http';
8 import { environment } from '../../../../../../../environments/environment';
9 import { RunService } from '../run.service';
10 import { GridsterConfig, GridsterItem, GridType } from 'angular-gridster2';
11 import { Observable } from 'rxjs';
12
13
14 export interface PeriodicElement {
15
16 }
17
18
19 const ELEMENT_DATA: PeriodicElement[] = [{}];
20
21 @Component({
22   selector: 'app-run-report',
23   templateUrl: './run-report.component.html',
24   styleUrls: ['./run-report.component.css']
25 })
26 export class RunReportComponent implements  OnInit, AfterViewInit {
27   @Input("reportId") reportId1 : string;
28   @Input("reportMode") reportMode : string;
29   @Input("queryString") queryString : string;
30   @Input("DashboardReportObj") DashboardReportObj : Array<GridsterItem>;
31   @Input("TriggerFFArr") TriggerFFArr : string[];
32   @Input("hitCnt") hitCnt : number;
33
34   
35   @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
36   @ViewChild(MatSort, {static: false} as any) sort: MatSort;
37   @ViewChild(MatTable, {static: false} as any) table: MatTable<RunReportFinalTableItem>;
38   dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
39   displayedColumns : string[];
40   IncomingReportId : string;
41   displayedColumnsArr : string[];
42   displayedRowObj : RunReportFinalTableItem[];
43   formFieldPresent : boolean;
44   showSpinner : boolean;
45   formFieldList : {}[];
46   isReady : boolean;
47   responseFormFieldListLength : number;
48   NEWdisplayedColumns : string[];
49   initCnt : number;
50   reportName : string;
51   showDashboardReport : boolean;
52   checkCnt : number;
53
54   options: GridsterConfig;
55   dashboard :  Array<GridsterItem> = new Array();
56   openOptionsFlag : boolean;
57   showMoreVert : boolean;
58   errorMessage : string = "";
59   stackTrace : string = "";
60   error : boolean = false;
61   environment : any;
62   initialQueryString : string;
63   initCounter : number;
64   runButtonHitCnt : number;
65
66   
67
68   constructor(private _http : HttpClient, 
69               private _route : ActivatedRoute, 
70               private _runService : RunService, 
71               private _router : Router, 
72               private changeDetectorRefs: ChangeDetectorRef)
73     {
74       this.displayedColumnsArr = new Array();
75       this.displayedRowObj = new Array();
76       this.displayedColumns = new Array();
77       this.formFieldList = new Array();
78       this.showSpinner = true;
79       this.isReady = false;
80       this.NEWdisplayedColumns = new Array();
81       this.initCnt = 0;
82       this.checkCnt = 0;
83       this.showDashboardReport = false;
84       this.openOptionsFlag = false;
85       this.showMoreVert = false;
86       this.environment = environment;
87       this.initCounter = 0;
88       this.runButtonHitCnt = 0;
89
90       this._router.routeReuseStrategy.shouldReuseRoute = function() {
91         return false;
92     };
93   }
94
95
96   ngOnChanges(changes: SimpleChanges)
97   {
98     if(this.reportMode !== "Regular" && this.initCnt > 0 && this.TriggerFFArr.length == 0)
99     {
100       this.showMoreVert = false;
101       if(changes["queryString"])
102       {
103       this.queryString = changes["queryString"]["currentValue"];
104       }
105       this.initCnt = 1;
106       this.showDashboardReport = false;
107
108       this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
109
110       this.displayedColumnsArr = new Array();
111       this.displayedRowObj = new Array();
112       this.displayedColumns = new Array();
113       this.formFieldList = new Array();
114       this.showSpinner = true;
115       this.isReady = false;
116       this.NEWdisplayedColumns = new Array();
117
118       this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
119       .subscribe((response) => {
120         if(response["errormessage"])
121         {
122           this.showError(response);
123         }
124         else
125         {
126           if(this.reportMode !== "FormField")
127           {
128             this.postFetchingReportDataFn(response);
129             this.showMoreVert = true;
130             this.showDashboardReport = true;
131           }
132           else
133           {
134             this.postFetchingReportDataFn(response);
135             this.showMoreVert = true;
136           }
137         }
138     });
139     }
140     else
141     {
142     }
143
144     if(this.initialQueryString !== this.queryString && this.initCounter > 0 && this.hitCnt !== this.runButtonHitCnt)
145     {
146       this.runButtonHitCnt = this.hitCnt;
147       this.initialQueryString = this.queryString;
148       this.initialProcesses();
149       this.afterViewInitialProcesses();
150     }
151     else
152     {
153       this.runButtonHitCnt = this.hitCnt;
154       this.initialQueryString = this.queryString;
155     }
156     
157   }
158
159   ngOnInit(){
160     this.initialProcesses();
161     
162   }
163
164   initialProcesses()
165   {
166     if(this.DashboardReportObj.length > 0)
167     {
168       this.dashboard = this.DashboardReportObj;
169       this.options = {
170       gridType: GridType.ScrollVertical,
171       margin: 10,
172       outerMargin: true,
173       outerMarginTop: 10,
174       outerMarginRight: 10,
175       outerMarginBottom: 5000,
176       outerMarginLeft: 10,
177       scrollSensitivity: 10,
178       scrollSpeed: 20,
179       emptyCellDragMaxCols: null,
180       emptyCellDragMaxRows: null,
181       ignoreContentClass: 'gridster-item-content',
182       enableOccupiedCellDrop : true,
183       ignoreMarginInRow: false,
184       draggable: {
185         enabled: true,
186       },
187       resizable: {
188         enabled: true,
189       },
190       swap: true,
191       pushItems: true,
192       disablePushOnDrag: false,
193       disablePushOnResize: false,
194       pushDirections: {north: true, east: true, south: true, west: true},
195       pushResizeItems: true,
196       disableWindowResize: true,
197       disableWarnings: false,
198       scrollToNewItems: true,
199       enableDropToAdd : true,
200       enableEmptyCellDrop : true,
201       minCols : 2,
202       minRows : 2,
203       
204     };
205     this.showDashboardReport = true;
206     
207   }
208
209   this.hitCnt = this.runButtonHitCnt;
210   this.initialQueryString = this.queryString;
211   this.initCounter++;
212   }
213
214   ngAfterViewInit() {
215     this.afterViewInitialProcesses();
216   }
217
218 afterViewInitialProcesses()
219 {
220   
221   if(this.DashboardReportObj.length === 0)
222   {
223     if(this.reportMode === "Regular" && this.initCnt == 0)
224     {
225       this.showMoreVert = false;
226       this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
227
228       this.displayedColumnsArr = new Array();
229       this.displayedRowObj = new Array();
230       this.displayedColumns = new Array();
231       this.formFieldList = new Array();
232       this.showSpinner = true;
233       this.isReady = false;
234       this.NEWdisplayedColumns = new Array();
235       this._runService.getReportData(this.reportId1)
236       .subscribe((response) => {
237         if(response["errormessage"])
238         {
239           this.showError(response);
240         }
241         else
242         {
243           this.postFetchingReportDataFn(response);
244           this.showMoreVert = true;
245         }
246       });
247     }
248     else
249     {
250       
251       this.showMoreVert = false;
252       this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
253
254       this.displayedColumnsArr = new Array();
255       this.displayedRowObj = new Array();
256       this.displayedColumns = new Array();
257       this.formFieldList = new Array();
258       this.showSpinner = true;
259       this.isReady = false;
260       this.NEWdisplayedColumns = new Array();
261
262       this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
263       .subscribe((response) => {
264         if(response["errormessage"])
265         {
266           this.showError(response);
267         }
268         else
269         {
270           this.postFetchingReportDataFn(response);
271           this.showMoreVert = true;
272         }
273       });
274     }
275
276     
277 }
278 else
279 {
280 this.showSpinner = false;
281 }
282
283 this.initCnt = 1;
284 }
285
286 showError(Errresponse : any)
287 {
288   this.errorMessage = Errresponse["errormessage"];
289   this.stackTrace = Errresponse["stacktrace"];
290   this.error = true;
291   this.showSpinner = false;
292 }
293
294   postFetchingReportDataFn(response : any)
295   {
296     
297     this.formFieldPresent = false;
298     this.responseFormFieldListLength = 0;
299
300     this.reportName = response["reportName"];
301
302   let i=0;
303   while(response["reportDataColumns"][i])
304   {
305     let columnTitle = response["reportDataColumns"][i]["columnTitle"];
306     let columnId = response["reportDataColumns"][i]["colId"];
307     this.displayedColumnsArr.push(columnTitle +","+ columnId);
308     i++;
309   }
310
311   let j=0;
312   while(response["reportDataRows"][j])
313   {
314     let k=0;
315     let obj = new Object();
316     let reportDataRows = response["reportDataRows"][j];
317     while(this.displayedColumnsArr[k])
318     {
319       let rowColumnId = this.displayedColumnsArr[k].split(",")[1];
320       if(reportDataRows[rowColumnId])
321       {
322          obj[reportDataRows[rowColumnId]["colId"]] = reportDataRows[rowColumnId]["displayValue"];
323       }
324       k++;
325     }
326     this.displayedRowObj.push(obj);
327     j++;
328   }
329   for(let l=0; l<this.displayedColumnsArr.length; l++)
330   {
331     let columnArrId = this.displayedColumnsArr[l].split(",")[1];
332     this.displayedColumns.push(columnArrId);
333   }
334   this.showSpinner = false;
335   
336   this.dataSource = new MatTableDataSource<PeriodicElement>(this.displayedRowObj);
337   
338   this.dataSource.sort = this.sort;
339   this.dataSource.paginator = this.paginator;
340   
341   this.table.dataSource = this.dataSource;
342  
343   this.changeDetectorRefs.detectChanges();
344   }
345
346   linkToReport(reportID : string, queryParameters : string)
347   {
348     this._router.navigate(['v2/run', reportID, queryParameters]);
349   }
350   
351   
352   linkToFeedback(feedBackId : string, queryParameters : string)
353   {
354     this._router.navigate(['v2/feedback', feedBackId]);
355   }
356
357   linkToMail(mailId : string)
358   {
359     var email = "mailto:" + mailId;
360     window.location.href = email;
361   }
362
363
364   openOptions()
365   {
366     this.openOptionsFlag = !this.openOptionsFlag;
367   }
368
369   downloadReportExcel()
370   {
371     this._runService.downloadReportExcel(this.reportId1)
372     .subscribe((responseExcel) => {
373       
374       this.downLoadFile(responseExcel, "application/vnd.ms-excel")
375     });
376   }
377
378   downLoadFile(data: any, type: string) {
379     let blob = new Blob([data], { type: type});
380     let url = window.URL.createObjectURL(blob);
381     let pwa = window.open(url);
382     if (!pwa || pwa.closed || typeof pwa.closed == 'undefined') {
383         alert( 'Please disable your Pop-up blocker and try again.');
384     }
385 }
386
387 applyFilter(filterValue: string) {
388   this.dataSource.filter = filterValue.trim().toLowerCase();
389 }
390
391
392 }
393