import {Injectable} from '@angular/core'; import {HttpClient, HttpHeaders} from '@angular/common/http'; import {Observable, throwError} from 'rxjs'; import {retry, catchError} from 'rxjs/operators'; import {HtmlParser} from '@angular/compiler'; import {environment} from '../../../environments/environment'; @Injectable({ providedIn: 'root' }) export class RunService { finalArr: any; finalResponseArr: any; constructor(private _http: HttpClient) { } getReportData(reportId: string): Observable { return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master=' + reportId + '&refresh=Y'); } getReportDataWithFormFields(queryString: string, reportId: string, groupSelectValue: string): Observable { return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master=' + reportId + queryString + '&refresh=Y&display_content=Y&r_page=0&groupSelectValue='+groupSelectValue); } getReportDataWithPageNo(reportId: string, pageNo: string): Observable { if (!pageNo || pageNo === null) { pageNo = '0'; } return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master=' + reportId + '&refresh=Ydisplay_content=Y&r_page=' + pageNo); } getReportDataWithFormFieldsWithPageNo(queryString: string, reportId: string, pageNo: string): Observable { if (!pageNo || pageNo === null) { pageNo = '0'; } return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master=' + reportId + queryString + '&refresh=Y&display_content=Y&r_page=' + pageNo); } getDefinitionPageDetails(IncomingReportId: number): Observable { return this._http.get(environment.baseUrl + 'report/wizard/retrieve_def_tab_wise_data/' + IncomingReportId, {headers: new HttpHeaders({'Content-Type': 'application/json'})}); } refreshFormFields(reportId: string, queryString: string): Observable { return this._http.get(environment.baseUrl + 'raptor.htm?action=report.formfields.run.container&c_master=' + reportId + queryString); } getFormFieldGroupsData(reportId: string): Observable { return this._http.get(environment.baseUrl + 'report/wizard/get_formfield_groups_data/' + reportId); } downloadReportExcel(reportId: string): Observable { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_dowload=true', {responseType: 'blob'}); } downloadReport(reportId: string, type: string, isGoBack: string): Observable { if (type === 'xlsx') { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_download=false&go_back=' + isGoBack, {responseType: 'blob'}); } else if (type === 'pdf') { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.pdf.session&page_download=false&go_back=' + isGoBack, {responseType: 'blob'}); } else if (type === 'zip') { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.csv.session&page_download=false&go_back=' + isGoBack, {responseType: 'blob'}); } else { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_download=false&go_back=' + isGoBack, {responseType: 'blob'}); } } downloadSinglePageReport(reportId: string, type: string, isGoBack: string): Observable { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_download=true&go_back=' + isGoBack, {responseType: 'blob'}); } getDashboardReportFormFields(reportId: string): Observable { return this._http.get(environment.baseUrl + 'raptor/dashboard/run/' + reportId); } runDashboardReport(reportId: string, queryString: string) { return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master=' + reportId + queryString + '&refresh=Y&display_content=Y&r_page=0', {responseType: 'text'}); } downloadDashboardReportExcel(reportId: string): Observable { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session', {responseType: 'blob'}); } handleError(error) { let errorMessage = ''; if (error.error instanceof ErrorEvent) { // client-side error errorMessage = `Error: ${error.error.message}`; } else { // server-side error errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; } window.alert(errorMessage); return throwError(errorMessage); } }