Perform shops search by proximity instead of plain string match

This commit is contained in:
Rohan Mitchell
2015-07-02 14:22:51 +10:00
parent d0d9e9e367
commit 744beaa26a
7 changed files with 16 additions and 12 deletions

View File

@@ -1,16 +1,19 @@
Darkswarm.controller "EnterprisesCtrl", ($scope, Enterprises, Search, $document, $rootScope, HashNavigation, FilterSelectorsService, EnterpriseModal) ->
$scope.Enterprises = Enterprises
$scope.totalActive = FilterSelectorsService.totalActive
$scope.clearAll = FilterSelectorsService.clearAll
$scope.filterText = FilterSelectorsService.filterText
$scope.FilterSelectorsService = FilterSelectorsService
$scope.totalActive = FilterSelectorsService.totalActive
$scope.clearAll = FilterSelectorsService.clearAll
$scope.filterText = FilterSelectorsService.filterText
$scope.FilterSelectorsService = FilterSelectorsService
$scope.query = Search.search()
$scope.openModal = EnterpriseModal.open
$scope.activeTaxons = []
$scope.show_profiles = false
$scope.filtersActive = false
$scope.$watch "query", (query)->
Enterprises.flagMatching query
Enterprises.updateDistance query
Search.search query
$rootScope.$on "$locationChangeSuccess", (newRoute, oldRoute) ->

View File

@@ -1,4 +1,4 @@
Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, visibleFilter, Matcher, Geo)->
Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, visibleFilter, Matcher, Geo, $rootScope)->
new class Enterprises
enterprises_by_id: {}
constructor: ->
@@ -51,8 +51,9 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer,
@resetDistance()
setDistanceFrom: (location) ->
for enterprise in @enterprises
enterprise.distance = Geo.distanceBetween enterprise, location
$rootScope.$apply =>
for enterprise in @enterprises
enterprise.distance = Geo.distanceBetween enterprise, location
resetDistance: ->
enterprise.distance = null for enterprise in @enterprises

0
app/assets/javascripts/shared/ng-tags-input.min.js vendored Executable file → Normal file
View File

View File

@@ -11,7 +11,7 @@
.row{bindonce: true}
.small-12.columns
.active_table
%hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | visible | searchEnterprises:query | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+orders_close_at'])",
%hub.active_table_node.row.animate-repeat{"ng-repeat" => "hub in filteredEnterprises = (Enterprises.hubs | visible | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '-matches_name_query', '+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}}"}

View File

@@ -9,6 +9,7 @@
%span.margin-top{"bo-text" => "hub.address.city"}
.columns.small-2.medium-1.large-1
%span.margin-top{"bo-bind" => "hub.address.state_name | uppercase"}
%span.margin-top{"ng-if" => "hub.distance != null"} ({{ hub.distance / 1000 | number:0 }} km)
.columns.small-4.medium-3.large-3.text-right{"bo-if" => "hub.active"}
%a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
@@ -26,7 +27,7 @@
%span.margin-top{ bo: { if: "!current()" } } Orders closed
.columns.small-2.medium-1.large-1.text-right
%span.margin-top
%span.margin-top
%i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"}
.row.active_table_row{"ng-if" => "!hub.is_distributor", "ng-class" => "closed"}
@@ -43,4 +44,3 @@
.columns.small-6.medium-3.large-4.text-right
%span.margin-top{ bo: { if: "!current()" } }
%em Profile only

View File

@@ -11,7 +11,7 @@
%link{href: "https://fonts.googleapis.com/css?family=Roboto:400,300italic,400italic,300,700,700italic|Oswald:300,400,700", rel: "stylesheet", type: "text/css"}
= yield :scripts
%script{src: "//maps.googleapis.com/maps/api/js?libraries=places&sensor=false"}
%script{src: "//maps.googleapis.com/maps/api/js?libraries=places,geometry&sensor=false"}
= split_stylesheet_link_tag "darkswarm/all"
= javascript_include_tag "darkswarm/all"

View File

@@ -3,5 +3,5 @@
%input{type: :text,
"ng-model" => "query",
placeholder: t('search_by_name'),
"ng-debounce" => "150",
"ng-debounce" => "500",
"ofn-disable-enter" => true}