mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Added postcode search that redirect to page with map view.
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -32,6 +32,7 @@ gem 'chili', :github => 'eaterprises/chili'
|
||||
gem 'deface', :github => 'spree/deface'
|
||||
gem 'paperclip'
|
||||
gem 'geocoder'
|
||||
gem 'gmaps4rails'
|
||||
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
|
||||
@@ -264,6 +264,7 @@ GEM
|
||||
formatador (0.2.4)
|
||||
fssm (0.2.10)
|
||||
geocoder (1.1.8)
|
||||
gmaps4rails (1.5.6)
|
||||
haml (3.1.6)
|
||||
highline (1.6.18)
|
||||
hike (1.2.3)
|
||||
@@ -463,6 +464,7 @@ DEPENDENCIES
|
||||
factory_girl_rails
|
||||
faker
|
||||
geocoder
|
||||
gmaps4rails
|
||||
haml
|
||||
jquery-rails
|
||||
letter_opener
|
||||
|
||||
@@ -10,4 +10,4 @@
|
||||
//= require foundation
|
||||
//= require_tree .
|
||||
|
||||
$(function(){ $(document).foundation(); });
|
||||
//$(function(){ $(document).foundation(); });
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
||||
*= require_self
|
||||
*= require ./foundation_and_overrides
|
||||
*= require_tree .
|
||||
*= require ./gmaps4rails
|
||||
*= require_tree .
|
||||
*/
|
||||
11
app/assets/stylesheets/search/enteprise_search.css.scss
Normal file
11
app/assets/stylesheets/search/enteprise_search.css.scss
Normal file
@@ -0,0 +1,11 @@
|
||||
@import "foundation/variables";
|
||||
@import "foundation/components/global";
|
||||
|
||||
.search-result {
|
||||
min-height: emCalc(50);
|
||||
|
||||
.secondary-info {
|
||||
font-size: 0.8em;
|
||||
color: #b7b7b7;
|
||||
}
|
||||
}
|
||||
@@ -87,4 +87,8 @@
|
||||
$adjust: true;
|
||||
|
||||
@include panel($bg, $padding, $adjust);
|
||||
}
|
||||
|
||||
.centered {
|
||||
text-align: center;
|
||||
}
|
||||
@@ -34,7 +34,8 @@ class EnterprisesController < BaseController
|
||||
|
||||
def search
|
||||
suburb = Suburb.find_by_postcode(params[:postcode])
|
||||
@enterpsises = Enterprise.all
|
||||
@enterpsises = Enterprise.find_near(suburb)
|
||||
@enterprises_json = @enterpsises.to_gmaps4rails
|
||||
render :layout => "landing_page"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
class Enterprise < ActiveRecord::Base
|
||||
ENTERPRISE_SEARCH_RADIUS = 100
|
||||
|
||||
acts_as_gmappable :process_geocoding => false
|
||||
|
||||
has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id'
|
||||
has_many :distributed_orders, :class_name => 'Spree::Order', :foreign_key => 'distributor_id'
|
||||
belongs_to :address, :class_name => 'Spree::Address'
|
||||
@@ -7,6 +11,8 @@ class Enterprise < ActiveRecord::Base
|
||||
has_many :enterprise_roles
|
||||
has_many :users, through: :enterprise_roles
|
||||
|
||||
delegate :latitude, :longitude, :city, :state_name, :to => :address
|
||||
|
||||
accepts_nested_attributes_for :address
|
||||
|
||||
validates_presence_of :name
|
||||
@@ -65,8 +71,15 @@ class Enterprise < ActiveRecord::Base
|
||||
count(distinct: true)
|
||||
end
|
||||
|
||||
def self.search_near(suburb)
|
||||
Enterprise.near [suburb.latitude, suburb.longitude]
|
||||
def self.find_near(suburb)
|
||||
enterprises = []
|
||||
|
||||
unless suburb.nil?
|
||||
addresses = Spree::Address.near([suburb.latitude, suburb.longitude], ENTERPRISE_SEARCH_RADIUS, :units => :km).limit(10)
|
||||
enterprises = addresses.collect(&:enterprise)
|
||||
end
|
||||
|
||||
enterprises
|
||||
end
|
||||
|
||||
def has_supplied_products_on_hand?
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
Spree::Address.class_eval do
|
||||
has_one :enterprise
|
||||
|
||||
geocoded_by :full_address
|
||||
after_validation :geocode
|
||||
|
||||
delegate :name, :to => :state, :prefix => true
|
||||
|
||||
def full_address
|
||||
full_address = [address1, address2, zipcode, city, country.name, state.name]
|
||||
filtered_address = full_address.select{ |field| !field.nil? && field != '' }
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
- @enterpsises.each do |enterprise|
|
||||
- if @enterpsises.any?
|
||||
.row.full-width
|
||||
.large-4.columns
|
||||
- @enterpsises.each do |enterprise|
|
||||
.search-result
|
||||
.large-12.columns
|
||||
= enterprise.name
|
||||
%span.secondary-info= "#{enterprise.city}, #{enterprise.state_name}"
|
||||
.large-8.columns
|
||||
= gmaps4rails(@enterprises_json)
|
||||
|
||||
- else
|
||||
.row
|
||||
.large-12.columns
|
||||
= enterprise.name
|
||||
.large-12.large-centered.columns
|
||||
.centered
|
||||
= "No distribution hubs found within #{Enterprise::ENTERPRISE_SEARCH_RADIUS} kilometer radius"
|
||||
= link_to "Try again...", new_landing_page_path
|
||||
@@ -30,3 +30,5 @@
|
||||
%li.divider
|
||||
%li= link_to "Farmers", "#"
|
||||
= yield
|
||||
= yield :scripts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user