453fc9cf2ddcc40d0816d92e21a95b5f40c4700c
[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     this.afterViewInitProcesses();
94 }
95
96   afterViewInitProcesses()
97   {
98
99     this.displayedColumnsArr = new Array();
100     this.displayedRowObj = new Array();
101     this.displayedColumns = new Array();
102     this.formFieldList = new Array();
103     this.showSpinner = true;
104     this.isReady = false;
105     this.NEWdisplayedColumns = new Array();
106   this._dashboardReportService.getReportDataWithFormFields(this.queryString, this.reportId1)
107   .subscribe((response) => {
108       this.formFieldPresent = false;
109       this.responseFormFieldListLength = 0;
110
111       this.reportName = response["reportName"];
112
113     let i=0;
114     while(response["reportDataColumns"][i])
115     {
116       this.displayedColumnsArr.push(response["reportDataColumns"][i]["columnTitle"] +","+ response["reportDataColumns"][i]["colId"]);
117       i++;
118     }
119
120     let j=0;
121     while(response["reportDataRows"][j])
122     {
123       let k=0;
124       let obj = new Object();
125       while(this.displayedColumnsArr[k])
126       {
127         if(response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]])
128         {
129           obj[response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["colId"]] = response["reportDataRows"][j][this.displayedColumnsArr[k].split(",")[1]]["displayValue"];
130         }
131         k++;
132       }
133       this.displayedRowObj.push(obj);
134       j++;
135     }
136
137     for(let l=0; l<this.displayedColumnsArr.length; l++)
138     {
139       this.displayedColumns.push(this.displayedColumnsArr[l].split(",")[1]);
140     }
141     this.showSpinner = false;
142     
143     this.dataSource = new MatTableDataSource<PeriodicElement>(this.displayedRowObj);
144     this.dataSource.sort = this.sort;
145     this.dataSource.paginator = this.paginator;
146    
147
148   });
149
150   
151   }
152   
153   
154   
155   linkToReport(reportID : string, queryParameters : string)
156   {
157     this._router.navigate(['v2/run', reportID, queryParameters]);
158   }
159
160   linkToFeedback(feedBackId : string, queryParameters : string)
161   {
162     this._router.navigate(['v2/feedback', feedBackId]);
163   }
164
165   linkToMail(mailId : string)
166   {
167     var email = "mailto:" + mailId;
168     window.location.href = email;
169   }
170
171   applyFilter(filterValue: string) {
172     this.dataSource.filter = filterValue.trim().toLowerCase();
173   }
174
175  
176
177 }