1 import { Component, OnInit, Input, AfterViewInit, ViewChild, ElementRef } 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 import { environment } from '../../../../../../../../environments/environment';
9 import { DisplayHtml } from '../../../display-html';
10 import { RunService } from '../../run.service';
11 import {FormControl} from '@angular/forms';
15 export interface PeriodicElement {
19 const ELEMENT_DATA: PeriodicElement[] = [{}];
22 selector: 'app-run-dashboard-report',
23 templateUrl: './run-dashboard-report.component.html',
24 styleUrls: ['./run-dashboard-report.component.css']
27 export class RunDashboardReportComponent implements AfterViewInit {
29 @Input('reportId') inputReportId: string;
30 @Input('queryString') queryString: string;
31 @Input('hitCnt') hitCnt: number;
32 @Input('reportType') reportType: string;
33 @Input('parentId') parentId: string;
34 dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
35 @ViewChild(MatPaginator, { static: false } as any) paginator: MatPaginator;
36 @ViewChild(MatSort, { static: false } as any) sort: MatSort;
37 @ViewChild('iframe') iframe: ElementRef;
38 options: GridsterConfig;
39 dashboard: Array<GridsterItem> = new Array();
40 displayedColumns: string[];
41 IncomingReportId: string;
42 displayedColumnsArr: string[];
43 displayedRowObj: {}[];
44 formFieldPresent: boolean;
48 responseFormFieldListLength: number;
49 NEWdisplayedColumns: string[];
52 showDashboardReport: boolean;
54 initialQueryString: string;
56 runButtonHitCounter: number;
58 displayColumValue: string;
60 private chartRunUrl: string;
61 replaceDisplayValue: String;
64 constructor(private _dashboardReportService: DashboardReportService, private _router: Router,
65 private _runService: RunService) {
67 this.runButtonHitCounter = 0;
71 this.initialQueryString = this.queryString;
73 this.runButtonHitCounter = this.hitCnt;
74 if (this.reportType === 'Chart') {
75 this.showChart = true;
78 this.initialProcesses();
82 this.dataSource.paginator = this.paginator;
86 if (this.initialQueryString !== this.queryString && this.initCounter > 0 && this.runButtonHitCounter !== this.hitCnt) {
87 this.initialQueryString = this.queryString;
88 this.runButtonHitCounter = this.hitCnt;
89 this.initialProcesses();
90 this.afterViewInitProcesses();
92 this.runButtonHitCounter = this.hitCnt;
93 this.initialQueryString = this.queryString;
98 this.afterViewInitProcesses();
101 afterViewInitProcesses() {
102 if (this.showChart) {
103 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
104 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
105 this.iframe.nativeElement.setAttribute('src', this.chartRunUrl);
106 this.showSpinner = false;
109 this.displayedColumnsArr = new Array();
110 this.displayedRowObj = new Array();
111 this.displayedColumns = new Array();
112 this.formFieldList = new Array();
113 this.showSpinner = true;
114 this.isReady = false;
115 this.NEWdisplayedColumns = new Array();
116 this.displayTotal = [];
117 if (localStorage.getItem(this.inputReportId)) {
118 this.postFetchingReportDataFn(JSON.parse(localStorage.getItem(this.inputReportId)));
119 localStorage.removeItem(this.inputReportId);
121 this._dashboardReportService.getReportDataWithFormFields(this.queryString, this.inputReportId)
122 .subscribe((response) => {
123 this.postFetchingReportDataFn(response);
129 postFetchingReportDataFn(response: any){
130 this.saveResponseObj = response;
131 this.formFieldPresent = false;
132 this.responseFormFieldListLength = 0;
133 this.reportName = response['reportName'];
135 while (response['reportDataColumns'][columnCntr]) {
136 this.displayedColumnsArr.push(response['reportDataColumns'][columnCntr]['columnTitle'] + ','
137 + response['reportDataColumns'][columnCntr]['colId']);
141 while (response['reportTotalDataRows'][totalCnt]) {
142 this.displayTotal.push(response['reportTotalDataRows'][totalCnt]);
146 while (response['reportDataRows'][rdr_cntr]) {
149 const reportDataRows = response['reportDataRows'][rdr_cntr];
150 while (this.displayedColumnsArr[dca_cntr]) {
151 const rowColumnId = this.displayedColumnsArr[dca_cntr].split(',')[1];
152 if (reportDataRows[rowColumnId]) {
153 let drillDownHtml = '';
154 let displayValue = '';
155 drillDownHtml = reportDataRows[rowColumnId]['drillDownURL'];
156 displayValue = reportDataRows[rowColumnId]['displayValue'];
157 if (drillDownHtml !== null &&
158 drillDownHtml.length > 0 &&
159 !displayValue.includes('linkToReport')) {
160 const value = this.convertToLinkToReport(drillDownHtml);
161 if (value.length > 0) {
162 this.replaceDisplayValue = value + ',' +
163 reportDataRows[rowColumnId]['displayValue'];
165 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
168 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
170 let displayObj: DisplayHtml = new class implements DisplayHtml {
171 'background-color': string;
172 'font-family': string;
174 'font-style': string;
175 'font-weight': string;
176 'text-align': string;
177 'text-decoration': string;
180 if (reportDataRows[rowColumnId]['displayValueHtml'].includes('{')) {
181 displayObj = JSON.parse(reportDataRows[rowColumnId]['displayValueHtml']);
183 displayObj['text-align'] = reportDataRows[rowColumnId]['alignment'];
184 if (this.replaceDisplayValue.includes('linkToReport') || this.replaceDisplayValue.includes('linkToFeedback') || this.replaceDisplayValue.includes('linkToMail')) {
185 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|')
186 + '|' + JSON.stringify(displayObj);
188 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue
189 + '|' + JSON.stringify(displayObj);
194 this.displayedRowObj.push(obj);
197 for (let pushCounter = 0; pushCounter < this.displayedColumnsArr.length; pushCounter++) {
198 this.displayedColumns.push(this.displayedColumnsArr[pushCounter].split(',')[1]);
200 this.showSpinner = false;
201 this.dataSource = new MatTableDataSource<PeriodicElement>(this.displayedRowObj);
202 this.dataSource.sort = this.sort;
203 this.dataSource.paginator = this.paginator;
206 linkToReport(reportID: string, queryParameters: string) {
207 localStorage.setItem(this.inputReportId, JSON.stringify(this.saveResponseObj));
208 if (sessionStorage.length === 0) {
209 sessionStorage.setItem('1', this.parentId + '|' + this.queryString);
211 let length = sessionStorage.length;
213 sessionStorage.setItem(length.toString(), this.parentId + '|' + this.queryString);
215 this._router.navigate(['v2/run', reportID, queryParameters]);
218 linkToFeedback(feedBackId: string, queryParameters: string) {
219 this._router.navigate(['v2/feedback', feedBackId]);
222 linkToMail(mailId: string) {
223 const email = 'mailto:' + mailId;
224 window.location.href = email;
227 applyFilter(filterValue: string) {
228 this.dataSource.filter = filterValue.trim().toLowerCase();
231 setStyle(styles: string) {
232 if (styles.includes('{')) {
233 return JSON.parse(styles);
239 getDisplayTotal(keys: any) {
240 if (this.displayTotal.length > 0) {
241 return this.displayTotal[0][keys].displayValue;
247 convertToLinkToReport(value: string) {
248 value = value.replace(/;/g, '');
250 while (value.includes('c_master=')) {
251 const index = value.indexOf('c_master=');
253 value = value.substring(index, value.length);
254 } else if (index === 0) {
255 value = value.replace('c_master=', '');
258 const split = value.split('&');
259 // const spltFirst = split[0].split('=');
260 if (split[1].length <= 0) {
263 outPut = 'linkToReport,' + split[0] + ',';
264 let splitCounter = 1;
265 for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
266 if (!split[splitCounter].includes('LOGIN_ID=') &&
267 !split[splitCounter].includes('display_content=') &&
268 !split[splitCounter].includes('drilldown_index=') &&
269 !split[splitCounter].includes('show_back_btn=') &&
270 !split[splitCounter].includes('r_action')) {
271 outPut = outPut + '&' + split[splitCounter];