mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-22 00:57:26 +00:00
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:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user