import { Injectable } from '@angular/core' ; import { SearchBuilderGroupQuery } from '../interfaces/group-query.interface' ; import { SearchBuilderFocusService } from '../search-builder-focus.service' ; import { SearchBuilderService } from '../search-builder.service' ; @ Injectable ( ) export class SearchBuilderGroupService { private _id : string ; constructor ( private _searchBuilderService , private _searchBuilderFocusService ) { } /**
     * Initialise the group by defining an id
     */ init ( id ) { this . _id = id ; if ( ! this . _searchBuilderService . query [ this . _id ] ) { this . _searchBuilderService . query [ this . _id ] = [ ] ; setTimeout ( ( ) => this . _searchBuilderService . queryHasChanged ( ) ) ; } } /**
     * Remove a field from the search builder query and return focus to the previous field.
     */ removeAtIndex ( index ) { const query = this . getQuery ( ) ; query . splice ( index , 1 ) ; this . _searchBuilderFocusService . setFocus ( this . _id , index <= 0 ? 0 : index - 1 ) ; } /**
     * Get the query for this specific search group
     */ getQuery ( ) { return this . _searchBuilderService . query [ this . _id ] ? this . _searchBuilderService . query [ this . _id ] : [ ] ; } }