import { QueryFilter } from "./query-filter.class" ; export class QueryFilters { private _queryFilterMap : any ; constructor ( ) { this . _queryFilterMap = { } ; } public addFilter ( queryFilter ) { this . _queryFilterMap [ queryFilter . filterKey ] = queryFilter ; } public addFilters ( queryFilters ) { for ( let queryFilter of queryFilters ) { this . addFilter ( queryFilter ) ; } } public createNewFilter ( filterKey , filterValue , label ) { let newQuery = new QueryFilter ( filterKey , filterValue , label ) ; this . addFilter ( newQuery ) ; } public removeFilter ( filterKey ) { delete this . _queryFilterMap [ filterKey ] ; } public toggleFilter ( filterKey , filterValue , label ) { if ( filterKey in this . _queryFilterMap ) { this . removeFilter ( filterKey ) ; } else { this . createNewFilter ( filterKey , filterValue , label ) ; } } get queryFilterKeys ( ) : string [ ] { return Object . keys ( this . _queryFilterMap ) ; } get queryFilters ( ) : QueryFilter [ ] { let toReturn = [ ] ; for ( let key of Object . keys ( this . _queryFilterMap ) ) { toReturn . push ( this . _queryFilterMap [ key ] ) ; } return toReturn ; } }