import { Injectable } from '@angular/core'; import { Http, RequestOptions, Response } from '@angular/http'; import { Observable, throwError } from 'rxjs'; import * as global from '../core/Common'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; import 'rxjs/add/observable/throw'; import { ClientDetails } from '../core/IClientDetails'; import { IMessages } from '../core/IMessages'; import { IDocuments } from '../core/IDocuments'; import { IDocumentStatus } from '../core/IDocumentStatus'; import { IDocumentTypes } from '../core/IDocumentTypes'; import { IMessageStatus } from '../core/IMessageStatus'; import { IPhases } from '../core/Questionnaire/IPhases'; @Injectable({ providedIn: 'root' }) export class ActivityServicesService { // API end points 1111 private SaveLocationStructure = global.serverBase + 'Activity/SaveSubjects'; private GetClientUrl = global.serverBase + 'Activity/GetClientDetailsById'; private GetJobPlansByLocation = global.serverBase + 'Activity/GetJobPlanLocationId'; private GetlocationsByLocation = global.serverBase + 'Activity/GetLocationsById'; private InsertMessageUrl = global.serverBase + 'Activity/InsertMessage'; private GetAllMessageUrl = global.serverBase + 'Activity/GetAllMessage'; private InsertDocumentUrl = global.serverBase + 'Activity/InsertDocument'; private GetMessages = global.serverBase + 'Activity/GetAllMessage'; private GetDocumentStatusUrl = global.serverBase + 'Activity/GetDocumentStatus'; private GetAllDocumentUrl = global.serverBase + 'Activity/GetAllDocuments'; private GetAllDocumentTypeUrl = global.serverBase + 'Activity/GetAllDocumentTypes'; private GetFilteredDocumentsUrl = global.serverBase + 'Activity/GetFilteredDocuments'; private UploadFileUrl = global.serverBase + 'Activity/UploadFile'; private GetAllMessageStatusUrl = global.serverBase + 'Activity/GetAllMessageStatus'; private GetFilteredMessagesUrl = global.serverBase + 'Activity/GetFilteredMessages'; private GetAllPhasesUrl = global.serverBase + 'Activity/GetAllPhasesByJobPlanId'; private GetAllPhasesBySearchUrl = global.serverBase + 'Activity/GetAllPhasesBySearch'; constructor(private http: Http) { } // Get Client details by Id GetClientDetailsById(clientId: string, staffId: string, companyID:any) { const myparams = new URLSearchParams(); myparams.append('clientId', clientId.toString()); myparams.append('staffId', staffId.toString()); myparams.append('companyID', companyID.toString()); // tslint:disable-next-line: deprecation const options = myparams.toString(); return this.http.get(this.GetClientUrl, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // ------------ Common methods ------------------// // The function of handling the error saveLocationStructure(location) { return this.http.post(this.SaveLocationStructure, location) .map((response: Response) => response.json() as boolean) .catch(this.handleError); } getJobPlansByLocation(clientId: number, locationId: number, typeId: number) { const myparams = new URLSearchParams(); myparams.append('clientId', clientId.toString()); myparams.append('locationId', locationId.toString()); myparams.append('typeId', typeId.toString()); // tslint:disable-next-line: deprecation const options = myparams.toString(); return this.http.get(this.GetJobPlansByLocation, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } getlocationsByLocation(clientId: number, locationId: number, typeId: number) { const myparams = new URLSearchParams(); myparams.append('clientId', clientId.toString()); myparams.append('locationId', locationId.toString()); myparams.append('typeId', typeId.toString()); // tslint:disable-next-line: deprecation const options = myparams.toString(); return this.http.get(this.GetlocationsByLocation, { params: options }) // tslint:disable-next-line:no-angle-bracket-type-assertion .map((response: Response) => response.json()) .catch(this.handleError); } // Get all messages GetAllMessage(JobplanID: number, parentType: string) { const myparams = new URLSearchParams(); myparams.append('JobplanID', JobplanID.toString()); myparams.append('parentType', parentType.toString()); // tslint:disable-next-line: deprecation const options = myparams.toString(); return this.http.get(this.GetAllMessageUrl, { params: options }) .map((response: Response) => response.json() as IMessages[]) .catch(this.handleError); } // Inserting the message InsertMessage(messages: IMessages) { return this.http.post(this.InsertMessageUrl, messages) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } // Insert the documents InsertDocument(frmData: any, JobPlanId: number, DocumentsTypeId: number, StaffId: number, Name: string, Description: string) { const myparams = new URLSearchParams(); myparams.append('jobPlanId', JobPlanId.toString()); myparams.append('documentsTypeId', DocumentsTypeId.toString()); myparams.append('staffId', StaffId.toString()); myparams.append('name', Name.toString()); myparams.append('description', Description.toString()); const options = myparams.toString(); return this.http.post(this.InsertDocumentUrl, frmData, { params: options }) .map((response: Response) => response.json() as IDocuments[]) .catch(this.handleError); } // Get All Document Types GetAllDocumentStatus() { return this.http.get(this.GetDocumentStatusUrl) .map((response: Response) => response.json() as IDocumentStatus[]) .catch(this.handleError); } // Get All Documents GetAllDocuments(JobPlanId: number) { const myparams = new URLSearchParams(); myparams.append('jobPlanId', JobPlanId.toString()); const options = myparams.toString(); return this.http.get(this.GetAllDocumentUrl, { params: options }) .map((response: Response) => response.json() as IDocumentStatus[]) .catch(this.handleError); } // Get All Documents Types GetAllDocumentTypes() { return this.http.get(this.GetAllDocumentTypeUrl) .map((response: Response) => response.json() as IDocumentTypes[]) .catch(this.handleError); } // Filter records GetFilteredDocuments(type: string, value: any) { const myparams = new URLSearchParams(); myparams.append('type', type.toString()); myparams.append('value', value.toString()); const options = myparams.toString(); return this.http.get(this.GetFilteredDocumentsUrl, { params: options }) .map((response: Response) => response.json() as IDocuments[]) .catch(this.handleError); } // Upload attachment UploadFile(file: FormData) { return this.http.post(this.UploadFileUrl, file) .map((response: Response) => response.json()) .catch(this.handleError); } // Get All Message Stats GetAllMessageStatus() { return this.http.get(this.GetAllMessageStatusUrl) .map((response: Response) => response.json() as IMessageStatus[]) .catch(this.handleError); } // Filter by message status GetFilteredMessages(jobPlanId: number, value: string, filter: string, messageType: string) { const myparams = new URLSearchParams(); myparams.append('jobPlanId', jobPlanId.toString()); myparams.append('value', value.toString()); myparams.append('filter', filter.toString()); myparams.append('messageType', messageType.toString()); const options = myparams.toString(); return this.http.get(this.GetFilteredMessagesUrl, { params: options }) .map((response: Response) => response.json() as IMessages[]) .catch(this.handleError); } // Get All Phases GetAllPhases(jobPlanId: number) { const myparams = new URLSearchParams(); myparams.append('jobPlanId', jobPlanId.toString()); const options = myparams.toString(); return this.http.get(this.GetAllPhasesUrl, { params: options }) .map((response: Response) => response.json() as IPhases[]) .catch(this.handleError); } // Search Phase GetAllPhasesBySearch(jobPlanId: number, serachWord: string) { const myparams = new URLSearchParams(); myparams.append('jobPlanId', jobPlanId.toString()); myparams.append('serach', serachWord.toString()); const options = myparams.toString(); return this.http.get(this.GetAllPhasesBySearchUrl, { params: options }) .map((response: Response) => response.json() as IPhases[]) .catch(this.handleError); } private handleError(error): Observable { const message = error.statusText || 'Server error'; return throwError(error); } }