mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-21 00:47:26 +00:00
Filter products list on shop by active properties
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Darkswarm.controller "ProductsCtrl", ($scope, $rootScope, Products, OrderCycle, FilterSelectorsService, Cart, Taxons) ->
|
||||
Darkswarm.controller "ProductsCtrl", ($scope, $rootScope, Products, OrderCycle, FilterSelectorsService, Cart, Taxons, Properties) ->
|
||||
$scope.Products = Products
|
||||
$scope.Cart = Cart
|
||||
$scope.totalActive = FilterSelectorsService.totalActive
|
||||
@@ -21,11 +21,16 @@ Darkswarm.controller "ProductsCtrl", ($scope, $rootScope, Products, OrderCycle,
|
||||
if code == 13
|
||||
e.preventDefault()
|
||||
|
||||
$scope.appliedTaxonsList = () ->
|
||||
$scope.appliedTaxonsList = ->
|
||||
$scope.activeTaxons.map( (taxon_id) ->
|
||||
Taxons.taxons_by_id[taxon_id].name
|
||||
).join(" & ") if $scope.activeTaxons?
|
||||
|
||||
$scope.appliedPropertiesList = ->
|
||||
$scope.activeProperties.map( (property_id) ->
|
||||
Properties.properties_by_id[property_id].name
|
||||
).join(" & ") if $scope.activeProperties?
|
||||
|
||||
$scope.clearAll = ->
|
||||
$scope.query = ""
|
||||
FilterSelectorsService.clearAll()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
Darkswarm.filter 'properties', ()->
|
||||
# Filter anything that responds to object.properties
|
||||
(objects, ids) ->
|
||||
objects ||= []
|
||||
ids ?= []
|
||||
if ids.length == 0
|
||||
# No properties selected, pass all objects through.
|
||||
objects
|
||||
else
|
||||
objects.filter (obj)->
|
||||
properties = obj.properties
|
||||
# Combine object properties with supplied properties, if they exist.
|
||||
# properties = properties.concat obj.supplied_properties if obj.supplied_properties
|
||||
# Match property array.
|
||||
properties.some (property)->
|
||||
property.id in ids
|
||||
@@ -7,7 +7,7 @@
|
||||
%span
|
||||
+ {{ overFlowSelectors().length }} more
|
||||
%i.ofn-i_052-point-down
|
||||
.f-dropdown.content#show-more
|
||||
.f-dropdown.right.text-left.medium.content#show-more
|
||||
%ul
|
||||
%active-selector{ ng: { repeat: "selector in overFlowSelectors()", hide: "selector.fits" } }
|
||||
%render-svg{path: "{{selector.object.icon}}"}
|
||||
|
||||
Reference in New Issue
Block a user