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;
94 constructor(private _http: HttpClient,
95 private _route: ActivatedRoute,
96 private _runService: RunService,
97 private _router: Router,
98 private changeDetectorRefs: ChangeDetectorRef,
99 public sanitizer: DomSanitizer) {
100 this.displayedColumnsArr = [];
101 this.displayedRowObj = [];
102 this.displayedColumns = [];
103 this.formFieldList = [];
104 this.showSpinner = true;
105 this.isReady = false;
106 this.NEWdisplayedColumns = [];
109 this.showDashboardReport = false;
110 this.openOptionsFlag = false;
111 this.showMoreVert = false;
112 this.environment = environment;
113 this.initCounter = 0;
114 this.runButtonHitCnt = 0;
115 this.displayTotal = [];
116 this.totalRecords = 0;
118 this.download_in_progress = false;
122 ngOnChanges(changes: SimpleChanges) {
123 if (this.reportMode !== 'Regular' && this.initCnt > 0 && changes['runAgain']) {
124 this.showMoreVert = false;
125 if (changes['queryString']) {
126 this.queryString = changes['queryString']['currentValue'];
128 if (this.queryString !== this.initialQueryString) {
130 this.showDashboardReport = false;
131 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
132 this.displayedColumnsArr = [];
133 this.displayedRowObj = [];
134 this.displayedColumns = [];
135 this.formFieldList = [];
136 this.showSpinner = true;
137 this.isReady = false;
138 this.NEWdisplayedColumns = [];
139 this.displayTotal = [];
140 this.isChartAvailable = false;
141 this.timeTaken = '...';
142 const startDate: Date = new Date();
143 const startTime = startDate.getTime();
144 this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId)
145 .subscribe((response) => {
146 if (response['errormessage']) {
147 this.showError(response);
149 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
150 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
151 if (this.reportMode !== 'FormField') {
152 this.postFetchingReportDataFn(response, false);
153 const endDate: Date = new Date();
154 const endTime = endDate.getTime();
155 this.timeTaken = ((endTime - startTime) / 1000).toString();
156 this.showMoreVert = true;
157 this.showDashboardReport = true;
158 this.errorMessage = '';
161 this.postFetchingReportDataFn(response, false);
162 const endDate: Date = new Date();
163 const endTime = endDate.getTime();
164 this.timeTaken = ((endTime - startTime) / 1000).toString();
165 this.showMoreVert = true;
166 this.errorMessage = '';
174 if (this.initialQueryString !== this.queryString && this.initCounter > 0 && this.hitCnt !== this.runButtonHitCnt) {
175 this.runButtonHitCnt = this.hitCnt;
176 this.initialQueryString = this.queryString;
177 this.initialProcesses();
179 this.runButtonHitCnt = this.hitCnt;
185 this.dataSource.paginator = this.paginator;
186 this.dataSource.sort = this.sort;
187 this.dataSource.data = this.displayedRowObj;
188 this.initialProcesses();
189 this.errorMessage = '';
194 if (this.DashboardReportObj.length > 0) {
195 this.dashboard = this.DashboardReportObj;
197 gridType: GridType.ScrollVertical,
201 outerMarginRight: 10,
202 outerMarginBottom: 5000,
204 scrollSensitivity: 10,
206 emptyCellDragMaxCols: null,
207 emptyCellDragMaxRows: null,
208 ignoreContentClass: 'gridster-item-content',
209 enableOccupiedCellDrop: true,
210 ignoreMarginInRow: false,
219 disablePushOnDrag: false,
220 disablePushOnResize: false,
221 pushDirections: {north: true, east: true, south: true, west: true},
222 pushResizeItems: true,
223 disableWindowResize: true,
224 disableWarnings: false,
225 scrollToNewItems: true,
226 enableDropToAdd: true,
227 enableEmptyCellDrop: true,
231 this._runService.getDashboardReportFormFields(this.inputReportId)
232 .subscribe((dashboardFormFields) => {
233 this.download_in_progress = true;
234 this._runService.runDashboardReport(this.inputReportId, this.queryString)
235 .subscribe((runDashboardReportResp) => {
237 this.download_in_progress = false;
241 this.showDashboardReport = true;
244 this.hitCnt = this.runButtonHitCnt;
245 this.initialQueryString = this.queryString;
251 this.afterViewInitialProcesses();
254 afterViewInitialProcesses() {
255 if (sessionStorage.length > 0) {
256 this.showBackButton = true;
258 this.showBackButton = false;
260 if (this.DashboardReportObj.length === 0) {
261 if (this.reportMode === 'Regular' && this.initCnt == 0) {
262 this.showMoreVert = false;
263 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
264 this.displayedColumnsArr = [];
265 this.displayedRowObj = [];
266 this.displayedColumns = [];
267 this.formFieldList = [];
268 this.showSpinner = true;
269 this.isReady = false;
270 this.NEWdisplayedColumns = [];
271 this.timeTaken = '...';
272 const startDate: Date = new Date();
273 const startTime = startDate.getTime();
274 this._runService.getReportData(this.inputReportId)
275 .subscribe((response) => {
276 if (response['errormessage']) {
277 this.showError(response);
279 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
280 this.inputReportId + '&refresh=Y&display_content=Y&r_page=0';
281 this.postFetchingReportDataFn(response, false);
282 const endDate: Date = new Date();
283 const endTime = endDate.getTime();
284 this.timeTaken = ((endTime - startTime) / 1000).toString();
285 this.showMoreVert = true;
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 if (localStorage.getItem(this.inputReportId)) {
302 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
303 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
304 this.postFetchingReportDataFn(JSON.parse(localStorage.getItem(this.inputReportId)), false);
305 this.saveResponseObj = JSON.parse(localStorage.getItem(this.inputReportId));
306 const endDate: Date = new Date();
307 const endTime = endDate.getTime();
308 this.timeTaken = ((endTime - startTime) / 1000).toString();
309 this.showMoreVert = true;
310 localStorage.removeItem(this.inputReportId);
312 this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId)
313 .subscribe((response) => {
314 if (response['errormessage']) {
315 this.showError(response);
317 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
318 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
319 this.saveResponseObj = response;
320 this.postFetchingReportDataFn(response, false);
321 const endDate: Date = new Date();
322 const endTime = endDate.getTime();
323 this.timeTaken = ((endTime - startTime) / 1000).toString();
324 this.showMoreVert = true;
330 this.showMoreVert = true;
331 this.showSpinner = false;
333 this.errorMessage = '';
338 showError(Errresponse: any) {
339 this.errorMessage = Errresponse['errormessage'];
340 this.stackTrace = Errresponse['stacktrace'];
342 this.showSpinner = false;
343 this.isChartAvailable = false;
346 postFetchingReportDataFn(response: any, isPageChange: boolean) {
348 this.totalRecords = 0;
349 this.displayedColumnsArr = [];
350 this.displayedColumns = [];
351 this.formFieldPresent = false;
352 this.responseFormFieldListLength = 0;
353 this.reportName = response['reportName'];
355 while (response['reportDataColumns'][rdc_cntr]) {
356 const columnTitle = response['reportDataColumns'][rdc_cntr]['columnTitle'];
357 const columnId = response['reportDataColumns'][rdc_cntr]['colId'];
358 this.displayedColumnsArr.push(columnTitle + ',' + columnId);
362 if (response['chartWizardAvailable'] === true) {
363 this.isChartAvailable = true;
364 this.iframe.nativeElement.setAttribute('src', this.chartRunUrl);
368 while (response['reportTotalDataRows'][totalCnt]) {
369 this.displayTotal.push(response['reportTotalDataRows'][totalCnt]);
374 while (response['reportDataRows'][rdr_cntr]) {
377 const reportDataRows = response['reportDataRows'][rdr_cntr];
378 while (this.displayedColumnsArr[dca_cntr]) {
379 const rowColumnId = this.displayedColumnsArr[dca_cntr].split(',')[1];
380 if (reportDataRows[rowColumnId]) {
381 let drillDownHtml = '';
382 let displayValue = '';
383 drillDownHtml = reportDataRows[rowColumnId]['drillDownURL'];
384 displayValue = reportDataRows[rowColumnId]['displayValue'];
385 if (drillDownHtml !== null &&
386 drillDownHtml.length > 0 &&
387 !displayValue.includes('linkToReport')) {
388 const value = this.convertToLinkToReport(drillDownHtml);
389 if (value.length > 0) {
390 this.replaceDisplayValue = value + ',' +
391 reportDataRows[rowColumnId]['displayValue'];
393 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
396 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
398 let displayObj: DisplayHtml = new class implements DisplayHtml {
399 'background-color': string;
400 'font-family': string;
402 'font-style': string;
403 'font-weight': string;
404 'text-align': string;
405 'text-decoration': string;
408 if (reportDataRows[rowColumnId]['displayValueHtml'].includes('{')) {
409 displayObj = JSON.parse(reportDataRows[rowColumnId]['displayValueHtml']);
411 displayObj['text-align'] = reportDataRows[rowColumnId]['alignment'];
412 if (this.replaceDisplayValue.includes('linkToReport') || this.replaceDisplayValue.includes('linkToFeedback') || this.replaceDisplayValue.includes('linkToMail')) {
413 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|')
414 + '|' + JSON.stringify(displayObj);
416 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue
417 + '|' + JSON.stringify(displayObj);
422 this.displayedRowObj.push(obj);
425 this.pageSize = response['pageSize'];
426 for (let cntr = 0; cntr < this.displayedColumnsArr.length; cntr++) {
427 const columnArrId = this.displayedColumnsArr[cntr].split(',')[1];
428 this.displayedColumns.push(columnArrId);
430 this.totalRecords = 0;
431 this.totalRecords = response['totalRows'];
432 this.showSpinner = false;
434 this.paginator.length = this.totalRecords;
435 this.paginator.pageSize = this.pageSize;
436 this.paginator.pageIndex = 0;
438 this.dataSource.data = this.displayedRowObj;
439 this.dataSource.sort = this.sort;
443 linkToReport(reportID: string, queryParameters: string) {
444 localStorage.setItem(this.inputReportId, JSON.stringify(this.saveResponseObj));
445 if (sessionStorage.length === 0) {
446 sessionStorage.setItem('1', this.inputReportId + '|' + this.queryString);
448 let length = sessionStorage.length;
450 sessionStorage.setItem(length.toString(), this.inputReportId + '|' + this.queryString);
452 this._router.navigate(['v2/run', reportID, queryParameters]);
456 linkToFeedback(feedBackId: string, queryParameters: string) {
457 this._router.navigate(['v2/feedback', feedBackId]);
460 linkToMail(mailId: string) {
461 const email = 'mailto:' + mailId;
462 window.location.href = email;
466 this.openOptionsFlag = !this.openOptionsFlag;
469 downloadReport(contentType: string, extension: string) {
471 if (this.showDashboardReport === false) {
472 this.download_in_progress = true;
473 this._runService.downloadReport(this.inputReportId, extension)
474 .subscribe((responseExcel) => {
476 this.downLoadFile(responseExcel, contentType, extension, '');
477 this.download_in_progress = false;
480 this._runService.getDashboardReportFormFields(this.inputReportId)
481 .subscribe((dashboardFormFields) => {
482 this.download_in_progress = true;
483 this._runService.runDashboardReport(this.inputReportId, this.queryString)
484 .subscribe((runDashboardReportResp) => {
485 this._runService.downloadDashboardReportExcel(this.inputReportId)
486 .subscribe((responseDownloadDashboardReport) => {
487 this.downLoadFile(responseDownloadDashboardReport, contentType, extension, 'Dashboard');
490 this.download_in_progress = false;
495 downloadSinglePage(contentType: string, extension: string) {
496 this.download_in_progress = true;
497 this._runService.downloadSinglePageReport(this.inputReportId, extension)
498 .subscribe((responseExcel) => {
500 this.downLoadFile(responseExcel, contentType, extension, '');
501 this.download_in_progress = false;
505 downLoadFile(data: any, type: string, extension: string, reportType: string) {
506 const blob = new Blob([data], {type: type});
507 const dt = new Date();
508 const utcDate = dt.getTime();
509 let fileName = this.reportName + utcDate + '.' + extension;
510 if (reportType === 'Dashboard') {
512 fileName = reportType + '-' + this.inputReportId + '.' + extension;
514 if (window.navigator.msSaveOrOpenBlob) {
515 window.navigator.msSaveBlob(blob, fileName);
517 const anchor = window.document.createElement('a');
518 anchor.href = window.URL.createObjectURL(blob);
519 anchor.download = fileName;
520 document.body.appendChild(anchor);
522 document.body.removeChild(anchor);
523 window.URL.revokeObjectURL(anchor.href);
527 applyFilter(filterValue: string) {
528 this.dataSource.data = this.displayedRowObj;
529 this.dataSource.sort = this.sort;
530 if (filterValue === '' || filterValue === null) {
532 this.dataSource.filter = filterValue.trim().toLowerCase();
536 setStyle(styles: string) {
537 if (styles.includes('{')) {
538 return JSON.parse(styles);
544 getDisplayTotal(keys: string) {
545 if (this.displayTotal.length > 0) {
546 return this.displayTotal[0][keys].displayValue;
552 onPaginationChange(event: any) {
553 if (this.DashboardReportObj.length === 0) {
554 if (this.reportMode === 'Regular' && this.initCnt === 0) {
555 this.showMoreVert = false;
556 this.displayedColumnsArr = [];
557 this.displayedRowObj = [];
558 this.displayedColumns = [];
559 this.formFieldList = [];
560 this.showSpinner = true;
561 this.isReady = false;
562 this.NEWdisplayedColumns = [];
563 this.isChartAvailable = false;
564 this.timeTaken = '...';
565 const startDate: Date = new Date();
566 const startTime = startDate.getTime();
567 this._runService.getReportDataWithPageNo(this.inputReportId, event.pagenum)
568 .subscribe((response) => {
569 if (response['errormessage']) {
570 this.showError(response);
572 const endDate: Date = new Date();
573 const endTime = endDate.getTime();
574 this.timeTaken = ((endTime - startTime) / 1000).toString();
575 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
576 this.inputReportId + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
577 this.postFetchingReportDataFn(response, true);
578 this.showMoreVert = true;
582 this.showMoreVert = false;
583 this.displayedColumnsArr = [];
584 this.displayedRowObj = [];
585 this.displayedColumns = [];
586 this.formFieldList = [];
587 this.showSpinner = true;
588 this.isReady = false;
589 this.NEWdisplayedColumns = [];
590 this.isChartAvailable = false;
591 this.timeTaken = '...';
592 const startDate: Date = new Date();
593 const startTime = startDate.getTime();
594 this._runService.getReportDataWithFormFieldsWithPageNo(this.queryString, this.inputReportId, event.pageIndex)
595 .subscribe((response) => {
596 if (response['errormessage']) {
597 this.showError(response);
599 const endDate: Date = new Date();
600 const endTime = endDate.getTime();
601 this.timeTaken = ((endTime - startTime) / 1000).toString();
602 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
603 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
604 this.postFetchingReportDataFn(response, true);
605 this.showMoreVert = true;
610 this.showMoreVert = true;
611 this.showSpinner = false;
613 this.errorMessage = '';
618 convertToLinkToReport(value: string) {
619 value = value.replace(/;/g, '');
621 while (value.includes('c_master=')) {
622 const index = value.indexOf('c_master=');
624 value = value.substring(index, value.length);
625 } else if (index === 0) {
626 value = value.replace('c_master=', '');
629 const split = value.split('&');
630 // const spltFirst = split[0].split('=');
631 if (split[1].length <= 0) {
634 outPut = 'linkToReport,' + split[0] + ',';
635 let splitCounter = 1;
636 for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
637 if (!split[splitCounter].includes('LOGIN_ID=') &&
638 !split[splitCounter].includes('display_content=') &&
639 !split[splitCounter].includes('drilldown_index=') &&
640 !split[splitCounter].includes('show_back_btn=') &&
641 !split[splitCounter].includes('r_action')) {
642 outPut = outPut + '&' + split[splitCounter];
650 takeToReport(queryString: string, reportID: string) {
651 this._router.navigate(['v2/run', reportID, queryString , this.groupSelectValue]);
655 const length = sessionStorage.length;
657 let queryString = '';
660 split = sessionStorage.getItem((length).toString()).split('|');
662 queryString = split[1];
663 sessionStorage.removeItem((length).toString());
664 } else if (length === 1) {
666 split = sessionStorage.getItem('1').split('|');
668 queryString = split[1];
669 sessionStorage.removeItem('1');
671 localStorage.removeItem(this.inputReportId);
672 this._router.navigate(['v2/run', repId, queryString]);