Extract filtering into controller

This commit is contained in:
Rohan Mitchell
2015-07-02 16:06:35 +10:00
parent 7fd4815904
commit eba0a12d29
3 changed files with 16 additions and 4 deletions

View File

@@ -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)

View File

@@ -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"

View File

@@ -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}}"}