mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-07 07:36:58 +00:00
Search and match through name + city and state_name
- Rename enterpriseMatchesNameQueryFilter as well to enterpriseMatchesQueryFilter - Update tests as well
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
angular.module('Darkswarm').controller "EnterprisesCtrl", ($scope, $rootScope, $timeout, $location, Enterprises, Search, $document, HashNavigation, FilterSelectorsService, EnterpriseModal, enterpriseMatchesNameQueryFilter, distanceWithinKmFilter) ->
|
||||
angular.module('Darkswarm').controller "EnterprisesCtrl", ($scope, $rootScope, $timeout, $location, Enterprises, Search, $document, HashNavigation, FilterSelectorsService, EnterpriseModal, enterpriseMatchesQueryFilter, distanceWithinKmFilter) ->
|
||||
$scope.Enterprises = Enterprises
|
||||
$scope.producers_to_filter = Enterprises.producers
|
||||
$scope.filterSelectors = FilterSelectorsService.createSelectors()
|
||||
@@ -55,8 +55,8 @@ angular.module('Darkswarm').controller "EnterprisesCtrl", ($scope, $rootScope, $
|
||||
|
||||
$scope.filterEnterprises = ->
|
||||
es = Enterprises.hubs
|
||||
$scope.nameMatches = enterpriseMatchesNameQueryFilter(es, true)
|
||||
noNameMatches = enterpriseMatchesNameQueryFilter(es, false)
|
||||
$scope.nameMatches = enterpriseMatchesQueryFilter(es, true)
|
||||
noNameMatches = enterpriseMatchesQueryFilter(es, false)
|
||||
$scope.distanceMatches = distanceWithinKmFilter(noNameMatches, 50)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
angular.module('Darkswarm').filter 'enterpriseMatchesNameQuery', ->
|
||||
(enterprises, matches_name_query) ->
|
||||
enterprises.filter (enterprise) ->
|
||||
enterprise.matches_name_query == matches_name_query
|
||||
@@ -0,0 +1,4 @@
|
||||
angular.module('Darkswarm').filter 'enterpriseMatchesQuery', ->
|
||||
(enterprises, matches_query) ->
|
||||
enterprises.filter (enterprise) ->
|
||||
enterprise.matches_query == matches_query
|
||||
@@ -53,8 +53,8 @@ angular.module('Darkswarm').factory 'Enterprises', (enterprises, ShopsResource,
|
||||
|
||||
flagMatching: (query) ->
|
||||
for enterprise in @enterprises
|
||||
enterprise.matches_name_query = if query? && query.length > 0
|
||||
Matcher.match([enterprise.name], query)
|
||||
enterprise.matches_query = if query? && query.length > 0
|
||||
Matcher.match([enterprise.name, enterprise.address?.state_name, enterprise.address?.city], query)
|
||||
else
|
||||
false
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ describe "Enterprises service", ->
|
||||
{id: 6, visible: true, name: 'f', category: "producer_shop", hubs: [{id: 2}]},
|
||||
{id: 7, visible: true, name: 'g', category: "producer", hubs: [{id: 2}]}
|
||||
{id: 8, visible: true, name: 'h', category: "producer", hubs: [{id: 2}], latitude: 76.26, longitude: -42.66 }
|
||||
{id: 9, visible: true, name: 'i', category: "hub", address: {state_name: "state", city: "city"}}
|
||||
]
|
||||
H1: 0
|
||||
beforeEach ->
|
||||
@@ -77,19 +78,22 @@ describe "Enterprises service", ->
|
||||
expect(Enterprises.producers).toContain Enterprises.enterprises[5]
|
||||
expect(Enterprises.producers).toContain Enterprises.enterprises[6]
|
||||
|
||||
describe "flagging enterprises with names matching a query", ->
|
||||
describe "flagging enterprises with names, city or state matching a query", ->
|
||||
it "flags enterprises when a query is provided", ->
|
||||
Enterprises.flagMatching 'c'
|
||||
expect(e.matches_name_query).toBe true for e in enterprises when e.name == 'c'
|
||||
expect(e.matches_name_query).toBe false for e in enterprises when e.name != 'c'
|
||||
expect(e.matches_query).toBe true for e in enterprises when e.name == 'c' || e.address?.city == 'city'
|
||||
expect(e.matches_query).toBe false for e in enterprises when e.name != 'c' && e.address?.city != 'city'
|
||||
Enterprises.flagMatching 'state'
|
||||
expect(e.matches_query).toBe true for e in enterprises when e.address?.state_name == "state"
|
||||
expect(e.matches_query).toBe false for e in enterprises when e.address?.state_name != "state"
|
||||
|
||||
it "clears flags when query is null", ->
|
||||
Enterprises.flagMatching null
|
||||
expect(e.matches_name_query).toBe false for e in enterprises
|
||||
expect(e.matches_query).toBe false for e in enterprises
|
||||
|
||||
it "clears flags when query is blank", ->
|
||||
Enterprises.flagMatching ''
|
||||
expect(e.matches_name_query).toBe false for e in enterprises
|
||||
expect(e.matches_query).toBe false for e in enterprises
|
||||
|
||||
describe "calculating the distance of enterprises from a location", ->
|
||||
describe "when a query is provided", ->
|
||||
|
||||
Reference in New Issue
Block a user