mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
20 lines
540 B
CoffeeScript
20 lines
540 B
CoffeeScript
angular.module("admin.taxons").factory "Taxons", (taxons, $filter) ->
|
|
new class Taxons
|
|
taxons: taxons
|
|
taxonsByID: {}
|
|
|
|
constructor: ->
|
|
for taxon in @taxons
|
|
@taxonsByID[taxon.id] = taxon
|
|
|
|
# For finding a single Taxon
|
|
findByID: (id) ->
|
|
@taxonsByID[id]
|
|
|
|
# For finding multiple Taxons represented by comma delimited string
|
|
findByIDs: (ids) ->
|
|
@taxonsByID[taxon_id] for taxon_id in ids.split(",") when @taxonsByID[taxon_id]
|
|
|
|
findByTerm: (term) ->
|
|
$filter('filter')(@taxons, term)
|