1 import {Component, OnInit, Input, AfterViewInit, ViewChild, ElementRef, ChangeDetectorRef} 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 { RunService } from '../../run.service';
9 import {FormControl} from '@angular/forms';
10 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
11 import {environment} from '../../../../../environments/environment';
12 import {DisplayHtml} from '../../../../pages/analytics/Report_List/Report/display-html';
13 import {ErrorModalComponent} from '../../../../modals/error-modal/error-modal.component';
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> = [];
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,
65 private _router: Router,
66 private _runService: RunService,
67 private ngModal: NgbModal,
68 private changeDetectorRefs: ChangeDetectorRef,
69 public ngbModal: NgbModal) {
71 this.runButtonHitCounter = 0;
75 this.initialQueryString = this.queryString;
77 this.runButtonHitCounter = this.hitCnt;
78 if (this.reportType === 'Chart') {
79 this.showChart = true;
82 this.initialProcesses();
86 // this.dataSource.paginator = this.paginator;
90 if (this.initialQueryString !== this.queryString && this.initCounter > 0 && this.runButtonHitCounter !== this.hitCnt) {
91 this.initialQueryString = this.queryString;
92 this.runButtonHitCounter = this.hitCnt;
93 this.initialProcesses();
94 this.afterViewInitProcesses();
96 this.runButtonHitCounter = this.hitCnt;
97 this.initialQueryString = this.queryString;
102 this.afterViewInitProcesses();
105 afterViewInitProcesses() {
106 if (this.showChart) {
107 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
108 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
109 this.iframe.nativeElement.setAttribute('src', this.chartRunUrl);
110 this.showSpinner = false;
113 this.displayedColumnsArr = [];
114 this.displayedRowObj = [];
115 this.displayedColumns = [];
116 this.formFieldList = [];
117 this.showSpinner = true;
118 this.isReady = false;
119 this.NEWdisplayedColumns = [];
120 this.displayTotal = [];
121 if (localStorage.getItem(this.inputReportId)) {
122 this.postFetchingReportDataFn(JSON.parse(localStorage.getItem(this.inputReportId)));
123 localStorage.removeItem(this.inputReportId);
125 this._dashboardReportService.getReportDataWithFormFields(this.queryString, this.inputReportId)
126 .subscribe((response) => {
127 if (response['errormessage']){
128 this.openErrorModel(response['errormessage']);
129 this.showSpinner = false;
130 this.changeDetectorRefs.detectChanges();
132 this.postFetchingReportDataFn(response);
135 this.openErrorModel('Error occurred while running report: ' + this.inputReportId);
136 this.showSpinner = false;
137 this.changeDetectorRefs.detectChanges();
143 postFetchingReportDataFn(response: any){
144 this.saveResponseObj = response;
145 this.formFieldPresent = false;
146 this.responseFormFieldListLength = 0;
147 this.reportName = response['reportName'];
149 this.displayedColumnsArr.push('RowNum,RowNum');
150 while (response['reportDataColumns'][columnCntr]) {
151 this.displayedColumnsArr.push(response['reportDataColumns'][columnCntr]['columnTitle'] + ','
152 + response['reportDataColumns'][columnCntr]['colId']);
156 while (response['reportTotalDataRows'][totalCnt]) {
157 this.displayTotal.push(response['reportTotalDataRows'][totalCnt]);
161 while (response['reportDataRows'][rdr_cntr]) {
164 const reportDataRows = response['reportDataRows'][rdr_cntr];
165 while (this.displayedColumnsArr[dca_cntr]) {
166 const rowColumnId = this.displayedColumnsArr[dca_cntr].split(',')[1];
167 if (reportDataRows[rowColumnId]) {
168 let drillDownHtml = '';
169 let displayValue = '';
170 drillDownHtml = reportDataRows[rowColumnId]['drillDownURL'];
171 displayValue = reportDataRows[rowColumnId]['displayValue'];
172 if (drillDownHtml !== null &&
173 drillDownHtml.length > 0 &&
174 !displayValue.includes('linkToReport')) {
175 const value = this.convertToLinkToReport(drillDownHtml);
176 if (value.length > 0) {
177 this.replaceDisplayValue = value + ',' +
178 reportDataRows[rowColumnId]['displayValue'];
180 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
183 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
185 let displayObj: DisplayHtml = new class implements DisplayHtml {
186 'background-color': string;
187 'font-family': string;
189 'font-style': string;
190 'font-weight': string;
191 'text-align': string;
192 'text-decoration': string;
195 if (reportDataRows[rowColumnId]['displayValueHtml'].includes('{')) {
196 displayObj = JSON.parse(reportDataRows[rowColumnId]['displayValueHtml']);
198 displayObj['text-align'] = reportDataRows[rowColumnId]['alignment'];
199 obj['RowNum'] = (rdr_cntr + 1) + '|{"text-align":"center"}';
200 if (this.replaceDisplayValue.includes('linkToReport') || this.replaceDisplayValue.includes('linkToMail')) {
201 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|')
202 + '|' + JSON.stringify(displayObj);
204 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue
205 + '|' + JSON.stringify(displayObj);
210 this.displayedRowObj.push(obj);
213 for (let pushCounter = 0; pushCounter < this.displayedColumnsArr.length; pushCounter++) {
214 this.displayedColumns.push(this.displayedColumnsArr[pushCounter].split(',')[1]);
216 this.showSpinner = false;
217 this.dataSource = new MatTableDataSource<PeriodicElement>(this.displayedRowObj);
218 this.dataSource.sort = this.sort;
219 this.changeDetectorRefs.detectChanges();
222 linkToReport(reportID: string, queryParameters: string) {
223 localStorage.setItem(this.inputReportId, JSON.stringify(this.saveResponseObj));
224 if (sessionStorage.length === 0) {
225 sessionStorage.setItem('1', this.parentId + '|' + this.queryString);
227 let length = sessionStorage.length;
229 sessionStorage.setItem(length.toString(), this.parentId + '|' + this.queryString);
231 this._router.navigate(['v2/run', reportID, queryParameters]);
234 linkToMail(mailId: string) {
235 const email = 'mailto:' + mailId;
236 window.location.href = email;
239 applyFilter(filterValue: string) {
240 this.dataSource.filter = filterValue.trim().toLowerCase();
243 setStyle(rowData: string) {
245 if (rowData.split('|')[0] === 'linkToReport') {
246 styles = rowData.split('|')[4];
247 } else if (rowData.split('|')[0] === 'linkToMail') {
248 styles = rowData.split('|')[3];
250 styles = rowData.split('|')[1];
252 if (styles !== undefined && styles.includes('{')) {
253 return JSON.parse(styles);
259 getDisplayTotal(keys: any) {
260 if (this.displayTotal.length > 0) {
261 return this.displayTotal[0][keys].displayValue;
267 convertToLinkToReport(value: string) {
268 value = value.replace(/;/g, '');
270 while (value.includes('c_master=')) {
271 const index = value.indexOf('c_master=');
273 value = value.substring(index, value.length);
274 } else if (index === 0) {
275 value = value.replace('c_master=', '');
278 const split = value.split('&');
279 // const spltFirst = split[0].split('=');
280 if (split[1].length <= 0) {
283 outPut = 'linkToReport,' + split[0] + ',';
284 let splitCounter = 1;
285 for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
286 if (!split[splitCounter].includes('LOGIN_ID=') &&
287 !split[splitCounter].includes('display_content=') &&
288 !split[splitCounter].includes('drilldown_index=') &&
289 !split[splitCounter].includes('show_back_btn=') &&
290 !split[splitCounter].includes('r_action')) {
291 outPut = outPut + '&' + split[splitCounter];
297 openErrorModel(_message: string) {
298 const modalInfoRef = this.ngbModal.open(ErrorModalComponent);
299 modalInfoRef.componentInstance.message = _message;