Take the first name match from the post-filter results to avoid matching off a result the user can't see

This commit is contained in:
Rohan Mitchell
2015-07-09 11:59:50 +10:00
parent 669c9911fe
commit 0ab75fe2ea
5 changed files with 21 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
Darkswarm.controller "EnterprisesCtrl", ($scope, $rootScope, Enterprises, Search, $document, HashNavigation, FilterSelectorsService, EnterpriseModal, enterpriseMatchesNameQueryFilter, distanceWithinKmFilter) ->
Darkswarm.controller "EnterprisesCtrl", ($scope, $rootScope, $timeout, Enterprises, Search, $document, HashNavigation, FilterSelectorsService, EnterpriseModal, enterpriseMatchesNameQueryFilter, distanceWithinKmFilter) ->
$scope.Enterprises = Enterprises
$scope.totalActive = FilterSelectorsService.totalActive
$scope.clearAll = FilterSelectorsService.clearAll
@@ -13,11 +13,15 @@ Darkswarm.controller "EnterprisesCtrl", ($scope, $rootScope, Enterprises, Search
$scope.$watch "query", (query)->
Enterprises.evaluateQuery query
Enterprises.flagMatching query
Search.search query
$rootScope.$broadcast 'enterprisesChanged'
$scope.distanceMatchesShown = false
$timeout ->
Enterprises.calculateDistance query, $scope.nameMatchesFiltered[0]
$rootScope.$broadcast 'enterprisesChanged'
$rootScope.$on "enterprisesChanged", ->
$scope.filterEnterprises()

View File

@@ -28,10 +28,6 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer,
Dereferencer.dereference enterprise.taxons, Taxons.taxons_by_id
Dereferencer.dereference enterprise.supplied_taxons, Taxons.taxons_by_id
evaluateQuery: (query) ->
@flagMatching query
@calculateDistance query
flagMatching: (query) ->
for enterprise in @enterprises
enterprise.matches_name_query = if query? && query.length > 0
@@ -39,15 +35,12 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer,
else
false
firstMatching: ->
(enterprise for enterprise in @enterprises when enterprise.matches_name_query)[0]
calculateDistance: (query) ->
calculateDistance: (query, firstMatching) ->
if query?.length > 0
if @firstMatching()?
@setDistanceFrom @firstMatching()
if firstMatching?
@setDistanceFrom firstMatching
else
@calculateDistanceGeo(query)
@calculateDistanceGeo query
else
@resetDistance()