import { TaxonomyServiceInterface } from '@vendasta/taxonomy-service'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { TAXONOMY_OPTIONS } from './taxonomy.data'; import { TaxonomyOption } from '../../src/services/taxonomy-service/interfaces'; @Injectable() export class TaxonomyService implements TaxonomyServiceInterface { getTaxonomyIds(): Observable { return Observable.of(TAXONOMY_OPTIONS.map(category => this.buildOption(category))); } buildOption(category: any) { let fullNameParts = []; let idParts = category.id.split(':'); if (idParts.length > 1) { // Work through all the sub-ids (ie. recreation:diving:deepsea would get recreation and recreation:diving) for (let i = 0; i < idParts.length - 1; i++) { let partOpt = TAXONOMY_OPTIONS.find(opt => opt.id === idParts.slice(0, i + 1).join(':')); fullNameParts.push(partOpt.name); } } fullNameParts.push(category.name); return { name: fullNameParts.join(' > '), id: category.id }; } }