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);
149 this.changeDetectorRefs.detectChanges();
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);
279 this.changeDetectorRefs.detectChanges();
281 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
282 this.inputReportId + '&refresh=Y&display_content=Y&r_page=0';
283 this.postFetchingReportDataFn(response, false);
284 const endDate: Date = new Date();
285 const endTime = endDate.getTime();
286 this.timeTaken = ((endTime - startTime) / 1000).toString();
287 this.showMoreVert = true;
291 this.showMoreVert = false;
292 this.dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
293 this.displayedColumnsArr = [];
294 this.displayedRowObj = [];
295 this.displayedColumns = [];
296 this.formFieldList = [];
297 this.showSpinner = true;
298 this.isReady = false;
299 this.NEWdisplayedColumns = [];
300 this.timeTaken = '...';
301 const startDate: Date = new Date();
302 const startTime = startDate.getTime();
303 if (localStorage.getItem(this.inputReportId)) {
304 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
305 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
306 this.postFetchingReportDataFn(JSON.parse(localStorage.getItem(this.inputReportId)), false);
307 this.saveResponseObj = JSON.parse(localStorage.getItem(this.inputReportId));
308 const endDate: Date = new Date();
309 const endTime = endDate.getTime();
310 this.timeTaken = ((endTime - startTime) / 1000).toString();
311 this.showMoreVert = true;
312 localStorage.removeItem(this.inputReportId);
314 this._runService.getReportDataWithFormFields(this.queryString, this.inputReportId)
315 .subscribe((response) => {
316 if (response['errormessage']) {
317 this.showError(response);
318 this.changeDetectorRefs.detectChanges();
320 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
321 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=0';
322 this.saveResponseObj = response;
323 this.postFetchingReportDataFn(response, false);
324 const endDate: Date = new Date();
325 const endTime = endDate.getTime();
326 this.timeTaken = ((endTime - startTime) / 1000).toString();
327 this.showMoreVert = true;
333 this.showMoreVert = true;
334 this.showSpinner = false;
336 this.errorMessage = '';
341 showError(Errresponse: any) {
342 this.errorMessage = Errresponse['errormessage'];
343 this.stackTrace = Errresponse['stacktrace'];
345 this.showSpinner = false;
346 this.isChartAvailable = false;
349 postFetchingReportDataFn(response: any, isPageChange: boolean) {
351 this.totalRecords = 0;
352 this.displayedColumnsArr = [];
353 this.displayedColumns = [];
354 this.formFieldPresent = false;
355 this.responseFormFieldListLength = 0;
356 this.reportName = response['reportName'];
358 while (response['reportDataColumns'][rdc_cntr]) {
359 const columnTitle = response['reportDataColumns'][rdc_cntr]['columnTitle'];
360 const columnId = response['reportDataColumns'][rdc_cntr]['colId'];
361 this.displayedColumnsArr.push(columnTitle + ',' + columnId);
365 if (response['chartWizardAvailable'] === true && this.chartType !== 'none') {
366 this.isChartAvailable = true;
367 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;
446 linkToReport(reportID: string, queryParameters: string) {
447 localStorage.setItem(this.inputReportId, JSON.stringify(this.saveResponseObj));
448 if (sessionStorage.length === 0) {
449 sessionStorage.setItem('1', this.inputReportId + '|' + this.queryString);
451 let length = sessionStorage.length;
453 sessionStorage.setItem(length.toString(), this.inputReportId + '|' + this.queryString);
455 this._router.navigate(['v2/app/run', reportID, queryParameters]);
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 date = new Date();
509 ('00' + (date.getMonth() + 1)).slice(-2) +
510 ('00' + date.getDate()).slice(-2) +
512 ('00' + date.getHours()).slice(-2) +
513 ('00' + date.getMinutes()).slice(-2) +
514 ('00' + date.getMilliseconds());
515 let fileName = this.reportName + dateStr + '.' + extension;
516 if (reportType === 'Dashboard') {
518 fileName = reportType + '_' + this.inputReportId + '_' + dateStr + '.' + 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(rowData: string) {
544 if (rowData.split('|')[0] === 'linkToReport') {
545 styles = rowData.split('|')[4];
546 } else if (rowData.split('|')[0] === 'linkToMail') {
547 styles = rowData.split('|')[3];
549 styles = rowData.split('|')[1];
551 if (styles.includes('{')) {
552 return JSON.parse(styles);
560 getDisplayTotal(keys: string) {
561 if (this.displayTotal.length > 0) {
562 return this.displayTotal[0][keys].displayValue;
568 onPaginationChange(event: any) {
569 if (this.DashboardReportObj.length === 0) {
570 if (this.reportMode === 'Regular' && this.initCnt === 0) {
571 this.showMoreVert = false;
572 this.displayedColumnsArr = [];
573 this.displayedRowObj = [];
574 this.displayedColumns = [];
575 this.formFieldList = [];
576 this.showSpinner = true;
577 this.isReady = false;
578 this.NEWdisplayedColumns = [];
579 this.isChartAvailable = false;
580 this.timeTaken = '...';
581 const startDate: Date = new Date();
582 const startTime = startDate.getTime();
583 this._runService.getReportDataWithPageNo(this.inputReportId, event.pagenum)
584 .subscribe((response) => {
585 if (response['errormessage']) {
586 this.showError(response);
587 this.changeDetectorRefs.detectChanges();
589 const endDate: Date = new Date();
590 const endTime = endDate.getTime();
591 this.timeTaken = ((endTime - startTime) / 1000).toString();
592 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
593 this.inputReportId + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
594 this.postFetchingReportDataFn(response, true);
595 this.showMoreVert = true;
599 this.showMoreVert = false;
600 this.displayedColumnsArr = [];
601 this.displayedRowObj = [];
602 this.displayedColumns = [];
603 this.formFieldList = [];
604 this.showSpinner = true;
605 this.isReady = false;
606 this.NEWdisplayedColumns = [];
607 this.isChartAvailable = false;
608 this.timeTaken = '...';
609 const startDate: Date = new Date();
610 const startTime = startDate.getTime();
611 this._runService.getReportDataWithFormFieldsWithPageNo(this.queryString, this.inputReportId, event.pageIndex)
612 .subscribe((response) => {
613 if (response['errormessage']) {
614 this.showError(response);
615 this.changeDetectorRefs.detectChanges();
617 const endDate: Date = new Date();
618 const endTime = endDate.getTime();
619 this.timeTaken = ((endTime - startTime) / 1000).toString();
620 this.chartRunUrl = environment.baseUrl + 'raptor.htm?action=chart.run&c_master=' +
621 this.inputReportId + this.queryString + '&refresh=Y&display_content=Y&r_page=' + event.pagenum;
622 this.postFetchingReportDataFn(response, true);
623 this.showMoreVert = true;
628 this.showMoreVert = true;
629 this.showSpinner = false;
631 this.errorMessage = '';
636 convertToLinkToReport(value: string) {
637 value = value.replace(/;/g, '');
639 while (value.includes('c_master=')) {
640 const index = value.indexOf('c_master=');
642 value = value.substring(index, value.length);
643 } else if (index === 0) {
644 value = value.replace('c_master=', '');
647 const split = value.split('&');
648 if (split[1].length <= 0) {
651 outPut = 'linkToReport,' + split[0] + ',';
652 let splitCounter = 1;
653 for (splitCounter = 1; splitCounter < split.length; splitCounter++) {
654 if (!split[splitCounter].includes('LOGIN_ID=') &&
655 !split[splitCounter].includes('display_content=') &&
656 !split[splitCounter].includes('drilldown_index=') &&
657 !split[splitCounter].includes('show_back_btn=') &&
658 !split[splitCounter].includes('r_action')) {
659 outPut = outPut + '&' + split[splitCounter];
665 takeToReport(queryString: string, reportID: string) {
666 this._router.navigate(['v2/app/run', reportID, queryString, this.groupSelectValue]);
670 const length = sessionStorage.length;
672 let queryString = '';
675 split = sessionStorage.getItem((length).toString()).split('|');
677 queryString = split[1];
678 sessionStorage.removeItem((length).toString());
679 } else if (length === 1) {
681 split = sessionStorage.getItem('1').split('|');
683 queryString = split[1];
684 sessionStorage.removeItem('1');
686 localStorage.removeItem(this.inputReportId);
687 this._router.navigate(['v2/app/run', repId, queryString]);