From 744beaa26aeb5c1aed8544a9a44d5e2c110f55af Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 2 Jul 2015 14:22:51 +1000 Subject: [PATCH] Perform shops search by proximity instead of plain string match --- .../controllers/enterprises_controller.js.coffee | 11 +++++++---- .../darkswarm/services/enterprises.js.coffee | 7 ++++--- app/assets/javascripts/shared/ng-tags-input.min.js | 0 app/views/home/_hubs.html.haml | 2 +- app/views/home/_skinny.html.haml | 4 ++-- app/views/layouts/darkswarm.html.haml | 2 +- .../shared/components/_enterprise_search.html.haml | 2 +- 7 files changed, 16 insertions(+), 12 deletions(-) mode change 100755 => 100644 app/assets/javascripts/shared/ng-tags-input.min.js diff --git a/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee index 1e43c17465..a23d4b5517 100644 --- a/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee @@ -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) -> diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 4a306f807e..daf121ed5a 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -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 diff --git a/app/assets/javascripts/shared/ng-tags-input.min.js b/app/assets/javascripts/shared/ng-tags-input.min.js old mode 100755 new mode 100644 diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index fd30050b90..d0d5aa15f2 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -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}}"} diff --git a/app/views/home/_skinny.html.haml b/app/views/home/_skinny.html.haml index c69e4beaaa..ded0fcec6d 100644 --- a/app/views/home/_skinny.html.haml +++ b/app/views/home/_skinny.html.haml @@ -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 - diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 0e2d1fa0f6..33a3d6148a 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -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" diff --git a/app/views/shared/components/_enterprise_search.html.haml b/app/views/shared/components/_enterprise_search.html.haml index 62dcec3ea6..4bb7ca446b 100644 --- a/app/views/shared/components/_enterprise_search.html.haml +++ b/app/views/shared/components/_enterprise_search.html.haml @@ -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}