caf00c63c56e716f3ffe1b9670582a68caa9a8d4
[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
46     // console.log(this.IncomingReportId);
47
48     this._runService.getReportData(this.reportId1)
49     .subscribe((response) => {
50       console.log(response);
51
52       let i=0;
53       while(response["reportDataColumns"][i])
54       {
55         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
56         i++;
57       }
58
59       let j=0;
60       while(response["reportDataRows"][j])
61       {
62         let k=0;
63         let obj = new Object();
64         while(this.displayedColumnsArr[k])
65         {
66           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
67           {
68             //console.log(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
69             obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
70             //this.displayedRowObj.push(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
71           }
72           k++;
73         }
74         this.displayedRowObj.push(obj);
75         //console.log(response["reportDataRows"][j]);
76         j++;
77       }
78
79       console.log(this.displayedColumnsArr);
80       console.log(this.displayedRowObj);
81
82       for(let l=0; l<this.displayedColumnsArr.length; l++)
83       {
84         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
85       }
86       
87
88       this.dataSource.data = this.displayedRowObj;
89       this.dataSource.sort = this.sort;
90       this.dataSource.paginator = this.paginator;
91       this.table.dataSource = this.dataSource;
92   
93     });
94
95     // this.dataSource.data = [{id: 1, name: 'Hydrogen'}];
96
97   }
98
99   ngAfterViewInit() {
100     this._runService.getReportData(this.reportId1)
101     .subscribe((response) => {
102       console.log(response);
103
104       let i=0;
105       while(response["reportDataColumns"][i])
106       {
107         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
108         i++;
109       }
110
111       let j=0;
112       while(response["reportDataRows"][j])
113       {
114         let k=0;
115         let obj = new Object();
116         while(this.displayedColumnsArr[k])
117         {
118           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
119           {
120             //console.log(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
121             obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
122             //this.displayedRowObj.push(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
123           }
124           k++;
125         }
126         this.displayedRowObj.push(obj);
127         //console.log(response["reportDataRows"][j]);
128         j++;
129       }
130
131       console.log(this.displayedColumnsArr);
132       console.log(this.displayedRowObj);
133
134       for(let l=0; l<this.displayedColumnsArr.length; l++)
135       {
136         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
137       }
138       
139       this.dataSource.data = this.displayedRowObj;
140       this.dataSource.sort = this.sort;
141       this.dataSource.paginator = this.paginator;
142       this.table.dataSource = this.dataSource;
143   
144     });
145
146
147   }
148
149   
150 }