12 } from '@angular/core';
13 import {MatPaginator} from '@angular/material/paginator';
14 import {MatSort} from '@angular/material/sort';
15 import {MatTable, MatTableDataSource} from '@angular/material/table';
16 import {ActivatedRoute, Router} from '@angular/router';
17 import {HttpClient} from '@angular/common/http';
18 import {environment} from '../../../../../../../environments/environment';
19 import {RunService} from '../run.service';
20 import {GridsterConfig, GridsterItem, GridType} from 'angular-gridster2';
21 import {Observable} from 'rxjs';
22 import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
23 import {displayGrids} from 'angular-gridster2/lib/gridsterConfig.interface';
24 import {DisplayHtml} from '../../display-html';
25 import {FormControl} from '@angular/forms';
27 export interface PeriodicElement {
31 const ELEMENT_DATA: PeriodicElement[] = [{}];
34 selector: 'app-run-report',
35 templateUrl: './run-report.component.html',
36 styleUrls: ['./run-report.component.css']
38 export class RunReportComponent implements OnInit, AfterViewInit {
39 @Input('reportId') inputReportId: string;
40 @Input('reportMode') reportMode: string;
41 @Input('queryString') queryString: string;
42 @Input('DashboardReportObj') DashboardReportObj: Array<GridsterItem>;
43 @Input('TriggerFFArr') TriggerFFArr: string[];
44 @Input('hitCnt') hitCnt: number;
45 @Input('runAgain') runAgain: string;
46 @Input('groupSelectValue') groupSelectValue: string;
47 @ViewChild('iframe') iframe: ElementRef;
48 @ViewChild(MatPaginator, {static: false} as any) paginator: MatPaginator;
49 @ViewChild(MatSort, {static: false} as any) sort: MatSort;
50 dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
51 displayedColumns: string[];
52 IncomingReportId: string;
53 displayedColumnsArr: string[];
54 displayedRowObj: PeriodicElement[];
55 formFieldPresent: boolean;
59 responseFormFieldListLength: number;
60 NEWdisplayedColumns: string[];
63 showDashboardReport: boolean;
65 options: GridsterConfig;
66 dashboard: Array<GridsterItem> = [];
67 openOptionsFlag: boolean;
68 showMoreVert: boolean;
73 initialQueryString: string;
75 runButtonHitCnt: number;
78 replaceDisplayValue: String;
87 download_in_progress: boolean;
88 commentCtrl = new FormControl('');
89 isChartAvailable = false;
92 showBackButton = false;
93 showChart: boolean = false;
95 constructor(private _http: HttpClient,
96 private _route: ActivatedRoute,
97 private _runService: RunService,
98 private _router: Router,
99 private changeDetectorRefs: ChangeDetectorRef,
100 public sanitizer: DomSanitizer) {
101 this.displayedColumnsArr = [];
102 this.displayedRowObj = [];
103 this.displayedColumns = [];
104 this.formFieldList = [];
105 this.showSpinner = true;
106 this.isReady = false;
107 this.NEWdisplayedColumns = [];
110 this.showDashboardReport = false;
111 this.openOptionsFlag = false;
112 this.showMoreVert = false;
113 this.environment = environment;
114 this.initCounter = 0;
115 this.runButtonHitCnt = 0;
116 this.displayTotal = [];
117 this.totalRecords = 0;
119 this.download_in_progress = false;
123 ngOnChanges(changes: SimpleChanges) {
124 if (this.reportMode !== 'Regular' && this.initCnt > 0 && changes['runAgain']) {
125 this.showMoreVert = false;
126 if (changes['queryString']) {
127 this.queryString = changes['queryString']['currentValue'];
129 if (this.queryString !== this.initialQueryString) {
131 this.showDashboardReport = false;
132 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
133 this.displayedColumnsArr = [];
134 this.displayedRowObj = [];
135 this.displayedColumns = [];
136 this.formFieldList = [];
137 this.showSpinner = true;
138 this.isReady = false;
139 this.NEWdisplayedColumns = [];
140 this.displayTotal = [];
141 this.isChartAvailable = false;
142 this.timeTaken = '...';
143 const startDate: Date = new Date();
144 const startTime = startDate.getTime();
145 this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId)
146 .subscribe((response) => {
147 if (response['errormessage']) {
148 this.showError(response);
150 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
151 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
152 if (this.reportMode !== 'FormField') {
153 this.postFetchingReportDataFn(response, false);
154 const endDate: Date = new Date();
155 const endTime = endDate.getTime();
156 this.timeTaken = ((endTime - startTime) / 1000).toString();
157 this.showMoreVert = true;
158 this.showDashboardReport = true;
159 this.errorMessage = '';
162 this.postFetchingReportDataFn(response, false);
163 const endDate: Date = new Date();
164 const endTime = endDate.getTime();
165 this.timeTaken = ((endTime - startTime) / 1000).toString();
166 this.showMoreVert = true;
167 this.errorMessage = '';
175 if (this.initialQueryString !== this.queryString && this.initCounter > 0 && this.hitCnt !== this.runButtonHitCnt) {
176 this.runButtonHitCnt = this.hitCnt;
177 this.initialQueryString = this.queryString;
178 this.initialProcesses();
180 this.runButtonHitCnt = this.hitCnt;
186 this.dataSource.paginator = this.paginator;
187 this.dataSource.sort = this.sort;
188 this.dataSource.data = this.displayedRowObj;
189 this.initialProcesses();
190 this.errorMessage = '';
195 if (this.DashboardReportObj.length > 0) {
196 this.dashboard = this.DashboardReportObj;
198 gridType: GridType.ScrollVertical,
202 outerMarginRight: 10,
203 outerMarginBottom: 5000,
205 scrollSensitivity: 10,
207 emptyCellDragMaxCols: null,
208 emptyCellDragMaxRows: null,
209 ignoreContentClass: 'gridster-item-content',
210 enableOccupiedCellDrop: true,
211 ignoreMarginInRow: false,
220 disablePushOnDrag: false,
221 disablePushOnResize: false,
222 pushDirections: {north: true, east: true, south: true, west: true},
223 pushResizeItems: true,
224 disableWindowResize: true,
225 disableWarnings: false,
226 scrollToNewItems: true,
227 enableDropToAdd: true,
228 enableEmptyCellDrop: true,
232 this._runService.getDashboardReportFormFields(this.inputReportId)
233 .subscribe((dashboardFormFields) => {
234 this.download_in_progress = true;
235 this._runService.runDashboardReport(this.inputReportId, this.queryString)
236 .subscribe((runDashboardReportResp) => {
238 this.download_in_progress = false;
242 this.showDashboardReport = true;
245 this.hitCnt = this.runButtonHitCnt;
246 this.initialQueryString = this.queryString;
252 this.afterViewInitialProcesses();
255 afterViewInitialProcesses() {
256 if (sessionStorage.length > 0) {
257 this.showBackButton = true;
259 this.showBackButton = false;
261 if (this.DashboardReportObj.length === 0) {
262 if (this.reportMode === 'Regular' && this.initCnt == 0) {
263 this.showMoreVert = false;
264 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
265 this.displayedColumnsArr = [];
266 this.displayedRowObj = [];
267 this.displayedColumns = [];
268 this.formFieldList = [];
269 this.showSpinner = true;
270 this.isReady = false;
271 this.NEWdisplayedColumns = [];
272 this.timeTaken = '...';
273 const startDate: Date = new Date();
274 const startTime = startDate.getTime();
275 this._runService.getReportData(this.inputReportId)
276 .subscribe((response) => {
277 if (response['errormessage']) {
278 this.showError(response);
280 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
281 this.inputReportId + '&refresh=Y&display_content=Y&r_page=0';
282 this.postFetchingReportDataFn(response, false);
283 const endDate: Date = new Date();
284 const endTime = endDate.getTime();
285 this.timeTaken = ((endTime - startTime) / 1000).toString();
286 this.showMoreVert = true;
290 this.showMoreVert = false;
291 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
292 this.displayedColumnsArr = [];
293 this.displayedRowObj = [];
294 this.displayedColumns = [];
295 this.formFieldList = [];
296 this.showSpinner = true;
297 this.isReady = false;
298 this.NEWdisplayedColumns = [];
299 this.timeTaken = '...';
300 const startDate: Date = new Date();
301 const startTime = startDate.getTime();
302 if (localStorage.getItem(this.inputReportId)) {
303 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
304 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
305 this.postFetchingReportDataFn(JSON.parse(localStorage.getItem(this.inputReportId)), false);
306 this.saveResponseObj = JSON.parse(localStorage.getItem(this.inputReportId));
307 const endDate: Date = new Date();
308 const endTime = endDate.getTime();
309 this.timeTaken = ((endTime - startTime) / 1000).toString();
310 this.showMoreVert = true;
311 localStorage.removeItem(this.inputReportId);
313 this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId)
314 .subscribe((response) => {
315 if (response['errormessage']) {
316 this.showError(response);
318 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
319 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
320 this.saveResponseObj = response;
321 this.postFetchingReportDataFn(response, false);
322 const endDate: Date = new Date();
323 const endTime = endDate.getTime();
324 this.timeTaken = ((endTime - startTime) / 1000).toString();
325 this.showMoreVert = true;
331 this.showMoreVert = true;
332 this.showSpinner = false;
334 this.errorMessage = '';
339 showError(Errresponse: any) {
340 this.errorMessage = Errresponse['errormessage'];
341 this.stackTrace = Errresponse['stacktrace'];
343 this.showSpinner = false;
344 this.isChartAvailable = false;
347 postFetchingReportDataFn(response: any, isPageChange: boolean) {
349 this.totalRecords = 0;
350 this.displayedColumnsArr = [];
351 this.displayedColumns = [];
352 this.formFieldPresent = false;
353 this.responseFormFieldListLength = 0;
354 this.reportName = response['reportName'];
356 while (response['reportDataColumns'][rdc_cntr]) {
357 const columnTitle = response['reportDataColumns'][rdc_cntr]['columnTitle'];
358 const columnId = response['reportDataColumns'][rdc_cntr]['colId'];
359 this.displayedColumnsArr.push(columnTitle + ',' + columnId);
363 if (response['chartWizardAvailable'] === true) {
364 this.isChartAvailable = true;
366 this.iframe.nativeElement.setAttribute('src', this.chartRunUrl);
371 while (response['reportTotalDataRows'][totalCnt]) {
372 this.displayTotal.push(response['reportTotalDataRows'][totalCnt]);
377 while (response['reportDataRows'][rdr_cntr]) {
380 const reportDataRows = response['reportDataRows'][rdr_cntr];
381 while (this.displayedColumnsArr[dca_cntr]) {
382 const rowColumnId = this.displayedColumnsArr[dca_cntr].split(',')[1];
383 if (reportDataRows[rowColumnId]) {
384 let drillDownHtml = '';
385 let displayValue = '';
386 drillDownHtml = reportDataRows[rowColumnId]['drillDownURL'];
387 displayValue = reportDataRows[rowColumnId]['displayValue'];
388 if (drillDownHtml !== null &&
389 drillDownHtml.length > 0 &&
390 !displayValue.includes('linkToReport')) {
391 const value = this.convertToLinkToReport(drillDownHtml);
392 if (value.length > 0) {
393 this.replaceDisplayValue = value + ',' +
394 reportDataRows[rowColumnId]['displayValue'];
396 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
399 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
401 let displayObj: DisplayHtml = new class implements DisplayHtml {
402 'background-color': string;
403 'font-family': string;
405 'font-style': string;
406 'font-weight': string;
407 'text-align': string;
408 'text-decoration': string;
411 if (reportDataRows[rowColumnId]['displayValueHtml'].includes('{')) {
412 displayObj = JSON.parse(reportDataRows[rowColumnId]['displayValueHtml']);
414 displayObj['text-align'] = reportDataRows[rowColumnId]['alignment'];
415 if (this.replaceDisplayValue.includes('linkToReport') || this.replaceDisplayValue.includes('linkToFeedback') || this.replaceDisplayValue.includes('linkToMail')) {
416 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|')
417 + '|' + JSON.stringify(displayObj);
419 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue
420 + '|' + JSON.stringify(displayObj);
425 this.displayedRowObj.push(obj);
428 this.pageSize = response['pageSize'];
429 for (let cntr = 0; cntr < this.displayedColumnsArr.length; cntr++) {
430 const columnArrId = this.displayedColumnsArr[cntr].split(',')[1];
431 this.displayedColumns.push(columnArrId);
433 this.totalRecords = 0;
434 this.totalRecords = response['totalRows'];
435 this.showSpinner = false;
437 this.paginator.length = this.totalRecords;
438 this.paginator.pageSize = this.pageSize;
439 this.paginator.pageIndex = 0;
441 this.dataSource.data = this.displayedRowObj;
442 this.dataSource.sort = this.sort;
443 if(this.totalRecords >0){
444 this.showChart = true;
449 linkToReport(reportID: string, queryParameters: string) {
450 localStorage.setItem(this.inputReportId, JSON.stringify(this.saveResponseObj));
451 if (sessionStorage.length === 0) {
452 sessionStorage.setItem('1', this.inputReportId + '|' + this.queryString);
454 let length = sessionStorage.length;
456 sessionStorage.setItem(length.toString(), this.inputReportId + '|' + this.queryString);
458 this._router.navigate(['v2/run', reportID, queryParameters]);
462 linkToFeedback(feedBackId: string, queryParameters: string) {
463 this._router.navigate(['v2/feedback', feedBackId]);
466 linkToMail(mailId: string) {
467 const email = 'mailto:' + mailId;
468 window.location.href = email;
472 this.openOptionsFlag = !this.openOptionsFlag;
475 downloadReport(contentType: string, extension: string) {
477 if (this.showDashboardReport === false) {
478 this.download_in_progress = true;
479 this._runService.downloadReport(this.inputReportId, extension)
480 .subscribe((responseExcel) => {
482 this.downLoadFile(responseExcel, contentType, extension, '');
483 this.download_in_progress = false;
486 this._runService.getDashboardReportFormFields(this.inputReportId)
487 .subscribe((dashboardFormFields) => {
488 this.download_in_progress = true;
489 this._runService.runDashboardReport(this.inputReportId, this.queryString)
490 .subscribe((runDashboardReportResp) => {
491 this._runService.downloadDashboardReportExcel(this.inputReportId)
492 .subscribe((responseDownloadDashboardReport) => {
493 this.downLoadFile(responseDownloadDashboardReport, contentType, extension, 'Dashboard');
496 this.download_in_progress = false;
501 downloadSinglePage(contentType: string, extension: string) {
502 this.download_in_progress = true;
503 this._runService.downloadSinglePageReport(this.inputReportId, extension)
504 .subscribe((responseExcel) => {
506 this.downLoadFile(responseExcel, contentType, extension, '');
507 this.download_in_progress = false;
511 downLoadFile(data: any, type: string, extension: string, reportType: string) {
512 const blob = new Blob([data], {type: type});
513 const dt = new Date();
514 const utcDate = dt.getTime();
515 let fileName = this.reportName + utcDate + '.' + extension;
516 if (reportType === 'Dashboard') {
518 fileName = reportType + '-' + this.inputReportId + '.' + extension;
520 if (window.navigator.msSaveOrOpenBlob) {
521 window.navigator.msSaveBlob(blob, fileName);
523 const anchor = window.document.createElement('a');
524 anchor.href = window.URL.createObjectURL(blob);
525 anchor.download = fileName;
526 document.body.appendChild(anchor);
528 document.body.removeChild(anchor);
529 window.URL.revokeObjectURL(anchor.href);
533 applyFilter(filterValue: string) {
534 this.dataSource.data = this.displayedRowObj;
535 this.dataSource.sort = this.sort;
536 if (filterValue === '' || filterValue === null) {
538 this.dataSource.filter = filterValue.trim().toLowerCase();
542 setStyle(styles: string) {
543 if (styles.includes('{')) {
544 return JSON.parse(styles);
550 getDisplayTotal(keys: string) {
551 if (this.displayTotal.length > 0) {
552 return this.displayTotal[0][keys].displayValue;
558 onPaginationChange(event: any) {
559 if (this.DashboardReportObj.length === 0) {
560 if (this.reportMode === 'Regular' && this.initCnt === 0) {
561 this.showMoreVert = false;
562 this.displayedColumnsArr = [];
563 this.displayedRowObj = [];
564 this.displayedColumns = [];
565 this.formFieldList = [];
566 this.showSpinner = true;
567 this.isReady = false;
568 this.NEWdisplayedColumns = [];
569 this.isChartAvailable = false;
570 this.timeTaken = '...';
571 const startDate: Date = new Date();
572 const startTime = startDate.getTime();
573 this._runService.getReportDataWithPageNo(this.inputReportId, event.pagenum)
574 .subscribe((response) => {
575 if (response['errormessage']) {
576 this.showError(response);
578 const endDate: Date = new Date();
579 const endTime = endDate.getTime();
580 this.timeTaken = ((endTime - startTime) / 1000).toString();
581 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
582 this.inputReportId + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
583 this.postFetchingReportDataFn(response, true);
584 this.showMoreVert = true;
588 this.showMoreVert = false;
589 this.displayedColumnsArr = [];
590 this.displayedRowObj = [];
591 this.displayedColumns = [];
592 this.formFieldList = [];
593 this.showSpinner = true;
594 this.isReady = false;
595 this.NEWdisplayedColumns = [];
596 this.isChartAvailable = false;
597 this.timeTaken = '...';
598 const startDate: Date = new Date();
599 const startTime = startDate.getTime();
600 this._runService.getReportDataWithFormFieldsWithPageNo(this.queryString, this.inputReportId, event.pageIndex)
601 .subscribe((response) => {
602 if (response['errormessage']) {
603 this.showError(response);
605 const endDate: Date = new Date();
606 const endTime = endDate.getTime();
607 this.timeTaken = ((endTime - startTime) / 1000).toString();
608 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
609 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
610 this.postFetchingReportDataFn(response, true);
611 this.showMoreVert = true;
616 this.showMoreVert = true;
617 this.showSpinner = false;
619 this.errorMessage = '';
624 convertToLinkToReport(value: string) {
625 value = value.replace(/;/g, '');
627 while (value.includes('c_master=')) {
628 const index = value.indexOf('c_master=');
630 value = value.substring(index, value.length);
631 } else if (index === 0) {
632 value = value.replace('c_master=', '');
635 const split = value.split('&');
636 // const spltFirst = split[0].split('=');
637 if (split[1].length <= 0) {
640 outPut = 'linkToReport,' + split[0] + ',';
641 let splitCounter = 1;
642 for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
643 if (!split[splitCounter].includes('LOGIN_ID=') &&
644 !split[splitCounter].includes('display_content=') &&
645 !split[splitCounter].includes('drilldown_index=') &&
646 !split[splitCounter].includes('show_back_btn=') &&
647 !split[splitCounter].includes('r_action')) {
648 outPut = outPut + '&' + split[splitCounter];
656 takeToReport(queryString: string, reportID: string) {
657 this._router.navigate(['v2/run', reportID, queryString , this.groupSelectValue]);
661 const length = sessionStorage.length;
663 let queryString = '';
666 split = sessionStorage.getItem((length).toString()).split('|');
668 queryString = split[1];
669 sessionStorage.removeItem((length).toString());
670 } else if (length === 1) {
672 split = sessionStorage.getItem('1').split('|');
674 queryString = split[1];
675 sessionStorage.removeItem('1');
677 localStorage.removeItem(this.inputReportId);
678 this._router.navigate(['v2/run', repId, queryString]);