1895cc35ddd173055a43bd396b2feef1ec3edef5
[portal/sdk.git] /
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';
10
11 @Component({
12   selector: 'app-run-report',
13   templateUrl: './run-report.component.html',
14   styleUrls: ['./run-report.component.css']
15 })
16 export class RunReportComponent implements  OnInit {
17   @Input("reportId") reportId1 : string;
18   @Input("reportMode") reportMode : string;
19   @Input("queryString") queryString : string;
20
21   
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;
26
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;
34   formFieldList : {}[];
35   isReady : boolean;
36   responseFormFieldListLength : number;
37   NEWdisplayedColumns : string[];
38   initCnt : number;
39
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;
47       this.isReady = false;
48       this.NEWdisplayedColumns = new Array();
49       this.initCnt = 0;
50   }
51
52
53
54   ngOnChanges(changes: SimpleChanges)
55   {
56
57     if(this.reportMode !== "Regular" && this.initCnt > 0)
58     {
59     console.log(changes);
60     this.queryString = changes["queryString"]["currentValue"];
61     this.initCnt = 1;
62
63  
64     this.dataSource = new RunReportDataSource();
65
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;
72       this.isReady = false;
73       this.NEWdisplayedColumns = new Array();
74
75     
76     this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
77     .subscribe((response) => {
78       console.log(response);
79       this.responseFormFieldListLength = 0;
80       this.formFieldPresent = false;
81
82       // this.formFieldPresent = true;
83       
84       let i=0;
85       while(response["reportDataColumns"][i])
86       {
87         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
88         i++;
89       }
90
91       let j=0;
92       while(response["reportDataRows"][j])
93       {
94         let k=0;
95         let obj = new Object();
96         while(this.displayedColumnsArr[k])
97         {
98           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
99           {
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]]);
103           }
104           k++;
105         }
106         this.displayedRowObj.push(obj);
107         //console.log(response["reportDataRows"][j]);
108         j++;
109       }
110
111       console.log(this.displayedColumnsArr);
112       console.log(this.displayedRowObj);
113
114       for(let l=0; l<this.displayedColumnsArr.length; l++)
115       {
116         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
117       }
118
119       
120       this.showSpinner = false;
121       
122       this.dataSource.data = this.displayedRowObj;
123       this.dataSource.sort = this.sort;
124       this.dataSource.paginator = this.paginator;
125       this.table.dataSource = this.dataSource;
126       
127     });
128     }
129     
130   }
131
132   ngOnInit() {
133     
134     
135     if(this.reportMode == "Regular" && this.initCnt == 0)
136     {
137       this.dataSource = new RunReportDataSource();
138
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]);
153
154       let i=0;
155       while(response["reportDataColumns"][i])
156       {
157         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
158         i++;
159       }
160
161       let j=0;
162       while(response["reportDataRows"][j])
163       {
164         let k=0;
165         let obj = new Object();
166         while(this.displayedColumnsArr[k])
167         {
168           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
169           {
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]]);
173           }
174           k++;
175         }
176         this.displayedRowObj.push(obj);
177         //console.log(response["reportDataRows"][j]);
178         j++;
179       }
180
181       console.log(this.displayedColumnsArr);
182       console.log(this.displayedRowObj);
183
184       for(let l=0; l<this.displayedColumnsArr.length; l++)
185       {
186         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
187       }
188
189       this.showSpinner = false;
190       
191       this.dataSource.data = this.displayedRowObj;
192       
193       this.dataSource.sort = this.sort;
194       this.dataSource.paginator = this.paginator;
195       
196       this.table.dataSource = this.dataSource;
197      
198     });
199   }
200   else
201   {
202
203     this.dataSource = new RunReportDataSource();
204
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();
213
214     
215     this._runService.getReportDataWithFormFields(this.queryString, this.reportId1)
216     .subscribe((response) => {
217       console.log(response);
218       this.responseFormFieldListLength = 0;
219       this.formFieldPresent = false;
220
221       // this.formFieldPresent = true;
222       
223       let i=0;
224       while(response["reportDataColumns"][i])
225       {
226         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
227         i++;
228       }
229
230       let j=0;
231       while(response["reportDataRows"][j])
232       {
233         let k=0;
234         let obj = new Object();
235         while(this.displayedColumnsArr[k])
236         {
237           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
238           {
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]]);
242           }
243           k++;
244         }
245         this.displayedRowObj.push(obj);
246         //console.log(response["reportDataRows"][j]);
247         j++;
248       }
249
250       console.log(this.displayedColumnsArr);
251       console.log(this.displayedRowObj);
252
253       for(let l=0; l<this.displayedColumnsArr.length; l++)
254       {
255         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
256       }
257
258       
259       this.showSpinner = false;
260       
261       this.dataSource.data = this.displayedRowObj;
262       this.dataSource.sort = this.sort;
263       this.dataSource.paginator = this.paginator;
264       this.table.dataSource = this.dataSource;
265       
266     });
267   }
268   this.initCnt = 1;
269   }
270
271 }