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 { ILinkedStaff } from '../core/ILinkedStaff'; import { IFilterClass } from '../core/IFilterclass'; import { Body } from '@angular/http/src/body'; import { ICompanyDetails } from '../core/ICompanyDetails'; import { ClientDetails } from '../core/IClientDetails'; import { IDocumentTypes } from '../core/IDocumentTypes'; import { IFilterType } from '../core/IFilterType'; import { IFilterKey } from '../core/IFilterKey'; import { IJobPlanSummary } from '../core/IJobPlanSummary'; @Injectable({ providedIn: 'root' }) export class DashboardServicesService { private GetAllClients = global.serverBase + 'Dashboard/GetClientListByRecord'; private GetAllLinkedStaff = global.serverBase + 'Dashboard/GetLinkedStaffs'; private GetStatus = global.serverBase + 'Dashboard/GetStatus'; private FilterByLinkStaf = global.serverBase + 'Dashboard/GetClientListByFilterRecord'; private SearchClient = global.serverBase + 'Dashboard/GetClientListBySearch'; private GetAllCountriesUrl = global.serverBase + 'JobPlan/GetAllCountries'; private GetAllStatesUrl = global.serverBase + 'JobPlan/GetAllStates'; private InsertNewClientUrl = global.serverBase + 'JobPlan/SaveClient'; private GetAllClientsByStaffId = global.serverBase + 'Dashboard/GetClientList'; private GetAllDocumentTypesUrl = global.serverBase + 'Dashboard/GetDocumentTypes'; private getFilterTypesUrl = global.serverBase + 'Dashboard/GetFilterTypes'; private getFilterValuesUrl = global.serverBase + 'Dashboard/GetFilterValues'; private GetAllFilterClientLists = global.serverBase + 'Dashboard/GetAllFilterClientLists'; private GetTotalJobPlanStatusUrl = global.serverBase + 'Dashboard/GetTotalJobPlanStatus'; private CopyJobPlanUrl = global.serverBase + 'Dashboard/GetCopyJobPlan'; linkedStaffs: ILinkedStaff[]; filterClientDetails: IFilterClass[]; constructor(private http: Http) { } getAllCountries() { return this.http.get(this.GetAllCountriesUrl) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } getAllStates(countryID: number) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('countryID', countryID.toString()); const body = urlSearchParams.toString(); return this.http.get(this.GetAllStatesUrl, { params: body }) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } insertNewClientDetails(companyDetails: ICompanyDetails) { return this.http.post(this.InsertNewClientUrl, companyDetails) .map((response: Response) => response.json() as boolean) .catch(this.handleError); } getAllClientsByStaffId(staffId: number) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('staffId', staffId.toString()); const body = urlSearchParams.toString(); return this.http.get(this.GetAllClientsByStaffId, { params: body }) .map((response: Response) => response.json() as ClientDetails) .catch(this.handleError); } getAllClients(staffId: number, recordCount: number, currentPage: number, companyID: number) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('staffId', staffId.toString()); urlSearchParams.append('recordCount', recordCount.toString()); urlSearchParams.append('currentPage', currentPage.toString()); urlSearchParams.append('companyID', companyID.toString()); const body = urlSearchParams.toString(); return this.http.get(this.GetAllClients, { params: body }) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } filterByLinkStaf(staffId, recordCount, currentPage, status, linkedStaffArray) { this.filterClientDetails = [{ LoginStaffId: staffId, RecordCount: recordCount, CurrentPage: currentPage, Status: status, LinkedStaffsList: linkedStaffArray }]; return this.http.post(this.FilterByLinkStaf, this.filterClientDetails[0]) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } getAllLinkedStaff() { return this.http.get(this.GetAllLinkedStaff) .map((response: Response) => response.json() as ILinkedStaff[]) .catch(this.handleError); } getStatus() { return this.http.get(this.GetStatus) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } searchClient(staffId, search, recordCount, currentPage) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('staffId', staffId.toString()); urlSearchParams.append('search', search.toString()); urlSearchParams.append('recordCount', recordCount.toString()); urlSearchParams.append('currentPage', currentPage.toString()); const body = urlSearchParams.toString(); return this.http.get(this.SearchClient, { params: body }) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } private handleError(error): Observable { const message = error.statusText || 'Server error'; return throwError(error); } // Get All Document Types GetAllDocumentTypes() { return this.http.get(this.GetAllDocumentTypesUrl) .map((response: Response) => response.json() as IDocumentTypes[]) .catch(this.handleError); } getFilterTypes(section: string, CompanyId: number): Observable { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('actionType', section.toString()); urlSearchParams.append('CompanyId', CompanyId.toString()); const body = urlSearchParams.toString(); return this.http.get(this.getFilterTypesUrl, { params: body }) .map((response: Response) => response.json() as IFilterType[]) .catch(this.handleError); } // Get Filter Value GetFilterValues(filterType: string) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('filterType', filterType.toString()); const body = urlSearchParams.toString(); return this.http.get(this.getFilterValuesUrl, { params: body }) .map((response: Response) => response.json() as IFilterType[]) .catch(this.handleError); } // Get Filter Client Recoreds getAllFilterClientLists({ staffId, recordCount, currentPage, filterKeys }: { staffId: any; recordCount: number; currentPage: number; filterKeys: IFilterKey[]; }): Observable { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('staffId', staffId.toString()); urlSearchParams.append('recordCount', recordCount.toString()); urlSearchParams.append('currentPage', currentPage.toString()); const body = urlSearchParams.toString(); return this.http.post(this.GetAllFilterClientLists, filterKeys, { params: body }) .map((response: Response) => response.json() as ClientDetails[]) .catch(this.handleError); } // Total job plan summary GetTotalJobPlanStatus(companyID: number, loggedUserId: number) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('companyID', companyID.toString()); urlSearchParams.append('loggedUserId', loggedUserId.toString()); const body = urlSearchParams.toString(); return this.http.get(this.GetTotalJobPlanStatusUrl, { params: body }) .map((response: Response) => response.json() as IJobPlanSummary[]) .catch(this.handleError); } // CopyJobPlan CopyJobPlan(companyID: number, jobPlanId: number, clientId: number, status: string) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('companyID', companyID.toString()); urlSearchParams.append('jobPlanId', jobPlanId.toString()); urlSearchParams.append('clientId', clientId.toString()); urlSearchParams.append('status', status.toString()); const body = urlSearchParams.toString(); return this.http.get(this.CopyJobPlanUrl, { params: body }) .map((response: Response) => response.json()) .catch(this.handleError); } }