mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract filtering into controller
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
Darkswarm.controller "EnterprisesCtrl", ($scope, Enterprises, Search, $document, $rootScope, HashNavigation, FilterSelectorsService, EnterpriseModal) ->
|
||||
Darkswarm.controller "EnterprisesCtrl", ($scope, Enterprises, Search, $document, $rootScope, HashNavigation, FilterSelectorsService, EnterpriseModal, visibleFilter, taxonsFilter, shippingFilter, showHubProfilesFilter, enterpriseMatchesNameQueryFilter) ->
|
||||
$scope.Enterprises = Enterprises
|
||||
$scope.totalActive = FilterSelectorsService.totalActive
|
||||
$scope.clearAll = FilterSelectorsService.clearAll
|
||||
@@ -14,7 +14,19 @@ Darkswarm.controller "EnterprisesCtrl", ($scope, Enterprises, Search, $document,
|
||||
$scope.$watch "query", (query)->
|
||||
Enterprises.evaluateQuery query
|
||||
Search.search query
|
||||
$scope.filterEnterprises()
|
||||
|
||||
|
||||
$rootScope.$on "$locationChangeSuccess", (newRoute, oldRoute) ->
|
||||
if HashNavigation.active "hubs"
|
||||
$document.scrollTo $("#hubs"), 100, 200
|
||||
|
||||
|
||||
$scope.filterEnterprises = ->
|
||||
es = Enterprises.hubs
|
||||
es = visibleFilter(es)
|
||||
es = taxonsFilter(es, $scope.activeTaxons)
|
||||
es = shippingFilter(es, $scope.shippingTypes)
|
||||
es = showHubProfilesFilter(es)
|
||||
$scope.nameMatches = enterpriseMatchesNameQueryFilter(es, true)
|
||||
$scope.distanceMatches = enterpriseMatchesNameQueryFilter(es, false)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
.row{bindonce: true}
|
||||
.small-12.columns
|
||||
%h2 Did you mean?
|
||||
= render "home/hubs_table", filters: "visible | enterpriseMatchesNameQuery:true | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles", order_by: "['-active', '+distance', '+orders_close_at']"
|
||||
= render "home/hubs_table", enterprises: "nameMatches"
|
||||
|
||||
%h2 Closest to {{ query }}...
|
||||
= render "home/hubs_table", filters: "visible | enterpriseMatchesNameQuery:false | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles", order_by: "['-active', '+distance', '+orders_close_at']"
|
||||
= render "home/hubs_table", enterprises: "distanceMatches"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.active_table
|
||||
%hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | #{filters} | orderBy:#{order_by})",
|
||||
%hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (#{enterprises} | orderBy:['-active', '+distance', '+orders_close_at'])",
|
||||
"ng-class" => "{'is_profile' : hub.category == 'hub_profile', 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}",
|
||||
"ng-controller" => "HubNodeCtrl",
|
||||
id: "{{hub.hash}}"}
|
||||
|
||||
Reference in New Issue
Block a user