geospatial searching
This commit is contained in:
@@ -38,6 +38,10 @@
|
|||||||
.alert-notice
|
.alert-notice
|
||||||
@extend .alert-info
|
@extend .alert-info
|
||||||
|
|
||||||
|
.form-inline > *
|
||||||
|
margin: 5px
|
||||||
|
|
||||||
|
|
||||||
body.admin
|
body.admin
|
||||||
background: repeating-linear-gradient(45deg, yellow, yellow 50px, black 50px, black 100px)
|
background: repeating-linear-gradient(45deg, yellow, yellow 50px, black 50px, black 100px)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,22 @@ class Network::SignatureCollectionsController < ApplicationController
|
|||||||
# GET /network/signature_collections
|
# GET /network/signature_collections
|
||||||
# GET /network/signature_collections.json
|
# GET /network/signature_collections.json
|
||||||
def index
|
def index
|
||||||
|
@query, @location, @distance = params[:query], params[:location], params[:distance]
|
||||||
|
|
||||||
@network_signature_collections = Network::SignatureCollection.where(:event_date_start.gte => DateTime.now)
|
@network_signature_collections = Network::SignatureCollection.where(:event_date_start.gte => DateTime.now)
|
||||||
|
|
||||||
|
@network_signature_collections = @network_signature_collections.or(location_zip_s: /#{@query}/) if @query
|
||||||
|
@network_signature_collections = @network_signature_collections.or(location_name: /#{@query}/) if @query
|
||||||
|
@network_signature_collections = @network_signature_collections.or(location_address: /#{@query}/) if @query
|
||||||
|
|
||||||
|
distance_from_location
|
||||||
|
end
|
||||||
|
|
||||||
|
def distance_from_location
|
||||||
|
return unless @location && @distance
|
||||||
|
location_coordinates = Geocoder.coordinates(@location)
|
||||||
|
return unless location_coordinates # only filter when coordinates found
|
||||||
|
@network_signature_collections = @network_signature_collections.geo_near(location_coordinates.reverse).max_distance(@distance.to_f/111)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /network/signature_collections/1
|
# GET /network/signature_collections/1
|
||||||
|
|||||||
@@ -1,8 +1,30 @@
|
|||||||
class Network::SignatureCollection
|
class Network::SignatureCollection
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
|
include Geocoder::Model::Mongoid
|
||||||
|
|
||||||
field :location_name, type: String
|
field :location_name, type: String
|
||||||
field :location_zip, type: Integer
|
field :location_zip, type: Integer
|
||||||
|
field :location_zip_s, type: String
|
||||||
field :location_address, type: String
|
field :location_address, type: String
|
||||||
field :event_date_start, type: Time
|
field :event_date_start, type: Time
|
||||||
field :event_date_end, type: Time
|
field :event_date_end, type: Time
|
||||||
|
field :coordinates, type: Array
|
||||||
|
|
||||||
|
geocoded_by :address
|
||||||
|
before_save :update_location # auto-fetch coordinates
|
||||||
|
before_save :stringify_zip # auto-fetch coordinates
|
||||||
|
|
||||||
|
def address
|
||||||
|
"#{location_zip} #{location_name}, Switzerland"
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_location
|
||||||
|
geocode
|
||||||
|
end
|
||||||
|
|
||||||
|
def stringify_zip
|
||||||
|
self.location_zip_s = self.location_zip.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
index({coordinates: "2d"})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
h1 = title t('.title')
|
h1 = title t('.title')
|
||||||
#signature_collections_table
|
css:
|
||||||
input.search.form-control.string placeholder="#{t('.search')}"
|
.form-inline > * {
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
form
|
||||||
|
.form-inline
|
||||||
|
input.form-control placeholder="#{t('.search')}" name="query" value="#{@query}"
|
||||||
|
input.form-control placeholder="#{t('.location')}" name="location" value="#{@location}"
|
||||||
|
select.form-control name="distance"
|
||||||
|
- [5, 10, 20, 50, 100, 150, 200].each do | d |
|
||||||
|
- if d == @distance.to_i
|
||||||
|
option value="#{d}" selected="selected" #{d} Km
|
||||||
|
- else
|
||||||
|
option value="#{d}" #{d} Km
|
||||||
|
|
||||||
|
input.btn.btn-primary type="submit" value="#{t('.search')}"
|
||||||
|
|
||||||
table.table
|
table.table
|
||||||
thead
|
thead
|
||||||
tr
|
tr
|
||||||
@@ -30,10 +45,3 @@ h1 = title t('.title')
|
|||||||
br
|
br
|
||||||
|
|
||||||
= link_to t('.new'), new_network_signature_collection_path
|
= link_to t('.new'), new_network_signature_collection_path
|
||||||
|
|
||||||
javascript:
|
|
||||||
var options = {
|
|
||||||
valueNames: [ 'location_name', 'location_zip', 'location_address', 'event_date_start', 'event_date_end' ]
|
|
||||||
};
|
|
||||||
|
|
||||||
var signature_collections = new List('signature_collections_table', options);
|
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ de:
|
|||||||
new: Neue Sammlung erfasssen
|
new: Neue Sammlung erfasssen
|
||||||
title: Unterschriftensammlungen
|
title: Unterschriftensammlungen
|
||||||
search: Suche
|
search: Suche
|
||||||
|
location: Ort
|
||||||
routes:
|
routes:
|
||||||
initiative_text: initiativtext
|
initiative_text: initiativtext
|
||||||
arguments: argumentarium
|
arguments: argumentarium
|
||||||
|
|||||||
+2
-1
@@ -7,8 +7,9 @@
|
|||||||
# Mayor.create(name: 'Emanuel', city: cities.first)
|
# Mayor.create(name: 'Emanuel', city: cities.first)
|
||||||
|
|
||||||
@cities = CSV.read Rails.root.join('db', 'plz_ch.csv')
|
@cities = CSV.read Rails.root.join('db', 'plz_ch.csv')
|
||||||
|
|
||||||
@cities.sample(122).each do |city|
|
@cities.sample(122).each do |city|
|
||||||
tmp_date = DateTime.now + rand(50)
|
tmp_date = DateTime.now + rand(50)
|
||||||
Network::SignatureCollection.create(location_zip: city.first, location_name: city.last, location_address: Faker::Address.street_address, event_date_start: tmp_date, event_date_end: tmp_date+rand(10).to_f/10)
|
Network::SignatureCollection.create(location_zip: city.first, location_name: city.last, location_address: Faker::Address.street_address, event_date_start: tmp_date, event_date_end: tmp_date+rand(10).to_f/10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Network::SignatureCollection.where(location: {"$near" => x.location, '$maxDistance' => 1.fdiv(111.12)}).map &:location_name
|
||||||
|
|||||||
Vendored
-1758
File diff suppressed because it is too large
Load Diff
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user