3 ChangeDetectionStrategy,
11 } from '@angular/core';
12 import { MatPaginator } from '@angular/material/paginator';
13 import { MatSort } from '@angular/material/sort';
14 import { MatTableDataSource } from '@angular/material/table';
15 import { ActivatedRoute, Router } from '@angular/router';
16 import { HttpClient } from '@angular/common/http';
17 import { environment } from '../../../../../../../environments/environment';
18 import { RunService } from '../run.service';
19 import { GridsterConfig, GridsterItem, GridType } from 'angular-gridster2';
20 import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
21 import { DisplayHtml } from '../../display-html';
22 import { FormControl } from '@angular/forms';
23 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
24 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
26 export interface PeriodicElement {
30 const ELEMENT_DATA: PeriodicElement[] = [{}];
33 selector: 'app-run-report',
34 templateUrl: './run-report.component.html',
35 styleUrls: ['./run-report.component.css'],
36 changeDetection: ChangeDetectionStrategy.OnPush
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 @Input('chartType') chartType: string;
48 @ViewChild('iframe') iframe: ElementRef;
49 @ViewChild(MatPaginator, { static: false } as any) paginator: MatPaginator;
50 @ViewChild(MatSort, { static: false } as any) sort: MatSort;
51 dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
52 displayedColumns: string[];
53 IncomingReportId: string;
54 displayedColumnsArr: string[];
55 displayedRowObj: PeriodicElement[];
56 formFieldPresent: boolean;
60 responseFormFieldListLength: number;
61 NEWdisplayedColumns: string[];
64 showDashboardReport: boolean;
66 options: GridsterConfig;
67 dashboard: Array<GridsterItem> = [];
68 openOptionsFlag: boolean;
69 showMoreVert: boolean;
74 initialQueryString: string;
76 runButtonHitCnt: number;
79 replaceDisplayValue: String;
88 download_in_progress: boolean;
89 commentCtrl = new FormControl('');
90 isChartAvailable = false;
93 showBackButton = 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;
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 && this.chartType !== 'none') {
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/app/run', reportID, queryParameters]);
457 linkToMail(mailId: string) {
458 const email = 'mailto:' + mailId;
459 window.location.href = email;
463 this.openOptionsFlag = !this.openOptionsFlag;
466 downloadReport(contentType: string, extension: string) {
468 if (this.showDashboardReport === false) {
469 this.download_in_progress = true;
470 this._runService.downloadReport(this.inputReportId, extension)
471 .subscribe((responseExcel) => {
473 this.downLoadFile(responseExcel, contentType, extension, '');
474 this.download_in_progress = false;
477 this._runService.getDashboardReportFormFields(this.inputReportId)
478 .subscribe((dashboardFormFields) => {
479 this.download_in_progress = true;
480 this._runService.runDashboardReport(this.inputReportId, this.queryString)
481 .subscribe((runDashboardReportResp) => {
482 this._runService.downloadDashboardReportExcel(this.inputReportId)
483 .subscribe((responseDownloadDashboardReport) => {
484 this.downLoadFile(responseDownloadDashboardReport, contentType, extension, 'Dashboard');
487 this.download_in_progress = false;
492 downloadSinglePage(contentType: string, extension: string) {
493 this.download_in_progress = true;
494 this._runService.downloadSinglePageReport(this.inputReportId, extension)
495 .subscribe((responseExcel) => {
497 this.downLoadFile(responseExcel, contentType, extension, '');
498 this.download_in_progress = false;
502 downLoadFile(data: any, type: string, extension: string, reportType: string) {
503 const blob = new Blob([data], { type: type });
504 const date = new Date();
506 ('00' + (date.getMonth() + 1)).slice(-2) +
507 ('00' + date.getDate()).slice(-2) +
509 ('00' + date.getHours()).slice(-2) +
510 ('00' + date.getMinutes()).slice(-2) +
511 ('00' + date.getMilliseconds());
512 let fileName = this.reportName + dateStr + '.' + extension;
513 if (reportType === 'Dashboard') {
515 fileName = reportType + '_' + this.inputReportId + '_' + dateStr + '.' + extension;
517 if (window.navigator.msSaveOrOpenBlob) {
518 window.navigator.msSaveBlob(blob, fileName);
520 const anchor = window.document.createElement('a');
521 anchor.href = window.URL.createObjectURL(blob);
522 anchor.download = fileName;
523 document.body.appendChild(anchor);
525 document.body.removeChild(anchor);
526 window.URL.revokeObjectURL(anchor.href);
530 applyFilter(filterValue: string) {
531 this.dataSource.data = this.displayedRowObj;
532 this.dataSource.sort = this.sort;
533 if (filterValue === '' || filterValue === null) {
535 this.dataSource.filter = filterValue.trim().toLowerCase();
539 setStyle(rowData: string) {
541 if (rowData.split('|')[0] === 'linkToReport') {
542 styles = rowData.split('|')[4];
543 } else if (rowData.split('|')[0] === 'linkToMail') {
544 styles = rowData.split('|')[3];
546 styles = rowData.split('|')[1];
548 if (styles.includes('{')) {
549 return JSON.parse(styles);
557 getDisplayTotal(keys: string) {
558 if (this.displayTotal.length > 0) {
559 return this.displayTotal[0][keys].displayValue;
565 onPaginationChange(event: any) {
566 if (this.DashboardReportObj.length === 0) {
567 if (this.reportMode === 'Regular' && this.initCnt === 0) {
568 this.showMoreVert = false;
569 this.displayedColumnsArr = [];
570 this.displayedRowObj = [];
571 this.displayedColumns = [];
572 this.formFieldList = [];
573 this.showSpinner = true;
574 this.isReady = false;
575 this.NEWdisplayedColumns = [];
576 this.isChartAvailable = false;
577 this.timeTaken = '...';
578 const startDate: Date = new Date();
579 const startTime = startDate.getTime();
580 this._runService.getReportDataWithPageNo(this.inputReportId, event.pagenum)
581 .subscribe((response) => {
582 if (response['errormessage']) {
583 this.showError(response);
585 const endDate: Date = new Date();
586 const endTime = endDate.getTime();
587 this.timeTaken = ((endTime - startTime) / 1000).toString();
588 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
589 this.inputReportId + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
590 this.postFetchingReportDataFn(response, true);
591 this.showMoreVert = true;
595 this.showMoreVert = false;
596 this.displayedColumnsArr = [];
597 this.displayedRowObj = [];
598 this.displayedColumns = [];
599 this.formFieldList = [];
600 this.showSpinner = true;
601 this.isReady = false;
602 this.NEWdisplayedColumns = [];
603 this.isChartAvailable = false;
604 this.timeTaken = '...';
605 const startDate: Date = new Date();
606 const startTime = startDate.getTime();
607 this._runService.getReportDataWithFormFieldsWithPageNo(this.queryString, this.inputReportId, event.pageIndex)
608 .subscribe((response) => {
609 if (response['errormessage']) {
610 this.showError(response);
612 const endDate: Date = new Date();
613 const endTime = endDate.getTime();
614 this.timeTaken = ((endTime - startTime) / 1000).toString();
615 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
616 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
617 this.postFetchingReportDataFn(response, true);
618 this.showMoreVert = true;
623 this.showMoreVert = true;
624 this.showSpinner = false;
626 this.errorMessage = '';
631 convertToLinkToReport(value: string) {
632 value = value.replace(/;/g, '');
634 while (value.includes('c_master=')) {
635 const index = value.indexOf('c_master=');
637 value = value.substring(index, value.length);
638 } else if (index === 0) {
639 value = value.replace('c_master=', '');
642 const split = value.split('&');
643 if (split[1].length <= 0) {
646 outPut = 'linkToReport,' + split[0] + ',';
647 let splitCounter = 1;
648 for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
649 if (!split[splitCounter].includes('LOGIN_ID=') &&
650 !split[splitCounter].includes('display_content=') &&
651 !split[splitCounter].includes('drilldown_index=') &&
652 !split[splitCounter].includes('show_back_btn=') &&
653 !split[splitCounter].includes('r_action')) {
654 outPut = outPut + '&' + split[splitCounter];
660 takeToReport(queryString: string, reportID: string) {
661 this._router.navigate(['v2/app/run', reportID, queryString, this.groupSelectValue]);
665 const length = sessionStorage.length;
667 let queryString = '';
670 split = sessionStorage.getItem((length).toString()).split('|');
672 queryString = split[1];
673 sessionStorage.removeItem((length).toString());
674 } else if (length === 1) {
676 split = sessionStorage.getItem('1').split('|');
678 queryString = split[1];
679 sessionStorage.removeItem('1');
681 localStorage.removeItem(this.inputReportId);
682 this._router.navigate(['v2/app/run', repId, queryString]);