35fe7414a3ff5543f64c5174dab9ce3c1b79e665
[portal/sdk.git] /
1 import { Component, OnInit, Input, AfterViewInit, ViewChild } from '@angular/core';
2 import { GridsterConfig, GridType, GridsterItem } from 'angular-gridster2';
3 import { MatTableDataSource } from '@angular/material/table';
4 import { MatPaginator } from '@angular/material/paginator';
5 import { DashboardReportService } from './dashboard-report.service';
6 import { MatSort } from '@angular/material';
7 import { Router } from '@angular/router';
8
9
10
11 export interface PeriodicElement {
12
13 }
14
15
16   
17 const ELEMENT_DATA: PeriodicElement[] = [{}];
18
19 @Component({
20   selector: 'app-run-dashboard-report',
21   templateUrl: './run-dashboard-report.component.html',
22   styleUrls: ['./run-dashboard-report.component.css']
23 })
24
25 export class RunDashboardReportComponent implements AfterViewInit {
26
27   
28
29   @Input("reportId") reportId1 : string;
30   @Input("queryString") queryString : string;
31   @Input("hitCnt") hitCnt : number;
32   dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
33
34   @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
35   @ViewChild(MatSort, {static: false} as any) sort: MatSort;
36
37   options: GridsterConfig;
38   dashboard :  Array<GridsterItem> = new Array();
39
40   displayedColumns : string[];
41   IncomingReportId : string;
42   displayedColumnsArr : string[];
43   displayedRowObj : {}[];
44   formFieldPresent : boolean;
45   showSpinner : boolean;
46   formFieldList : {}[];
47   isReady : boolean;
48   responseFormFieldListLength : number;
49   NEWdisplayedColumns : string[];
50   initCnt : number;
51   reportName : string;
52   showDashboardReport : boolean;
53   checkCnt : number;
54   initialQueryString : string;
55   initCounter : number;
56   runButtonHitCounter : number;
57   
58   constructor(private _dashboardReportService : DashboardReportService, private _router : Router) {
59     this.initCounter = 0;
60     this.runButtonHitCounter = 0;
61    }
62
63   ngOnInit(){
64     this.initialQueryString = this.queryString;
65     this.initCounter++;
66     this.runButtonHitCounter = this.hitCnt;
67     this.initialProcesses();
68   }
69
70   initialProcesses()
71   {
72     this.dataSource.paginator = this.paginator;
73   }
74
75   ngOnChanges()
76   {
77     if(this.initialQueryString !== this.queryString && this.initCounter > 0 && this.runButtonHitCounter !== this.hitCnt)
78     {
79       this.initialQueryString = this.queryString;
80       this.runButtonHitCounter = this.hitCnt;
81       this.initialProcesses();
82       this.afterViewInitProcesses();
83     }
84     else
85     {
86       this.runButtonHitCounter = this.hitCnt;
87       this.initialQueryString = this.queryString;
88     }
89     
90   }
91
92   ngAfterViewInit() {
93     setTimeout(() => {
94       this.afterViewInitProcesses();
95     })
96 }
97
98   afterViewInitProcesses()
99   {
100
101     this.displayedColumnsArr = new Array();
102     this.displayedRowObj = new Array();
103     this.displayedColumns = new Array();
104     this.formFieldList = new Array();
105     this.showSpinner = true;
106     this.isReady = false;
107     this.NEWdisplayedColumns = new Array();
108   this._dashboardReportService.getReportDataWithFormFields(this.queryString, this.reportId1)
109   .subscribe((response) => {
110       this.formFieldPresent = false;
111       this.responseFormFieldListLength = 0;
112
113       this.reportName = response["reportName"];
114
115     let i=0;
116     while(response["reportDataColumns"][i])
117     {
118       this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
119       i++;
120     }
121
122     let j=0;
123     while(response["reportDataRows"][j])
124     {
125       let k=0;
126       let obj = new Object();
127       while(this.displayedColumnsArr[k])
128       {
129         if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
130         {
131           obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
132         }
133         k++;
134       }
135       this.displayedRowObj.push(obj);
136       j++;
137     }
138
139     for(let l=0; l<this.displayedColumnsArr.length; l++)
140     {
141       this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
142     }
143     this.showSpinner = false;
144     
145     this.dataSource = new MatTableDataSource<PeriodicElement>(this.displayedRowObj);
146     this.dataSource.sort = this.sort;
147     this.dataSource.paginator = this.paginator;
148    
149
150   });
151
152   
153   }
154   
155   
156   
157   linkToReport(reportID : string, queryParameters : string)
158   {
159     this._router.navigate(['v2/run', reportID, queryParameters]);
160   }
161
162   linkToFeedback(feedBackId : string, queryParameters : string)
163   {
164     this._router.navigate(['v2/feedback', feedBackId]);
165   }
166
167   linkToMail(mailId : string)
168   {
169     var email = "mailto:" + mailId;
170     window.location.href = email;
171   }
172
173   applyFilter(filterValue: string) {
174     this.dataSource.filter = filterValue.trim().toLowerCase();
175   }
176
177  
178
179 }