import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable, throwError } from 'rxjs'; import { retry, catchError } from 'rxjs/operators'; import { environment } from '../../../../../../environments/environment'; import { HtmlParser } from '@angular/compiler'; @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): 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'); } 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): Observable { if (type === 'xlsx') { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_download=false', { 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', { responseType: 'blob' }); } } downloadSinglePageReport(reportId: string, type: string): Observable { return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_download=true', { 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' }); } proceedWithLoad(object: Object) { const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); return this._http.post(environment.baseUrl + 'proceed-with-load', object, { headers }); } onDeleteFromUploadedReport(object: Object): Observable { const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); return this._http.post(environment.baseUrl + "delete-upload", object, { headers }); } onResubmitUnplannedLTEUploadedReport(object: Object): Observable { const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); return this._http.post(environment.baseUrl + "resubmit-unplanned-lte-upload", object, { headers }) .pipe(retry(1), catchError(this.handleError) ); } onAutomaticUploadedReport(): Observable { const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); return this._http.post(environment.baseUrl + 'automated-upload?'+'parentReportId=25633'+'&templateName=SUPER_E911_4G',{headers}) .pipe( retry(1), catchError(this.handleError) ); } onSubmitApproved(object:Object):Observable{ const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); return this._http.post(environment.baseUrl + 'submit-approval',object,{headers}) .pipe( retry(1), catchError(this.handleError) ); } 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); } }