mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Tests for the taxon filtering
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
Darkswarm.directive "shippingTypeSelector", ->
|
||||
restrict: 'E'
|
||||
templateUrl: 'shipping_type_selector.html'
|
||||
link: (scope, elem, attr)->
|
||||
scope.shippingTypes =
|
||||
pickup: false
|
||||
delivery: false
|
||||
@@ -1,6 +1,8 @@
|
||||
Darkswarm.directive "taxonSelector", (TaxonSelector) ->
|
||||
restrict: 'E'
|
||||
scope: {}
|
||||
scope:
|
||||
enterprises: "="
|
||||
templateUrl: "taxon_selector.html"
|
||||
link: (scope, elem, attr)->
|
||||
scope.TaxonSelector = TaxonSelector
|
||||
TaxonSelector.collectTaxons scope.enterprises
|
||||
|
||||
@@ -3,10 +3,9 @@ Darkswarm.filter 'taxons', (Matcher)->
|
||||
(objects, ids) ->
|
||||
objects ||= []
|
||||
ids ?= []
|
||||
console.log ids
|
||||
if ids.length == 0
|
||||
objects
|
||||
else
|
||||
objects.filter (obj)->
|
||||
obj.primary_taxon?.id in ids || obj.taxons.some (taxon)->
|
||||
obj.primary_taxon?.id in ids || (obj.taxons.concat obj.supplied_taxons).some (taxon)->
|
||||
taxon.id in ids
|
||||
|
||||
@@ -18,3 +18,4 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer)
|
||||
dereferenceTaxons: ->
|
||||
for enterprise in @enterprises
|
||||
Dereferencer.dereference enterprise.taxons, Taxons.taxons_by_id
|
||||
Dereferencer.dereference enterprise.supplied_taxons, Taxons.taxons_by_id
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
Darkswarm.factory 'TaxonSelector', ->
|
||||
new class TaxonSelector
|
||||
selectors: []
|
||||
# Collect all taxons on the supplied enterprises
|
||||
collectTaxons: (enterprises)->
|
||||
taxons = {}
|
||||
for enterprise in enterprises
|
||||
for taxon in (enterprise.taxons.concat enterprise.supplied_taxons)
|
||||
taxons[taxon.id] = taxon
|
||||
for id, taxon of taxons
|
||||
@selectors.push
|
||||
active: false
|
||||
taxon: taxon
|
||||
|
||||
active: ->
|
||||
@selectors.filter (selector)->
|
||||
selector.active
|
||||
.map (selector)->
|
||||
selector.taxon.id
|
||||
@@ -1,14 +0,0 @@
|
||||
Darkswarm.factory 'TaxonSelector', (Taxons)->
|
||||
new class TaxonSelector
|
||||
selectors: []
|
||||
constructor: ->
|
||||
for taxon in Taxons.taxons
|
||||
@selectors.push
|
||||
active: false
|
||||
taxon: taxon
|
||||
|
||||
active: ->
|
||||
@selectors.filter (selector)->
|
||||
selector.active
|
||||
.map (selector)->
|
||||
selector.taxon.id
|
||||
@@ -0,0 +1,7 @@
|
||||
%ul.small-block-grid-4
|
||||
%li{"ng-class" => "{active: shippingTypes['delivery']}"}
|
||||
%a{"ng-click" => "shippingTypes['delivery'] = !shippingTypes['delivery']"}
|
||||
Delivery
|
||||
%li{"ng-class" => "{active: shippingTypes['pickup']}"}
|
||||
%a{"ng-click" => "shippingTypes['pickup'] = !shippingTypes['pickup']"}
|
||||
Pickup
|
||||
Reference in New Issue
Block a user