a910d2ba63c2af71df7be573fb04d5e208591732
[portal/sdk.git] /
1 import { AfterViewInit, Component, OnInit, ViewChild, Input, SimpleChange } 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 { RunReportFinalTableDataSource, RunReportFinalTableItem } from './run-report-result-set-datasource';
6 import { ActivatedRoute } 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-result-set',
13   templateUrl: './run-report-result-set.component.html',
14   styleUrls: ['./run-report-result-set.component.css']
15 })
16 export class RunReportResultSetComponent implements AfterViewInit, OnInit {
17   
18   @Input("reportId") reportId1 : string;
19
20   
21   @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
22   @ViewChild(MatSort, {static: false} as any) sort: MatSort;
23   @ViewChild(MatTable, {static: false} as any) table: MatTable<RunReportFinalTableItem>;
24   dataSource: RunReportFinalTableDataSource;
25
26   /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
27   displayedColumns : string[];
28   IncomingReportId : string;
29   displayedColumnsArr : string[];
30   displayedRowObj : RunReportFinalTableItem[];
31
32   constructor(private _http : HttpClient, private _route : ActivatedRoute, private _runService : RunService){
33       this.displayedColumnsArr = new Array();
34       this.displayedRowObj = new Array();
35       this.displayedColumns = new Array();
36   }
37
38   ngOnInit() {
39     this.dataSource = new RunReportFinalTableDataSource();
40
41     this._route.params.subscribe(params => {
42       
43       this.IncomingReportId = params["reportId"];
44     });
45     this._runService.getReportData(this.reportId1)
46     .subscribe((response) => {
47       console.log(response);
48
49       let i=0;
50       while(response["reportDataColumns"][i])
51       {
52         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
53         i++;
54       }
55
56       let j=0;
57       while(response["reportDataRows"][j])
58       {
59         let k=0;
60         let obj = new Object();
61         while(this.displayedColumnsArr[k])
62         {
63           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
64           {
65             obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
66           }
67           k++;
68         }
69         this.displayedRowObj.push(obj);
70         j++;
71       }
72
73       console.log(this.displayedColumnsArr);
74       console.log(this.displayedRowObj);
75
76       for(let l=0; l<this.displayedColumnsArr.length; l++)
77       {
78         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
79       }
80       
81
82       this.dataSource.data = this.displayedRowObj;
83       this.dataSource.sort = this.sort;
84       this.dataSource.paginator = this.paginator;
85       this.table.dataSource = this.dataSource;
86   
87     });
88
89
90   }
91
92   ngAfterViewInit() {
93     this._runService.getReportData(this.reportId1)
94     .subscribe((response) => {
95       console.log(response);
96
97       let i=0;
98       while(response["reportDataColumns"][i])
99       {
100         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
101         i++;
102       }
103
104       let j=0;
105       while(response["reportDataRows"][j])
106       {
107         let k=0;
108         let obj = new Object();
109         while(this.displayedColumnsArr[k])
110         {
111           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
112           {
113             obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
114           }
115           k++;
116         }
117         this.displayedRowObj.push(obj);
118         j++;
119       }
120
121       console.log(this.displayedColumnsArr);
122       console.log(this.displayedRowObj);
123
124       for(let l=0; l<this.displayedColumnsArr.length; l++)
125       {
126         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
127       }
128       
129       this.dataSource.data = this.displayedRowObj;
130       this.dataSource.sort = this.sort;
131       this.dataSource.paginator = this.paginator;
132       this.table.dataSource = this.dataSource;
133   
134     });
135
136
137   }
138
139   
140 }