File

app/dxa/dxa-entity/views/dist-office-search-views/dist-office-search.service.ts

Index

Properties
Methods

Constructor

constructor(httpClient: HttpClient, publicationService: PublicationService)
Parameters :
Name Type Optional
httpClient HttpClient No
publicationService PublicationService No

Methods

Public distributorTaxonomyService
distributorTaxonomyService(value)
Parameters :
Name Optional
value No
Returns : Observable<any>
Public getDistOffices
getDistOffices(boundingBox: BoundingBox, type: string, selectedDropdownList: any)
Parameters :
Name Type Optional
boundingBox BoundingBox No
type string No
selectedDropdownList any No
Returns : Observable<any>
getTaxonomy
getTaxonomy(list, productCategoryDropdownList, distributorCategoryDropdownList)

Resolve category IDs to display names

Parameters :
Name Optional
list No
productCategoryDropdownList No
distributorCategoryDropdownList No
Returns : void
openList
openList(clickedMap: MapConfig)
Parameters :
Name Type Optional
clickedMap MapConfig No
Returns : void

Properties

Private clickSource
Default value : new BehaviorSubject<MapConfig>({ startLat: 0, startLng: 0, lat: 0, lng: 0, startZoom: 0, maxZoom: 0, appType: 'Distributor Search' })
currentDistributorOnMap
Default value : this.clickSource.asObservable()
Private solrUrl
Type : string
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { BoundingBox, MapConfig } from './dist-office-search.model';
import { Observable, BehaviorSubject } from 'rxjs';
import { AppConfig } from '../../../../app.config';
import { PublicationService } from 'src/app/core/services/publication-service/publication.service';


@Injectable({
	providedIn: 'root'
})
export class DistOfficeSearchService {

	private solrUrl: string;
	private clickSource = new BehaviorSubject<MapConfig>({
		startLat: 0,
		startLng: 0,
		lat: 0,
		lng: 0,
		startZoom: 0,
		maxZoom: 0,
		appType: 'Distributor Search'
	});
	currentDistributorOnMap = this.clickSource.asObservable();

	constructor(private httpClient: HttpClient, private publicationService: PublicationService) {
		this.solrUrl = AppConfig.settings.addressServiceConfig.config.url;
	}

	public getDistOffices(boundingBox: BoundingBox, type: string, selectedDropdownList: any): Observable<any> {
		let requestUrl: string;
		requestUrl = (type === 'distributors') ? `${this.solrUrl}location?bounding_box=${JSON.stringify(boundingBox)}` + selectedDropdownList :
			`${this.solrUrl}location?bounding_box=${JSON.stringify(boundingBox)}&offices=true`;
		return this.httpClient.get(requestUrl);
	}

	public distributorTaxonomyService(value): Observable<any> {
		const pubPath = this.publicationService.getPublicationPath();
		const requestUrl = `content${pubPath}/api/category/${value}%20Categories`;
		return this.httpClient.get(requestUrl);
	}

	openList(clickedMap: MapConfig): void {
		this.clickSource.next(clickedMap);
	}

	/** Resolve category IDs to display names */
	getTaxonomy(list, productCategoryDropdownList, distributorCategoryDropdownList): void {
		list.forEach(element => {
			let categoryList = element.product_category ? element.product_category.split(',') : [];

				categoryList = categoryList.map(cat => {
					const match = productCategoryDropdownList.find(el => {
						if (el.Value === cat) { return el; }
					});

					if (match) { return match.Key; }
				}).filter(cat => cat);

				element.product_category = categoryList.join(', ');

			let distList = element.distributor_category ? element.distributor_category.split(',') : [];
				distList = distList.map(dist => {
					const match = distributorCategoryDropdownList.find(el => {
						if (el.Value === dist) { return el; }
					});

					if (match) { return match.Key; }
				}).filter(dist => dist);

			element.distributor_category = distList.join(', ');
		});
	}
}

result-matching ""

    No results matching ""