1 import { AfterViewInit, Component, OnInit, ViewChild, Input, SimpleChange, SimpleChanges } from '@angular/core';
2 import { MatPaginator } from '@angular/material/paginator';
3 import { MatSort } from '@angular/material/sort';
4 import { MatTable } 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';
12 selector: 'app-run-report',
13 templateUrl: './run-report.component.html',
14 styleUrls: ['./run-report.component.css']
16 export class RunReportComponent implements OnInit {
17 @Input("reportId") reportId1 : string;
18 @Input("reportMode") reportMode : string;
19 @Input("queryString") queryString : string;
22 @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
23 @ViewChild(MatSort, {static: false} as any) sort: MatSort;
24 @ViewChild(MatTable, {static: false} as any) table: MatTable<RunReportFinalTableItem>;
25 dataSource: RunReportDataSource;
27 /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
28 displayedColumns : string[];
29 IncomingReportId : string;
30 displayedColumnsArr : string[];
31 displayedRowObj : RunReportFinalTableItem[];
32 formFieldPresent : boolean;
33 showSpinner : boolean;
36 responseFormFieldListLength : number;
37 NEWdisplayedColumns : string[];
40 constructor(private _http : HttpClient, private _route : ActivatedRoute, private _runService : RunService, private _router : Router){
41 this.displayedColumnsArr = new Array();
42 this.displayedRowObj = new Array();
43 this.displayedColumns = new Array();
44 this.formFieldList = new Array();
45 // this.formFieldPresent = false;
46 this.showSpinner = true;
48 this.NEWdisplayedColumns = new Array();
54 ngOnChanges(changes: SimpleChanges)
57 if(this.reportMode !== "Regular" && this.initCnt > 0)
60 this.queryString = changes["queryString"]["currentValue"];
64 this.dataSource = new RunReportDataSource();
66 this.displayedColumnsArr = new Array();
67 this.displayedRowObj = new Array();
68 this.displayedColumns = new Array();
69 this.formFieldList = new Array();
70 // this.formFieldPresent = false;
71 this.showSpinner = true;
73 this.NEWdisplayedColumns = new Array();
76 this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
77 .subscribe((response) => {
78 console.log(response);
79 this.responseFormFieldListLength = 0;
80 this.formFieldPresent = false;
82 // this.formFieldPresent = true;
85 while(response["reportDataColumns"][i])
87 this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
92 while(response["reportDataRows"][j])
95 let obj = new Object();
96 while(this.displayedColumnsArr[k])
98 if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
100 //console.log(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
101 obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
102 //this.displayedRowObj.push(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
106 this.displayedRowObj.push(obj);
107 //console.log(response["reportDataRows"][j]);
111 console.log(this.displayedColumnsArr);
112 console.log(this.displayedRowObj);
114 for(let l=0; l<this.displayedColumnsArr.length; l++)
116 this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
120 this.showSpinner = false;
122 this.dataSource.data = this.displayedRowObj;
123 this.dataSource.sort = this.sort;
124 this.dataSource.paginator = this.paginator;
125 this.table.dataSource = this.dataSource;
135 if(this.reportMode == "Regular" && this.initCnt == 0)
137 this.dataSource = new RunReportDataSource();
139 this.displayedColumnsArr = new Array();
140 this.displayedRowObj = new Array();
141 this.displayedColumns = new Array();
142 this.formFieldList = new Array();
143 // this.formFieldPresent = false;
144 this.showSpinner = true;
145 this.isReady = false;
146 this.NEWdisplayedColumns = new Array();
147 this._runService.getReportData(this.reportId1)
148 .subscribe((response) => {
149 this.formFieldPresent = false;
150 this.responseFormFieldListLength = 0;
151 console.log(this.reportId1, this.reportMode);
152 // this._router.navigate(['v2/run', this.reportId1]);
155 while(response["reportDataColumns"][i])
157 this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
162 while(response["reportDataRows"][j])
165 let obj = new Object();
166 while(this.displayedColumnsArr[k])
168 if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
170 //console.log(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
171 obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
172 //this.displayedRowObj.push(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
176 this.displayedRowObj.push(obj);
177 //console.log(response["reportDataRows"][j]);
181 console.log(this.displayedColumnsArr);
182 console.log(this.displayedRowObj);
184 for(let l=0; l<this.displayedColumnsArr.length; l++)
186 this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
189 this.showSpinner = false;
191 this.dataSource.data = this.displayedRowObj;
193 this.dataSource.sort = this.sort;
194 this.dataSource.paginator = this.paginator;
196 this.table.dataSource = this.dataSource;
203 this.dataSource = new RunReportDataSource();
205 this.displayedColumnsArr = new Array();
206 this.displayedRowObj = new Array();
207 this.displayedColumns = new Array();
208 this.formFieldList = new Array();
209 // this.formFieldPresent = false;
210 this.showSpinner = true;
211 this.isReady = false;
212 this.NEWdisplayedColumns = new Array();
215 this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
216 .subscribe((response) => {
217 console.log(response);
218 this.responseFormFieldListLength = 0;
219 this.formFieldPresent = false;
221 // this.formFieldPresent = true;
224 while(response["reportDataColumns"][i])
226 this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
231 while(response["reportDataRows"][j])
234 let obj = new Object();
235 while(this.displayedColumnsArr[k])
237 if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
239 //console.log(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
240 obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
241 //this.displayedRowObj.push(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
245 this.displayedRowObj.push(obj);
246 //console.log(response["reportDataRows"][j]);
250 console.log(this.displayedColumnsArr);
251 console.log(this.displayedRowObj);
253 for(let l=0; l<this.displayedColumnsArr.length; l++)
255 this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
259 this.showSpinner = false;
261 this.dataSource.data = this.displayedRowObj;
262 this.dataSource.sort = this.sort;
263 this.dataSource.paginator = this.paginator;
264 this.table.dataSource = this.dataSource;