aa36178f3bc3667e4015fc31109904afcad128fc
[portal/sdk.git] /
1 import {
2     AfterViewInit,
3     ChangeDetectionStrategy,
4     ChangeDetectorRef,
5     Component,
6     ElementRef,
7     HostListener,
8     Input,
9     OnChanges,
10     OnInit,
11     SimpleChanges,
12     ViewChild
13 } from '@angular/core';
14 import { MatPaginator } from '@angular/material/paginator';
15 import { MatSort } from '@angular/material/sort';
16 import { MatTableDataSource } from '@angular/material/table';
17 import { ActivatedRoute, Router } from '@angular/router';
18 import { HttpClient } from '@angular/common/http';
19 import { RunService } from '../run.service';
20 import { GridsterConfig, GridsterItem, GridType } from 'angular-gridster2';
21 import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
22 import {environment} from '../../../../environments/environment';
23 import {DisplayHtml} from '../../../pages/analytics/Report_List/Report/display-html';
24 import {ErrorModalComponent} from '../../../modals/error-modal/error-modal.component';
25 import {InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
26 import { FormControl } from '@angular/forms';
27 import { NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
28 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
29 import {MatDialog} from '@angular/material';
30 import {HttpCacheService} from '../../../shared/services/cache.service';
31
32 export interface PeriodicElement {
33
34 }
35
36 const ELEMENT_DATA: PeriodicElement[] = [{}];
37
38 @Component({
39     selector: 'app-run-report',
40     templateUrl: './run-report.component.html',
41     styleUrls: ['./run-report.component.css'],
42     changeDetection: ChangeDetectionStrategy.OnPush
43 })
44 export class RunReportComponent implements OnInit, AfterViewInit, OnChanges {
45     @Input('reportId') inputReportId: string;
46     @Input('reportMode') reportMode: string;
47     @Input('reportType') reportType: string;
48     @Input('queryString') queryString: string;
49     @Input('isGoBack') isGoBack: string;
50     @Input('DashboardReportObj') DashboardReportObj: Array<GridsterItem>;
51     @Input('TriggerFFArr') TriggerFFArr: string[];
52     @Input('hitCnt') hitCnt: number;
53     @Input('runAgain') runAgain: string;
54     @Input('groupSelectValue') groupSelectValue: string;
55     @Input('chartType') chartType: string;
56     @ViewChild('iframe') iframe: ElementRef;
57     @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
58     @ViewChild(MatSort, {static: false} as any) sort: MatSort;
59     dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
60     displayedColumns: string[];
61     IncomingReportId: string;
62     displayedColumnsArr: string[];
63     displayedRowObj: PeriodicElement[];
64     formFieldPresent: boolean;
65     showSpinner: boolean;
66     formFieldList: {}[];
67     isReady: boolean;
68     responseFormFieldListLength: number;
69     NEWdisplayedColumns: string[];
70     initCnt: number;
71     reportName: string;
72     showDashboardReport: boolean;
73     checkCnt: number;
74     options: GridsterConfig;
75     dashboard: Array<GridsterItem> = [];
76     openOptionsFlag: boolean;
77     showMoreVert: boolean;
78     errorMessage = '';
79     stackTrace = '';
80     error = false;
81     environment: any;
82     initialQueryString: string;
83     initCounter: number;
84     runButtonHitCnt: number;
85     chartRunUrl: string;
86     url: SafeResourceUrl;
87     replaceDisplayValue: String;
88     nodeName: string;
89     uploadId: string;
90     ecgi: string;
91     lac: string;
92     cid: string;
93     displayTotal: any[];
94     totalRecords: number;
95     pageSize: number;
96     download_in_progress: boolean;
97     commentCtrl = new FormControl('');
98     isChartAvailable = false;
99     timeTaken = '...';
100     saveResponseObj: any;
101     showBackButton = false;
102     customFieldsDataArray: any[];
103
104         isDashboardExcelReadyToDownload = false;
105     modalOptions: NgbModalOptions;
106         
107     constructor(private _http: HttpClient,
108         private _route: ActivatedRoute,
109         private _runService: RunService,
110         private _router: Router,
111         private changeDetectorRefs: ChangeDetectorRef,
112         public sanitizer: DomSanitizer,
113         public ngbModal: NgbModal,
114         private httpCacheService: HttpCacheService,
115         private dialog: MatDialog) {
116         this.displayedColumnsArr = [];
117         this.displayedRowObj = [];
118         this.displayedColumns = [];
119         this.formFieldList = [];
120         this.showSpinner = true;
121         this.isReady = false;
122         this.NEWdisplayedColumns = [];
123         this.initCnt = 0;
124         this.checkCnt = 0;
125         this.showDashboardReport = false;
126         this.openOptionsFlag = false;
127         this.showMoreVert = false;
128         this.environment = environment;
129         this.initCounter = 0;
130         this.runButtonHitCnt = 0;
131         this.displayTotal = [];
132         this.totalRecords = 0;
133         this.pageSize = 0;
134         this.download_in_progress = false;
135         this.isGoBack = '';
136                 this.isDashboardExcelReadyToDownload = false;
137         this.modalOptions = {
138             backdrop: 'static',
139             keyboard: false,
140             size: 'lg'
141         };
142     }
143
144     @HostListener('click') onClick() {
145         this.changeDetectorRefs.detectChanges();
146     }
147
148     ngOnChanges(changes: SimpleChanges) {
149         if (this.reportMode !== 'Regular' && this.initCnt > 0 && changes['runAgain']) {
150             this.isGoBack = '';
151             this.showMoreVert = false;
152             if (changes['queryString']) {
153                 this.queryString = changes['queryString']['currentValue'];
154             }
155             if (this.queryString !== this.initialQueryString) {
156                 this.initCnt = 1;
157                 this.showDashboardReport = false;
158                 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
159                 this.displayedColumnsArr = [];
160                 this.displayedRowObj = [];
161                 this.displayedColumns = [];
162                 this.formFieldList = [];
163                 this.showSpinner = true;
164                 this.isReady = false;
165                 this.NEWdisplayedColumns = [];
166                 this.displayTotal = [];
167                 this.isChartAvailable = false;
168                 this.timeTaken = '...';
169                 const startDate: Date = new Date();
170                 const startTime = startDate.getTime();
171                 this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId, this.groupSelectValue)
172                     .subscribe((response) => {
173                         if (response['errormessage']) {
174                             this.openErrorModel(response['errormessage']);
175                             this.showError();
176                             this.changeDetectorRefs.detectChanges();
177                         } else {
178                             this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
179                                 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
180                             if (this.reportMode !== 'FormField') {
181                                 this.postFetchingReportDataFn(response, false, 0);
182                                 const endDate: Date = new Date();
183                                 const endTime = endDate.getTime();
184                                 this.showMoreVert = true;
185                                 this.showDashboardReport = true;
186                                 this.errorMessage = '';
187                                 this.error = false;
188                             } else {
189                                 this.postFetchingReportDataFn(response, false, 0);
190                                 const endDate: Date = new Date();
191                                 const endTime = endDate.getTime();
192                                 this.showMoreVert = true;
193                                 this.errorMessage = '';
194                                 this.error = false;
195                             }
196                         }
197                     }, error => {
198                         this.openErrorModel('Error occurred while running report: ' + this.inputReportId);
199                         this.showError();
200                     });
201             }
202         } else {
203         }
204         if (this.initialQueryString !== this.queryString && this.initCounter > 0 && this.hitCnt !== this.runButtonHitCnt) {
205             this.runButtonHitCnt = this.hitCnt;
206             this.initialQueryString = this.queryString;
207             this.initialProcesses();
208         } else {
209             this.runButtonHitCnt = this.hitCnt;
210         }
211
212     }
213
214     ngOnInit() {
215         this.dataSource.paginator = this.paginator;
216         this.dataSource.sort = this.sort;
217         this.dataSource.data = this.displayedRowObj;
218         this.initialProcesses();
219         this.errorMessage = '';
220         this.error = false;
221     }
222
223     initialProcesses() {
224         if (this.DashboardReportObj.length > 0) {
225             this.dashboard = this.DashboardReportObj;
226             this.options = {
227                 gridType: GridType.VerticalFixed,
228                 margin: 10,
229                 outerMargin: true,
230                 outerMarginTop: 10,
231                 outerMarginRight: 10,
232                 outerMarginBottom: 5000,
233                 outerMarginLeft: 10,
234                 scrollSensitivity: 10,
235                 scrollSpeed: 20,
236                 fixedColWidth: 400,
237                 fixedRowHeight: 600,
238                 emptyCellDragMaxCols: null,
239                 emptyCellDragMaxRows: null,
240                 ignoreContentClass: 'gridster-item-content',
241                 enableOccupiedCellDrop: true,
242                 ignoreMarginInRow: false,
243                 draggable: {
244                     enabled: true,
245                 },
246                 resizable: {
247                     enabled: true,
248                 },
249                 swap: true,
250                 pushItems: true,
251                 disablePushOnDrag: false,
252                 disablePushOnResize: false,
253                 pushDirections: {north: true, east: true, south: true, west: true},
254                 pushResizeItems: true,
255                 disableWindowResize: true,
256                 disableWarnings: false,
257                 scrollToNewItems: true,
258                 enableDropToAdd: true,
259                 enableEmptyCellDrop: true,
260                 minCols: 2,
261                 minRows: 2,
262             };
263                 this._runService.getDashboardReportFormFields(this.inputReportId)
264                     .subscribe((dashboardFormFields) => {
265                         this.changeDetectorRefs.detectChanges();
266                             this._runService.runDashboardReport(this.inputReportId, this.queryString)
267                                 .subscribe((runDashboardReportResp) => {
268                                     if (runDashboardReportResp) {
269                                                                                 this.isDashboardExcelReadyToDownload = true;
270                                         this.changeDetectorRefs.detectChanges();
271                                     }
272                                 });
273                             this.download_in_progress = false;
274                         
275                     });
276             
277             this.showDashboardReport = true;
278
279         }
280         this.hitCnt = this.runButtonHitCnt;
281         this.initialQueryString = this.queryString;
282         this.initCounter++;
283     }
284
285     ngAfterViewInit() {
286         this.afterViewInitialProcesses();
287     }
288
289     afterViewInitialProcesses() {
290         if (sessionStorage.length > 0) {
291             this.showBackButton = true;
292         } else {
293             this.showBackButton = false;
294         }
295         if (this.DashboardReportObj.length === 0) {
296             if (this.reportMode === 'Regular' && this.initCnt == 0) {
297                 this.showMoreVert = false;
298                 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
299                 this.displayedColumnsArr = [];
300                 this.displayedRowObj = [];
301                 this.displayedColumns = [];
302                 this.formFieldList = [];
303                 this.showSpinner = true;
304                 this.isReady = false;
305                 this.NEWdisplayedColumns = [];
306                 this.timeTaken = '...';
307                 const startDate: Date = new Date();
308                 const startTime = startDate.getTime();
309                 this._runService.getReportData(this.inputReportId)
310                     .subscribe((response) => {
311                         if (response['errormessage']) {
312                             this.openErrorModel(response['errormessage']);
313                             this.showError();
314                             this.changeDetectorRefs.detectChanges();
315                         } else {
316                             this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
317                                 this.inputReportId + '&refresh=Y&display_content=Y&r_page=0';
318                             this.postFetchingReportDataFn(response, false, 0);
319                             const endDate: Date = new Date();
320                             const endTime = endDate.getTime();
321                             this.showMoreVert = true;
322                         }
323                     }, error => {
324                         this.openErrorModel('Error occurred while running report: ' + this.inputReportId);
325                         this.showError();
326                     });
327             } else {
328                 this.showMoreVert = false;
329                 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
330                 this.displayedColumnsArr = [];
331                 this.displayedRowObj = [];
332                 this.displayedColumns = [];
333                 this.formFieldList = [];
334                 this.showSpinner = true;
335                 this.isReady = false;
336                 this.NEWdisplayedColumns = [];
337                 this.timeTaken = '...';
338                 const startDate: Date = new Date();
339                 const startTime = startDate.getTime();
340                 if (localStorage.getItem(this.inputReportId)) {
341                     this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
342                         this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
343                     this.postFetchingReportDataFn(JSON.parse(localStorage.getItem(this.inputReportId)), false, 0);
344                     this.saveResponseObj = JSON.parse(localStorage.getItem(this.inputReportId));
345                     const endDate: Date = new Date();
346                     const endTime = endDate.getTime();
347                     this.showMoreVert = true;
348                     localStorage.removeItem(this.inputReportId);
349                     this.isGoBack = 'true';
350                 } else {
351                     this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId, this.groupSelectValue)
352                         .subscribe((response) => {
353                             if (response['errormessage']) {
354                                 this.openErrorModel(response['errormessage']);
355                                 this.showError();
356                                 this.changeDetectorRefs.detectChanges();
357                             } else {
358                                 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
359                                     this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
360                                 this.saveResponseObj = response;
361                                 this.postFetchingReportDataFn(response, false, 0);
362                                 const endDate: Date = new Date();
363                                 const endTime = endDate.getTime();
364                                 this.showMoreVert = true;
365                             }
366                         }, error => {
367                             this.openErrorModel('Error occurred while running report: ' + this.inputReportId);
368                             this.showError();
369                         });
370                 }
371             }
372         } else {
373             this.showMoreVert = true;
374             this.showSpinner = false;
375         }
376         this.errorMessage = '';
377         this.error = false;
378         this.initCnt = 1;
379     }
380
381     showError() {
382         this.showSpinner = false;
383         this.isChartAvailable = false;
384         this.changeDetectorRefs.detectChanges();
385     }
386
387     postFetchingReportDataFn(response: any, isPageChange: boolean, pagenum: any) {
388         this.pageSize = 0;
389         this.totalRecords = 0;
390         this.displayedColumnsArr = [];
391         this.displayedColumns = [];
392         this.customFieldsDataArray = [];
393         this.formFieldPresent = false;
394         this.responseFormFieldListLength = 0;
395         this.reportName = response['reportName'];
396         let rdc_cntr = 0;
397         this.timeTaken = (response['totalRunTime'] / 1000).toString();
398         this.displayedColumnsArr.push('RowNum,RowNum');
399         while (response['reportDataColumns'][rdc_cntr]) {
400             const columnTitle = response['reportDataColumns'][rdc_cntr]['columnTitle'];
401             const columnId = response['reportDataColumns'][rdc_cntr]['colId'];
402             this.displayedColumnsArr.push(columnTitle + ',' + columnId);
403             rdc_cntr++;
404         }
405
406         if (response['chartWizardAvailable'] === true && this.chartType !== 'none') {
407             this.isChartAvailable = true;
408             this.iframe.nativeElement.setAttribute('src', this.chartRunUrl);
409         }
410
411         let totalCnt = 0;
412         while (response['reportTotalDataRows'][totalCnt]) {
413             this.displayTotal.push(response['reportTotalDataRows'][totalCnt]);
414             totalCnt++;
415         }
416         this.customFieldsDataArray = response['reportDataRows'];
417         let rdr_cntr = 0;
418         while (response['reportDataRows'][rdr_cntr]) {
419             let dca_cntr = 0;
420             const obj = {};
421             const reportDataRows = response['reportDataRows'][rdr_cntr];
422             while (this.displayedColumnsArr[dca_cntr]) {
423                 const rowColumnId = this.displayedColumnsArr[dca_cntr].split(',')[1];
424                 if (reportDataRows[rowColumnId]) {
425                     let drillDownHtml = '';
426                     let displayValue = '';
427                     drillDownHtml = reportDataRows[rowColumnId]['drillDownURL'];
428                     displayValue = reportDataRows[rowColumnId]['displayValue'];
429                     if (drillDownHtml !== null &&
430                         drillDownHtml.length > 0 &&
431                         !displayValue.includes('linkToReport')) {
432                         const value = this.convertToLinkToReport(drillDownHtml);
433                         if (value.length > 0) {
434                             let valueCount = [];
435                             let valueDisplay = '';
436                             valueCount = reportDataRows[rowColumnId]['displayValue'].split('|');
437                             if (valueCount.length > 1 && this.reportType === 'Cross-Tab') {
438                                 for (let count = 0; count < valueCount.length - 1; count++) {
439                                     valueDisplay = valueDisplay + valueCount[count];
440                                 }
441                                 this.replaceDisplayValue = value + ',' + valueDisplay;
442                             } else {
443                                 this.replaceDisplayValue = value + ',' + reportDataRows[rowColumnId]['displayValue'];
444                             }
445                         } else {
446                             this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
447                         }
448                     } else {
449                         this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
450                     }
451                     let displayObj: DisplayHtml = new class implements DisplayHtml {
452                         'background-color': string;
453                         'font-family': string;
454                         'font-size': string;
455                         'font-style': string;
456                         'font-weight': string;
457                         'text-align': string;
458                         'text-decoration': string;
459                         color: string;
460                     };
461                     if (this.reportType === ('Cross-Tab') && reportDataRows[rowColumnId]['displayValueHtml'].includes('|')) {
462                         let crossTabDisplayValArr = [];
463                         crossTabDisplayValArr = reportDataRows[rowColumnId]['displayValueHtml'].split('|');
464                         if (crossTabDisplayValArr.length > 1) {
465                             displayObj['background-color'] = crossTabDisplayValArr[1];
466                         }
467                     }
468                     if (reportDataRows[rowColumnId]['displayValueHtml'].includes('setStyle')) {
469                         displayObj = JSON.parse(reportDataRows[rowColumnId]['displayValueHtml']);
470                     }
471                     displayObj['text-align'] = reportDataRows[rowColumnId]['alignment'];
472                     obj['RowNum'] = (pagenum * response['pageSize'] + rdr_cntr + 1) + '|{"text-align":"center"}';
473                     if (this.replaceDisplayValue.includes('linkToReport') || this.replaceDisplayValue.includes('linkToFeedback') || this.replaceDisplayValue.includes('linkToMail')
474                         || this.replaceDisplayValue.includes('linkToMap') || this.replaceDisplayValue.includes('linkToHref')) {
475                         let replaceValArr = new Array();
476                         if (this.replaceDisplayValue.includes('linkToReport')) {
477                             obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|');
478                             replaceValArr = obj[reportDataRows[rowColumnId]['colId']].split('|');
479                             if (replaceValArr.length > 4) {
480                                 const dispValue = replaceValArr[3] + ',' + replaceValArr[4];
481                                 obj[reportDataRows[rowColumnId]['colId']] =  obj[reportDataRows[rowColumnId]['colId']].replace(replaceValArr[3] + '|' + replaceValArr[4], replaceValArr[3] + ',' + replaceValArr[4])+ '|' + JSON.stringify(displayObj);
482                             } else {
483                                 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|')
484                                     + '|' + JSON.stringify(displayObj);
485                             }
486                         } else {
487                             obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|')
488                                 + '|' + JSON.stringify(displayObj);
489                         }
490                     } else {
491                         obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split('comment-break-line').join('')
492                             + '|' + JSON.stringify(displayObj);
493                     }
494                 }
495                 dca_cntr++;
496             }
497             this.displayedRowObj.push(obj);
498             rdr_cntr++;
499         }
500         this.pageSize = response['pageSize'];
501         for (let cntr = 0; cntr < this.displayedColumnsArr.length; cntr++) {
502             const columnArrId = this.displayedColumnsArr[cntr].split(',')[1];
503             this.displayedColumns.push(columnArrId);
504         }
505         this.totalRecords = 0;
506         this.totalRecords = response['totalRows'];
507         this.showSpinner = false;
508         if (!isPageChange) {
509             this.paginator.length = this.totalRecords;
510             this.paginator.pageSize = this.pageSize;
511             this.paginator.pageIndex = 0;
512         }
513         this.dataSource.data = this.displayedRowObj;
514         this.dataSource.sort = this.sort;
515         this.changeDetectorRefs.detectChanges();
516     }
517
518 linkToReport(reportID: string, queryParameters: string) {
519         if (!this.httpCacheService.getPreviousId(this.inputReportId)) {
520             this.httpCacheService.setPreviousId(this.inputReportId, 'parent');
521         }
522         this.httpCacheService.setPreviousId(reportID, this.inputReportId);
523 /*         localStorage.setItem(this.inputReportId, JSON.stringify(this.saveResponseObj));
524          if (sessionStorage.length === 0) {
525              sessionStorage.setItem('1', this.inputReportId + '|' + this.queryString);
526          } else {
527              let length = sessionStorage.length;
528              length++;
529              sessionStorage.setItem(length.toString(), this.inputReportId + '|' + this.queryString);
530          }*/
531         let queryParamsArr = [];
532         let columnDrilldownqueryParamsArr = [];
533          let groupSelectValue = '';
534          if (queryParameters.includes('groupSelectValue')) {
535              queryParamsArr = queryParameters.split('&');
536              for (let val = 0; val < queryParamsArr.length; val++) {
537                  if (queryParamsArr[val].includes('groupSelectValue')) {
538                      groupSelectValue = queryParamsArr[val].substring(queryParamsArr[val].indexOf('=') + 1, queryParamsArr[val].length);
539                  }
540              }
541              this._router.navigate(['v2/run', reportID, queryParameters, groupSelectValue]);
542          } else if (queryParameters.includes('SELECTCRITERIA-')) {
543              columnDrilldownqueryParamsArr = queryParameters.split('&');
544              for (let val = 0; val < columnDrilldownqueryParamsArr.length; val++) {
545                  if (columnDrilldownqueryParamsArr[val].includes('SELECTCRITERIA-')) {
546                      groupSelectValue = columnDrilldownqueryParamsArr[val].substring(columnDrilldownqueryParamsArr[val].indexOf('-') + 1, columnDrilldownqueryParamsArr[val].length);
547                  }
548              }
549              this._router.navigate(['v2/run', reportID, queryParameters, groupSelectValue, 'true', '']);
550          } else {
551              this._router.navigate(['v2/run', reportID, queryParameters, '' , 'true', '']);
552          }
553      }
554
555
556     linkToMail(mailId: string) {
557         this.changeDetectorRefs.detectChanges();
558         const email = 'mailto:' + mailId;
559         window.location.href = email;
560     }
561
562     openOptions() {
563         this.changeDetectorRefs.detectChanges();
564         this.openOptionsFlag = !this.openOptionsFlag;
565     }
566
567     downloadReport(contentType: string, extension: string) {
568
569         this.changeDetectorRefs.detectChanges();
570         if (this.showDashboardReport === false) {
571             this.download_in_progress = true;
572             this._runService.downloadReport(this.inputReportId, extension,this.isGoBack)
573                 .subscribe((responseExcel) => {
574
575                     this.downLoadFile(responseExcel, contentType, extension, '');
576                     this.download_in_progress = false;
577                     this.changeDetectorRefs.detectChanges();
578                 });
579         } else {
580             this.download_in_progress = true;
581             this._runService.getDashboardReportFormFields(this.inputReportId)
582                 .subscribe((dashboardFormFields) => {
583 /*                    this._runService.runDashboardReport(this.inputReportId, this.queryString)
584                             .subscribe((runDashboardReportResp) => {*/
585                             this._runService.downloadDashboardReportExcel(this.inputReportId)
586                                 .subscribe((responseDownloadDashboardReport) => {
587                                     this.downLoadFile(responseDownloadDashboardReport, contentType, extension, 'Dashboard');
588                                     this.download_in_progress = false;
589                                     this.changeDetectorRefs.detectChanges();
590                                 });
591                         //});
592
593                 });
594         }
595     }
596
597     downloadSinglePage(contentType: string, extension: string) {
598         this.changeDetectorRefs.detectChanges();
599         this.download_in_progress = true;
600         this._runService.downloadSinglePageReport(this.inputReportId, extension, this.isGoBack)
601             .subscribe((responseExcel) => {
602
603                 this.downLoadFile(responseExcel, contentType, extension, '');
604                 this.download_in_progress = false;
605                 this.changeDetectorRefs.detectChanges();
606             });
607     }
608
609     downLoadFile(data: any, type: string, extension: string, reportType: string) {
610         const blob = new Blob([data], {type: type});
611         const date = new Date();
612         const dateStr =
613             ('00' + (date.getMonth() + 1)).slice(-2) +
614             ('00' + date.getDate()).slice(-2) +
615             date.getFullYear() +
616             ('00' + date.getHours()).slice(-2) +
617             ('00' + date.getMinutes()).slice(-2) +
618             ('00' + date.getMilliseconds());
619         let fileName = this.reportName + dateStr + '.' + extension;
620         if (reportType === 'Dashboard') {
621             fileName = '';
622             fileName = reportType + '_' + this.inputReportId + '_' + dateStr + '.' + extension;
623         }
624         if (window.navigator.msSaveOrOpenBlob) {
625             window.navigator.msSaveBlob(blob, fileName);
626         } else {
627             const anchor = window.document.createElement('a');
628             anchor.href = window.URL.createObjectURL(blob);
629             anchor.download = fileName;
630             document.body.appendChild(anchor);
631             anchor.click();
632             document.body.removeChild(anchor);
633             window.URL.revokeObjectURL(anchor.href);
634         }
635     }
636
637     applyFilter(filterValue: string) {
638         this.changeDetectorRefs.detectChanges();
639         this.dataSource.data = this.displayedRowObj;
640         this.dataSource.sort = this.sort;
641         if (filterValue === '' || filterValue === null) {
642         } else {
643             this.dataSource.filter = filterValue.trim().toLowerCase();
644             this.changeDetectorRefs.detectChanges();
645         }
646     }
647
648     setStyle(rowData: string) {
649         let styles = '';
650         if (rowData.split('|')[0] === 'linkToReport') {
651             styles = rowData.split('|')[4];
652         } else if (rowData.split('|')[0] === 'linkToMail') {
653             styles = rowData.split('|')[3];
654         }  else if (this.reportType === 'Cross-Tab') {
655             const rowDataArray = rowData.split('|');
656             let crossTabstyles = {};
657             if (rowDataArray.length > 0) {
658                 if (rowDataArray[1].includes('{')) {
659                     styles = rowDataArray[1];
660                     return JSON.parse(styles);
661                 } else {
662                     crossTabstyles = {'background-color': rowData.split('|')[1]};
663                     return crossTabstyles;
664                 }
665             }
666         } else {
667             styles = rowData.split('|')[1];
668         }
669         if (styles !== undefined && styles.includes('{')) {
670             return JSON.parse(styles);
671         } else {
672             return {};
673         }
674     }
675
676     
677
678     getDisplayTotal(keys: string) {
679         if (this.displayTotal.length > 0 && this.displayTotal[0][keys]) {
680             return this.displayTotal[0][keys].displayValue;
681         } else {
682             return '';
683         }
684     }
685
686     onPaginationChange(event: any) {
687         this.changeDetectorRefs.detectChanges();
688         if (this.DashboardReportObj.length === 0) {
689             if (this.reportMode === 'Regular' && this.initCnt === 0) {
690                 this.showMoreVert = false;
691                 this.displayedColumnsArr = [];
692                 this.displayedRowObj = [];
693                 this.displayedColumns = [];
694                 this.formFieldList = [];
695                 this.showSpinner = true;
696                 this.isReady = false;
697                 this.NEWdisplayedColumns = [];
698                 this.isChartAvailable = false;
699                 this.timeTaken = '...';
700                 const startDate: Date = new Date();
701                 const startTime = startDate.getTime();
702                 this._runService.getReportDataWithPageNo(this.inputReportId, event.pageIndex)
703                     .subscribe((response) => {
704                         if (response['errormessage']) {
705                             this.openErrorModel(response['errormessage']);
706                             this.showError();
707                             this.changeDetectorRefs.detectChanges();
708                         } else {
709                             const endDate: Date = new Date();
710                             const endTime = endDate.getTime();
711                             this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
712                                 this.inputReportId + '&refresh=Y&display_content=Y&r_page=' + event.pageIndex;
713                             this.postFetchingReportDataFn(response, true, event.pageIndex);
714                             this.showMoreVert = true;
715                         }
716                     }, error => {
717                         this.openErrorModel('Error occurred while running report: ' + this.inputReportId);
718                         this.showError();
719                     });
720             } else {
721                 this.showMoreVert = false;
722                 this.displayedColumnsArr = [];
723                 this.displayedRowObj = [];
724                 this.displayedColumns = [];
725                 this.formFieldList = [];
726                 this.showSpinner = true;
727                 this.isReady = false;
728                 this.NEWdisplayedColumns = [];
729                 this.isChartAvailable = false;
730                 this.timeTaken = '...';
731                 const startDate: Date = new Date();
732                 const startTime = startDate.getTime();
733                 this._runService.getReportDataWithFormFieldsWithPageNo(this.queryString, this.inputReportId, event.pageIndex)
734                     .subscribe((response) => {
735                         if (response['errormessage']) {
736                             this.openErrorModel(response['errormessage']);
737                             this.showError();
738                             this.changeDetectorRefs.detectChanges();
739                         } else {
740                             const endDate: Date = new Date();
741                             const endTime = endDate.getTime();
742                             this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
743                                 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=' + event.pageIndex;
744                             this.postFetchingReportDataFn(response, true, event.pageIndex);
745                             this.showMoreVert = true;
746                         }
747                     }, error => {
748                         this.openErrorModel('Error occurred while running report: ' + this.inputReportId);
749                         this.showError();
750                     });
751             }
752         } else {
753             this.showMoreVert = true;
754             this.showSpinner = false;
755         }
756         this.errorMessage = '';
757         this.error = false;
758         this.initCnt = 1;
759     }
760
761     convertToLinkToReport(value: string) {
762         value = value.replace(/;/g, '');
763         let outPut = '';
764         while (value.includes('c_master=')) {
765             const index = value.indexOf('c_master=');
766             if (index > 0) {
767                 value = value.substring(index, value.length);
768             } else if (index === 0) {
769                 value = value.replace('c_master=', '');
770             }
771         }
772         const split = value.split('&');
773         if (split[1].length <= 0) {
774             return outPut;
775         }
776         outPut = 'linkToReport,' + split[0] + ',';
777         let splitCounter = 1;
778         for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
779             if (!split[splitCounter].includes('LOGIN_ID=') &&
780                 !split[splitCounter].includes('display_content=') &&
781                 !split[splitCounter].includes('drilldown_index=') &&
782                 !split[splitCounter].includes('show_back_btn=') &&
783                 !split[splitCounter].includes('r_action')) {
784                 outPut = outPut + '&' + split[splitCounter];
785             }
786         }
787         return outPut;
788     }
789
790     takeToReport(queryString: string, reportID: string) {
791         this._router.navigate(['v2/run', reportID, queryString, this.groupSelectValue]);
792     }
793
794     goBack() {
795         this.changeDetectorRefs.detectChanges();
796         const length = sessionStorage.length;
797         let repId = '';
798         let queryString = '';
799         if (length > 1) {
800             let split = [];
801             split = sessionStorage.getItem((length).toString()).split('|');
802             repId = split[0];
803             queryString = split[1];
804             sessionStorage.removeItem((length).toString());
805         } else if (length === 1) {
806             let split = [];
807             split = sessionStorage.getItem('1').split('|');
808             repId = split[0];
809             queryString = split[1];
810             sessionStorage.removeItem('1');
811         }
812         localStorage.removeItem(this.inputReportId);
813         this._router.navigate(['v2/run', repId, queryString]);
814     }
815     
816         openErrorModel(_message: string) { 
817         this.changeDetectorRefs.detectChanges(); 
818         const modalInfoRef = this.ngbModal.open(ErrorModalComponent, this.modalOptions);
819         modalInfoRef.componentInstance.message = _message; 
820         return modalInfoRef; 
821     }
822
823     openErrorModelPopup(_message: string) {
824         this.changeDetectorRefs.detectChanges();
825         const modalInfoRef = this.ngbModal.open(ErrorModalComponent, this.modalOptions);
826         modalInfoRef.componentInstance.message = _message;
827         modalInfoRef.result.then((data) => {
828             this.resetFormFieldValues(this.inputReportId);
829         });
830         return modalInfoRef;
831     }
832
833     resetFormFieldValues(reportId) {
834         this.httpCacheService.clearCache();
835         this._router.navigateByUrl('v2/app/refresh', {skipLocationChange: true}).then(() =>
836             this._router.navigate(['v2/run', reportId]));
837     }
838
839     linkToOpenNewTab(repId, formfiledValues) {
840         let str = [];
841         formfiledValues = formfiledValues.replaceAll('%2F','||');
842         str = window.location.pathname.split('/');
843         let approot = str[1];
844         let reportLink2 = this._router.serializeUrl(this._router.createUrlTree([approot + '/v2/run', repId, formfiledValues]));
845         window.open(reportLink2, '_blank');
846     }
847 }