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 { HeaderService } from 'src/app/shared/services/header/header.service';
24 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
25 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
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'],
37 changeDetection: ChangeDetectionStrategy.OnPush
39 export class RunReportComponent implements OnInit, AfterViewInit {
40 @Input('reportId') inputReportId: string;
41 @Input('reportMode') reportMode: string;
42 @Input('queryString') queryString: string;
43 @Input('DashboardReportObj') DashboardReportObj: Array<GridsterItem>;
44 @Input('TriggerFFArr') TriggerFFArr: string[];
45 @Input('hitCnt') hitCnt: number;
46 @Input('runAgain') runAgain: string;
47 @Input('groupSelectValue') groupSelectValue: string;
48 @Input('chartType') chartType: string;
49 @ViewChild('iframe') iframe: ElementRef;
50 @ViewChild(MatPaginator, { static: false } as any) paginator: MatPaginator;
51 @ViewChild(MatSort, { static: false } as any) sort: MatSort;
52 dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
53 displayedColumns: string[];
54 IncomingReportId: string;
55 displayedColumnsArr: string[];
56 displayedRowObj: PeriodicElement[];
57 formFieldPresent: boolean;
61 responseFormFieldListLength: number;
62 NEWdisplayedColumns: string[];
65 showDashboardReport: boolean;
67 options: GridsterConfig;
68 dashboard: Array<GridsterItem> = [];
69 openOptionsFlag: boolean;
70 showMoreVert: boolean;
75 initialQueryString: string;
77 runButtonHitCnt: number;
80 replaceDisplayValue: String;
89 download_in_progress: boolean;
90 commentCtrl = new FormControl('');
91 isChartAvailable = false;
94 showBackButton = false;
96 constructor(private _http: HttpClient,
97 private _route: ActivatedRoute,
98 private _runService: RunService,
99 private _router: Router,
100 private changeDetectorRefs: ChangeDetectorRef,
101 public sanitizer: DomSanitizer) {
102 this.displayedColumnsArr = [];
103 this.displayedRowObj = [];
104 this.displayedColumns = [];
105 this.formFieldList = [];
106 this.showSpinner = true;
107 this.isReady = false;
108 this.NEWdisplayedColumns = [];
111 this.showDashboardReport = false;
112 this.openOptionsFlag = false;
113 this.showMoreVert = false;
114 this.environment = environment;
115 this.initCounter = 0;
116 this.runButtonHitCnt = 0;
117 this.displayTotal = [];
118 this.totalRecords = 0;
120 this.download_in_progress = false;
124 ngOnChanges(changes: SimpleChanges) {
125 if (this.reportMode !== 'Regular' && this.initCnt > 0 && changes['runAgain']) {
126 this.showMoreVert = false;
127 if (changes['queryString']) {
128 this.queryString = changes['queryString']['currentValue'];
130 if (this.queryString !== this.initialQueryString) {
132 this.showDashboardReport = false;
133 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
134 this.displayedColumnsArr = [];
135 this.displayedRowObj = [];
136 this.displayedColumns = [];
137 this.formFieldList = [];
138 this.showSpinner = true;
139 this.isReady = false;
140 this.NEWdisplayedColumns = [];
141 this.displayTotal = [];
142 this.isChartAvailable = false;
143 this.timeTaken = '...';
144 const startDate: Date = new Date();
145 const startTime = startDate.getTime();
146 this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId)
147 .subscribe((response) => {
148 if (response['errormessage']) {
149 this.showError(response);
151 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
152 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
153 if (this.reportMode !== 'FormField') {
154 this.postFetchingReportDataFn(response, false);
155 const endDate: Date = new Date();
156 const endTime = endDate.getTime();
157 this.timeTaken = ((endTime - startTime) / 1000).toString();
158 this.showMoreVert = true;
159 this.showDashboardReport = true;
160 this.errorMessage = '';
163 this.postFetchingReportDataFn(response, false);
164 const endDate: Date = new Date();
165 const endTime = endDate.getTime();
166 this.timeTaken = ((endTime - startTime) / 1000).toString();
167 this.showMoreVert = true;
168 this.errorMessage = '';
176 if (this.initialQueryString !== this.queryString && this.initCounter > 0 && this.hitCnt !== this.runButtonHitCnt) {
177 this.runButtonHitCnt = this.hitCnt;
178 this.initialQueryString = this.queryString;
179 this.initialProcesses();
181 this.runButtonHitCnt = this.hitCnt;
187 this.dataSource.paginator = this.paginator;
188 this.dataSource.sort = this.sort;
189 this.dataSource.data = this.displayedRowObj;
190 this.initialProcesses();
191 this.errorMessage = '';
196 if (this.DashboardReportObj.length > 0) {
197 this.dashboard = this.DashboardReportObj;
199 gridType: GridType.ScrollVertical,
203 outerMarginRight: 10,
204 outerMarginBottom: 5000,
206 scrollSensitivity: 10,
208 emptyCellDragMaxCols: null,
209 emptyCellDragMaxRows: null,
210 ignoreContentClass: 'gridster-item-content',
211 enableOccupiedCellDrop: true,
212 ignoreMarginInRow: false,
221 disablePushOnDrag: false,
222 disablePushOnResize: false,
223 pushDirections: { north: true, east: true, south: true, west: true },
224 pushResizeItems: true,
225 disableWindowResize: true,
226 disableWarnings: false,
227 scrollToNewItems: true,
228 enableDropToAdd: true,
229 enableEmptyCellDrop: true,
233 this._runService.getDashboardReportFormFields(this.inputReportId)
234 .subscribe((dashboardFormFields) => {
235 this.download_in_progress = true;
236 this._runService.runDashboardReport(this.inputReportId, this.queryString)
237 .subscribe((runDashboardReportResp) => {
239 this.download_in_progress = false;
243 this.showDashboardReport = true;
246 this.hitCnt = this.runButtonHitCnt;
247 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 && this.chartType !== 'none') {
364 this.isChartAvailable = true;
365 this.iframe.nativeElement.setAttribute('src', this.chartRunUrl);
369 while (response['reportTotalDataRows'][totalCnt]) {
370 this.displayTotal.push(response['reportTotalDataRows'][totalCnt]);
375 while (response['reportDataRows'][rdr_cntr]) {
378 const reportDataRows = response['reportDataRows'][rdr_cntr];
379 while (this.displayedColumnsArr[dca_cntr]) {
380 const rowColumnId = this.displayedColumnsArr[dca_cntr].split(',')[1];
381 if (reportDataRows[rowColumnId]) {
382 let drillDownHtml = '';
383 let displayValue = '';
384 drillDownHtml = reportDataRows[rowColumnId]['drillDownURL'];
385 displayValue = reportDataRows[rowColumnId]['displayValue'];
386 if (drillDownHtml !== null &&
387 drillDownHtml.length > 0 &&
388 !displayValue.includes('linkToReport')) {
389 const value = this.convertToLinkToReport(drillDownHtml);
390 if (value.length > 0) {
391 this.replaceDisplayValue = value + ',' +
392 reportDataRows[rowColumnId]['displayValue'];
394 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
397 this.replaceDisplayValue = reportDataRows[rowColumnId]['displayValue'];
399 let displayObj: DisplayHtml = new class implements DisplayHtml {
400 'background-color': string;
401 'font-family': string;
403 'font-style': string;
404 'font-weight': string;
405 'text-align': string;
406 'text-decoration': string;
409 if (reportDataRows[rowColumnId]['displayValueHtml'].includes('{')) {
410 displayObj = JSON.parse(reportDataRows[rowColumnId]['displayValueHtml']);
412 displayObj['text-align'] = reportDataRows[rowColumnId]['alignment'];
413 if (this.replaceDisplayValue.includes('linkToReport') || this.replaceDisplayValue.includes('linkToFeedback') || this.replaceDisplayValue.includes('linkToMail')) {
414 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue.split(',').join('|')
415 + '|' + JSON.stringify(displayObj);
417 obj[reportDataRows[rowColumnId]['colId']] = this.replaceDisplayValue
418 + '|' + JSON.stringify(displayObj);
423 this.displayedRowObj.push(obj);
426 this.pageSize = response['pageSize'];
427 for (let cntr = 0; cntr < this.displayedColumnsArr.length; cntr++) {
428 const columnArrId = this.displayedColumnsArr[cntr].split(',')[1];
429 this.displayedColumns.push(columnArrId);
431 this.totalRecords = 0;
432 this.totalRecords = response['totalRows'];
433 this.showSpinner = false;
435 this.paginator.length = this.totalRecords;
436 this.paginator.pageSize = this.pageSize;
437 this.paginator.pageIndex = 0;
439 this.dataSource.data = this.displayedRowObj;
440 this.dataSource.sort = this.sort;
444 linkToReport(reportID: string, queryParameters: string) {
445 localStorage.setItem(this.inputReportId, JSON.stringify(this.saveResponseObj));
446 if (sessionStorage.length === 0) {
447 sessionStorage.setItem('1', this.inputReportId + '|' + this.queryString);
449 let length = sessionStorage.length;
451 sessionStorage.setItem(length.toString(), this.inputReportId + '|' + this.queryString);
453 this._router.navigate(['v2/app/run', reportID, queryParameters]);
458 linkToMail(mailId: string) {
459 const email = 'mailto:' + mailId;
460 window.location.href = email;
464 this.openOptionsFlag = !this.openOptionsFlag;
467 downloadReport(contentType: string, extension: string) {
469 if (this.showDashboardReport === false) {
470 this.download_in_progress = true;
471 this._runService.downloadReport(this.inputReportId, extension)
472 .subscribe((responseExcel) => {
474 this.downLoadFile(responseExcel, contentType, extension, '');
475 this.download_in_progress = false;
478 this._runService.getDashboardReportFormFields(this.inputReportId)
479 .subscribe((dashboardFormFields) => {
480 this.download_in_progress = true;
481 this._runService.runDashboardReport(this.inputReportId, this.queryString)
482 .subscribe((runDashboardReportResp) => {
483 this._runService.downloadDashboardReportExcel(this.inputReportId)
484 .subscribe((responseDownloadDashboardReport) => {
485 this.downLoadFile(responseDownloadDashboardReport, contentType, extension, 'Dashboard');
488 this.download_in_progress = false;
493 downloadSinglePage(contentType: string, extension: string) {
494 this.download_in_progress = true;
495 this._runService.downloadSinglePageReport(this.inputReportId, extension)
496 .subscribe((responseExcel) => {
498 this.downLoadFile(responseExcel, contentType, extension, '');
499 this.download_in_progress = false;
503 downLoadFile(data: any, type: string, extension: string, reportType: string) {
504 const blob = new Blob([data], { type: type });
505 const date = new Date();
507 ('00' + (date.getMonth() + 1)).slice(-2) +
508 ('00' + date.getDate()).slice(-2) +
510 ('00' + date.getHours()).slice(-2) +
511 ('00' + date.getMinutes()).slice(-2) +
512 ('00' + date.getMilliseconds());
513 let fileName = this.reportName + dateStr + '.' + extension;
514 if (reportType === 'Dashboard') {
516 fileName = reportType + '_' + this.inputReportId + '_' + dateStr + '.' + extension;
518 if (window.navigator.msSaveOrOpenBlob) {
519 window.navigator.msSaveBlob(blob, fileName);
521 const anchor = window.document.createElement('a');
522 anchor.href = window.URL.createObjectURL(blob);
523 anchor.download = fileName;
524 document.body.appendChild(anchor);
526 document.body.removeChild(anchor);
527 window.URL.revokeObjectURL(anchor.href);
531 applyFilter(filterValue: string) {
532 this.dataSource.data = this.displayedRowObj;
533 this.dataSource.sort = this.sort;
534 if (filterValue === '' || filterValue === null) {
536 this.dataSource.filter = filterValue.trim().toLowerCase();
540 setStyle(rowData: string) {
542 if (rowData.split('|')[0] === 'linkToReport') {
543 styles = rowData.split('|')[4];
544 } else if (rowData.split('|')[0] === 'linkToMail') {
545 styles = rowData.split('|')[3];
547 styles = rowData.split('|')[1];
549 if (styles.includes('{')) {
550 return JSON.parse(styles);
558 getDisplayTotal(keys: string) {
559 if (this.displayTotal.length > 0) {
560 return this.displayTotal[0][keys].displayValue;
566 onPaginationChange(event: any) {
567 if (this.DashboardReportObj.length === 0) {
568 if (this.reportMode === 'Regular' && this.initCnt === 0) {
569 this.showMoreVert = false;
570 this.displayedColumnsArr = [];
571 this.displayedRowObj = [];
572 this.displayedColumns = [];
573 this.formFieldList = [];
574 this.showSpinner = true;
575 this.isReady = false;
576 this.NEWdisplayedColumns = [];
577 this.isChartAvailable = false;
578 this.timeTaken = '...';
579 const startDate: Date = new Date();
580 const startTime = startDate.getTime();
581 this._runService.getReportDataWithPageNo(this.inputReportId, event.pagenum)
582 .subscribe((response) => {
583 if (response['errormessage']) {
584 this.showError(response);
586 const endDate: Date = new Date();
587 const endTime = endDate.getTime();
588 this.timeTaken = ((endTime - startTime) / 1000).toString();
589 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
590 this.inputReportId + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
591 this.postFetchingReportDataFn(response, true);
592 this.showMoreVert = true;
596 this.showMoreVert = false;
597 this.displayedColumnsArr = [];
598 this.displayedRowObj = [];
599 this.displayedColumns = [];
600 this.formFieldList = [];
601 this.showSpinner = true;
602 this.isReady = false;
603 this.NEWdisplayedColumns = [];
604 this.isChartAvailable = false;
605 this.timeTaken = '...';
606 const startDate: Date = new Date();
607 const startTime = startDate.getTime();
608 this._runService.getReportDataWithFormFieldsWithPageNo(this.queryString, this.inputReportId, event.pageIndex)
609 .subscribe((response) => {
610 if (response['errormessage']) {
611 this.showError(response);
613 const endDate: Date = new Date();
614 const endTime = endDate.getTime();
615 this.timeTaken = ((endTime - startTime) / 1000).toString();
616 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
617 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
618 this.postFetchingReportDataFn(response, true);
619 this.showMoreVert = true;
624 this.showMoreVert = true;
625 this.showSpinner = false;
627 this.errorMessage = '';
632 convertToLinkToReport(value: string) {
633 value = value.replace(/;/g, '');
635 while (value.includes('c_master=')) {
636 const index = value.indexOf('c_master=');
638 value = value.substring(index, value.length);
639 } else if (index === 0) {
640 value = value.replace('c_master=', '');
643 const split = value.split('&');
644 if (split[1].length <= 0) {
647 outPut = 'linkToReport,' + split[0] + ',';
648 let splitCounter = 1;
649 for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
650 if (!split[splitCounter].includes('LOGIN_ID=') &&
651 !split[splitCounter].includes('display_content=') &&
652 !split[splitCounter].includes('drilldown_index=') &&
653 !split[splitCounter].includes('show_back_btn=') &&
654 !split[splitCounter].includes('r_action')) {
655 outPut = outPut + '&' + split[splitCounter];
661 takeToReport(queryString: string, reportID: string) {
662 this._router.navigate(['v2/app/run', reportID, queryString, this.groupSelectValue]);
666 const length = sessionStorage.length;
668 let queryString = '';
671 split = sessionStorage.getItem((length).toString()).split('|');
673 queryString = split[1];
674 sessionStorage.removeItem((length).toString());
675 } else if (length === 1) {
677 split = sessionStorage.getItem('1').split('|');
679 queryString = split[1];
680 sessionStorage.removeItem('1');
682 localStorage.removeItem(this.inputReportId);
683 this._router.navigate(['v2/app/run', repId, queryString]);