6e44a6981f97b1dc9c8d4dbed06daacf5db485b1
[portal/sdk.git] /
1 import { Injectable } from '@angular/core';
2 import { HttpClient, HttpHeaders } from '@angular/common/http';
3 import { Observable, throwError } from 'rxjs';
4 import { retry, catchError } from 'rxjs/operators';
5 import { environment } from '../../../../../../environments/environment';
6 import { HtmlParser } from '@angular/compiler';
7
8 @Injectable({
9     providedIn: 'root'
10 })
11 export class RunService {
12     finalArr: any;
13     finalResponseArr: any;
14
15     constructor(private _http: HttpClient) {
16
17
18     }
19
20     getReportData(reportId: string): Observable<any> {
21         return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master=' + reportId + '&refresh=Y');
22     }
23
24     getReportDataWithFormFields(queryString: string, reportId: string): Observable<any> {
25         return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master=' + reportId + queryString + '&refresh=Y&display_content=Y&r_page=0');
26     }
27
28     getReportDataWithPageNo(reportId: string, pageNo: string): Observable<any> {
29         if (!pageNo || pageNo === null) {
30             pageNo = '0';
31         }
32         return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master='
33             + reportId + '&refresh=Ydisplay_content=Y&r_page=' + pageNo);
34     }
35
36     getReportDataWithFormFieldsWithPageNo(queryString: string, reportId: string, pageNo: string): Observable<any> {
37         if (!pageNo || pageNo === null) {
38             pageNo = '0';
39         }
40         return this._http.get(environment.baseUrl + 'raptor.htm?action=report.run.container&c_master='
41             + reportId + queryString + '&refresh=Y&display_content=Y&r_page=' + pageNo);
42     }
43
44     getDefinitionPageDetails(IncomingReportId: number): Observable<any> {
45         return this._http.get(environment.baseUrl + 'report/wizard/retrieve_def_tab_wise_data/' + IncomingReportId, { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) });
46     }
47
48     refreshFormFields(reportId: string, queryString: string): Observable<any> {
49         return this._http.get(environment.baseUrl + 'raptor.htm?action=report.formfields.run.container&c_master=' + reportId + queryString);
50     }
51
52     getFormFieldGroupsData(reportId: string): Observable<any> {
53         return this._http.get(environment.baseUrl + 'report/wizard/get_formfield_groups_data/' + reportId);
54     }
55
56     downloadReportExcel(reportId: string): Observable<Blob> {
57         return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_dowload=true', { responseType: 'blob' });
58     }
59
60     downloadReport(reportId: string, type: string): Observable<Blob> {
61         if (type === 'xlsx') {
62             return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_download=false', { responseType: 'blob' });
63         } else if (type === 'pdf') {
64             return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.pdf.session&page_download=false', { responseType: 'blob' });
65         }
66     }
67
68     downloadSinglePageReport(reportId: string, type: string): Observable<Blob> {
69         return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session&page_download=true', { responseType: 'blob' });
70
71     }
72
73
74     getDashboardReportFormFields(reportId: string): Observable<any> {
75         return this._http.get(environment.baseUrl + 'raptor/dashboard/run/' + reportId);
76     }
77
78     runDashboardReport(reportId: string, queryString: string) {
79         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' });
80     }
81
82     downloadDashboardReportExcel(reportId: string): Observable<Blob> {
83         return this._http.get(environment.baseUrl + 'raptor.htm?c_master=' + reportId + '&r_action=report.download.excel.session', { responseType: 'blob' });
84     }
85
86     proceedWithLoad(object: Object) {
87         const headers = new HttpHeaders({
88             'Content-Type': 'application/json'
89         });
90         return this._http.post(environment.baseUrl + 'proceed-with-load', object, { headers });
91     }
92
93     onDeleteFromUploadedReport(object: Object): Observable<any> {
94         const headers = new HttpHeaders({
95             'Content-Type': 'application/json'
96         });
97         return this._http.post(environment.baseUrl + "delete-upload", object, { headers });
98     }
99     onResubmitUnplannedLTEUploadedReport(object: Object): Observable<any> {
100         const headers = new HttpHeaders({
101             'Content-Type': 'application/json'
102         });
103         return this._http.post(environment.baseUrl + "resubmit-unplanned-lte-upload", object, { headers })
104         .pipe(retry(1),
105          catchError(this.handleError)
106         );
107     }
108
109     onAutomaticUploadedReport(): Observable<any> {
110         const headers = new HttpHeaders({
111             'Content-Type': 'application/json'
112         });
113         return this._http.post(environment.baseUrl + 'automated-upload?'+'parentReportId=25633'+'&templateName=SUPER_E911_4G',{headers})
114         .pipe(
115             retry(1),
116             catchError(this.handleError)
117         );
118
119     }
120     
121     onSubmitApproved(object:Object):Observable<any>{
122         const headers = new HttpHeaders({
123             'Content-Type': 'application/json'
124         });    
125
126         return this._http.post(environment.baseUrl + 'submit-approval',object,{headers})
127         .pipe(
128             retry(1),
129             catchError(this.handleError)
130         );
131     }
132     
133     handleError(error) {
134         let errorMessage = '';
135         if (error.error instanceof ErrorEvent) {
136             // client-side error
137             errorMessage = `Error: ${error.error.message}`;
138         } else {
139             // server-side error
140             errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
141         }
142         window.alert(errorMessage);
143         return throwError(errorMessage);
144     }
145 }