a8ac3642f6c2bd023ebcb46d598bdbc52c773528
[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 { RunReportDataSource, RunReportFinalTableItem } from './run-report-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',
13   templateUrl: './run-report.component.html',
14   styleUrls: ['./run-report.component.css']
15 })
16 export class RunReportComponent implements AfterViewInit, OnInit {
17   @Input("reportId") reportId1 : string;
18
19   
20   @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
21   @ViewChild(MatSort, {static: false} as any) sort: MatSort;
22   @ViewChild(MatTable, {static: false} as any) table: MatTable<RunReportFinalTableItem>;
23   dataSource: RunReportDataSource;
24
25   /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
26   displayedColumns : string[];
27   IncomingReportId : string;
28   displayedColumnsArr : string[];
29   displayedRowObj : RunReportFinalTableItem[];
30
31   constructor(private _http : HttpClient, private _route : ActivatedRoute, private _runService : RunService){
32       this.displayedColumnsArr = new Array();
33       this.displayedRowObj = new Array();
34       this.displayedColumns = new Array();
35   }
36
37   ngOnInit() {
38     this.dataSource = new RunReportDataSource();
39
40     this._route.params.subscribe(params => {
41       
42       this.IncomingReportId = params["reportId"];
43       this.reportId1 = params["reportId"];
44     });
45
46     
47
48     // console.log(this.IncomingReportId);
49
50     this._runService.getReportData(this.reportId1)
51     .subscribe((response) => {
52       console.log(response);
53
54       let i=0;
55       while(response["reportDataColumns"][i])
56       {
57         this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
58         i++;
59       }
60
61       let j=0;
62       while(response["reportDataRows"][j])
63       {
64         let k=0;
65         let obj = new Object();
66         while(this.displayedColumnsArr[k])
67         {
68           if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
69           {
70             //console.log(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
71             obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
72             //this.displayedRowObj.push(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]);
73           }
74           k++;
75         }
76         this.displayedRowObj.push(obj);
77         //console.log(response["reportDataRows"][j]);
78         j++;
79       }
80
81       console.log(this.displayedColumnsArr);
82       console.log(this.displayedRowObj);
83
84       for(let l=0; l<this.displayedColumnsArr.length; l++)
85       {
86         this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
87       }
88       
89       this.dataSource.data = this.displayedRowObj;
90       this.dataSource.sort = this.sort;
91       this.dataSource.paginator = this.paginator;
92       this.table.dataSource = this.dataSource;
93   
94     });
95
96     // this.dataSource.data = [{id: 1, name: 'Hydrogen'}];
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 }