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';
14 export interface PeriodicElement {
19 const ELEMENT_DATA: PeriodicElement[] = [{}];
22 selector: 'app-run-report',
23 templateUrl: './run-report.component.html',
24 styleUrls: ['./run-report.component.css']
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;
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;
47 responseFormFieldListLength : number;
48 NEWdisplayedColumns : string[];
51 showDashboardReport : boolean;
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;
62 initialQueryString : string;
64 runButtonHitCnt : number;
68 constructor(private _http : HttpClient,
69 private _route : ActivatedRoute,
70 private _runService : RunService,
71 private _router : Router,
72 private changeDetectorRefs: ChangeDetectorRef)
74 this.displayedColumnsArr = new Array();
75 this.displayedRowObj = new Array();
76 this.displayedColumns = new Array();
77 this.formFieldList = new Array();
78 this.showSpinner = true;
80 this.NEWdisplayedColumns = new Array();
83 this.showDashboardReport = false;
84 this.openOptionsFlag = false;
85 this.showMoreVert = false;
86 this.environment = environment;
88 this.runButtonHitCnt = 0;
90 this._router.routeReuseStrategy.shouldReuseRoute = function() {
96 ngOnChanges(changes: SimpleChanges)
98 if(this.reportMode !== "Regular" && this.initCnt > 0 && this.TriggerFFArr.length == 0)
100 this.showMoreVert = false;
101 if(changes["queryString"])
103 this.queryString = changes["queryString"]["currentValue"];
106 this.showDashboardReport = false;
108 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
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();
118 this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
119 .subscribe((response) => {
120 if(response["errormessage"])
122 this.showError(response);
126 if(this.reportMode !== "FormField")
128 this.postFetchingReportDataFn(response);
129 this.showMoreVert = true;
130 this.showDashboardReport = true;
134 this.postFetchingReportDataFn(response);
135 this.showMoreVert = true;
144 if(this.initialQueryString !== this.queryString && this.initCounter > 0 && this.hitCnt !== this.runButtonHitCnt)
146 this.runButtonHitCnt = this.hitCnt;
147 this.initialQueryString = this.queryString;
148 this.initialProcesses();
149 this.afterViewInitialProcesses();
153 this.runButtonHitCnt = this.hitCnt;
154 this.initialQueryString = this.queryString;
160 this.initialProcesses();
166 if(this.DashboardReportObj.length > 0)
168 this.dashboard = this.DashboardReportObj;
170 gridType: GridType.ScrollVertical,
174 outerMarginRight: 10,
175 outerMarginBottom: 5000,
177 scrollSensitivity: 10,
179 emptyCellDragMaxCols: null,
180 emptyCellDragMaxRows: null,
181 ignoreContentClass: 'gridster-item-content',
182 enableOccupiedCellDrop : true,
183 ignoreMarginInRow: false,
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,
205 this.showDashboardReport = true;
209 this.hitCnt = this.runButtonHitCnt;
210 this.initialQueryString = this.queryString;
215 this.afterViewInitialProcesses();
218 afterViewInitialProcesses()
221 if(this.DashboardReportObj.length === 0)
223 if(this.reportMode === "Regular" && this.initCnt == 0)
225 this.showMoreVert = false;
226 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
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"])
239 this.showError(response);
243 this.postFetchingReportDataFn(response);
244 this.showMoreVert = true;
251 this.showMoreVert = false;
252 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
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();
262 this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
263 .subscribe((response) => {
264 if(response["errormessage"])
266 this.showError(response);
270 this.postFetchingReportDataFn(response);
271 this.showMoreVert = true;
280 this.showSpinner = false;
286 showError(Errresponse : any)
288 this.errorMessage = Errresponse["errormessage"];
289 this.stackTrace = Errresponse["stacktrace"];
291 this.showSpinner = false;
294 postFetchingReportDataFn(response : any)
297 this.formFieldPresent = false;
298 this.responseFormFieldListLength = 0;
300 this.reportName = response["reportName"];
303 while(response["reportDataColumns"][i])
305 let columnTitle = response["reportDataColumns"][i]["columnTitle"];
306 let columnId = response["reportDataColumns"][i]["colId"];
307 this.displayedColumnsArr.push(columnTitle +","+ columnId);
312 while(response["reportDataRows"][j])
315 let obj = new Object();
316 let reportDataRows = response["reportDataRows"][j];
317 while(this.displayedColumnsArr[k])
319 let rowColumnId = this.displayedColumnsArr[k].split(",")[1];
320 if(reportDataRows[rowColumnId])
322 obj[reportDataRows[rowColumnId]["colId"]] = reportDataRows[rowColumnId]["displayValue"];
326 this.displayedRowObj.push(obj);
329 for(let l=0; l<this.displayedColumnsArr.length; l++)
331 let columnArrId = this.displayedColumnsArr[l].split(",")[1];
332 this.displayedColumns.push(columnArrId);
334 this.showSpinner = false;
336 this.dataSource = new MatTableDataSource<PeriodicElement>(this.displayedRowObj);
338 this.dataSource.sort = this.sort;
339 this.dataSource.paginator = this.paginator;
341 this.table.dataSource = this.dataSource;
343 this.changeDetectorRefs.detectChanges();
346 linkToReport(reportID : string, queryParameters : string)
348 this._router.navigate(['v2/run', reportID, queryParameters]);
352 linkToFeedback(feedBackId : string, queryParameters : string)
354 this._router.navigate(['v2/feedback', feedBackId]);
357 linkToMail(mailId : string)
359 var email = "mailto:" + mailId;
360 window.location.href = email;
366 this.openOptionsFlag = !this.openOptionsFlag;
369 downloadReportExcel()
371 this._runService.downloadReportExcel(this.reportId1)
372 .subscribe((responseExcel) => {
374 this.downLoadFile(responseExcel, "application/vnd.ms-excel")
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.');
387 applyFilter(filterValue: string) {
388 this.dataSource.filter = filterValue.trim().toLowerCase();