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