geospatial searching
This commit is contained in:
@@ -110,7 +110,7 @@ group :development do
|
|||||||
# Access an IRB console on exception pages or by using <%= console %> in views
|
# Access an IRB console on exception pages or by using <%= console %> in views
|
||||||
gem 'web-console', '~> 2.0'
|
gem 'web-console', '~> 2.0'
|
||||||
|
|
||||||
# Better Errors replaces the standard Rails error page with a much better and more useful error page.
|
# Better Errors replaces the standard Rails error page with a much better and more useful error page.
|
||||||
gem "better_errors"
|
gem "better_errors"
|
||||||
gem "binding_of_caller"
|
gem "binding_of_caller"
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
@import "donations"
|
@import "donations"
|
||||||
@import "nav"
|
@import "nav"
|
||||||
|
|
||||||
*:focus
|
*:focus
|
||||||
outline: 0
|
outline: 0
|
||||||
-webkit-box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red
|
-webkit-box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red
|
||||||
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red
|
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red
|
||||||
@@ -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)
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@ body
|
|||||||
padding: 20px
|
padding: 20px
|
||||||
margin-top: 10px
|
margin-top: 10px
|
||||||
background: #FFF
|
background: #FFF
|
||||||
|
|
||||||
.anouncement
|
.anouncement
|
||||||
margin-top: 10px
|
margin-top: 10px
|
||||||
|
|
||||||
@@ -64,38 +68,38 @@ body
|
|||||||
h1
|
h1
|
||||||
font-size: 20px
|
font-size: 20px
|
||||||
margin-top: 35px
|
margin-top: 35px
|
||||||
|
|
||||||
.navbar
|
.navbar
|
||||||
.container
|
.container
|
||||||
padding-left: 0px
|
padding-left: 0px
|
||||||
|
|
||||||
header > .row
|
header > .row
|
||||||
margin-bottom: 12px
|
margin-bottom: 12px
|
||||||
|
|
||||||
main > h1
|
main > h1
|
||||||
margin-top: 0px
|
margin-top: 0px
|
||||||
|
|
||||||
ul#topnav
|
ul#topnav
|
||||||
font-size: 1.2em
|
font-size: 1.2em
|
||||||
|
|
||||||
li
|
li
|
||||||
text-transform: uppercase
|
text-transform: uppercase
|
||||||
|
|
||||||
ul
|
ul
|
||||||
li
|
li
|
||||||
text-transform: none
|
text-transform: none
|
||||||
|
|
||||||
li.active
|
li.active
|
||||||
border-bottom: 1px solid #66903F
|
border-bottom: 1px solid #66903F
|
||||||
|
|
||||||
.lead
|
.lead
|
||||||
font-weight: normal
|
font-weight: normal
|
||||||
|
|
||||||
#new_supporter
|
#new_supporter
|
||||||
label.required
|
label.required
|
||||||
abbr
|
abbr
|
||||||
display: none
|
display: none
|
||||||
|
|
||||||
#counter
|
#counter
|
||||||
background-color: $brand-success
|
background-color: $brand-success
|
||||||
margin-top: 24px
|
margin-top: 24px
|
||||||
@@ -103,7 +107,7 @@ body
|
|||||||
border: 1px solid $brand-success
|
border: 1px solid $brand-success
|
||||||
border-radius: 5px
|
border-radius: 5px
|
||||||
color: white
|
color: white
|
||||||
|
|
||||||
.counter_char
|
.counter_char
|
||||||
background-color: white
|
background-color: white
|
||||||
width: 20px
|
width: 20px
|
||||||
@@ -114,7 +118,7 @@ body
|
|||||||
display: inline-block
|
display: inline-block
|
||||||
text-align: center
|
text-align: center
|
||||||
color: $brand-success
|
color: $brand-success
|
||||||
|
|
||||||
.text-success
|
.text-success
|
||||||
color: $brand-success
|
color: $brand-success
|
||||||
|
|
||||||
@@ -122,18 +126,18 @@ body
|
|||||||
display: block
|
display: block
|
||||||
float: left
|
float: left
|
||||||
margin: 12px
|
margin: 12px
|
||||||
|
|
||||||
.table-inherit
|
.table-inherit
|
||||||
width: inherit
|
width: inherit
|
||||||
|
|
||||||
footer
|
footer
|
||||||
h2
|
h2
|
||||||
margin: 0px
|
margin: 0px
|
||||||
font-size: $font-size-base
|
font-size: $font-size-base
|
||||||
|
|
||||||
ol
|
ol
|
||||||
padding-left: 1em
|
padding-left: 1em
|
||||||
|
|
||||||
.donation_button
|
.donation_button
|
||||||
height: 50px
|
height: 50px
|
||||||
background: $brand-success
|
background: $brand-success
|
||||||
@@ -149,10 +153,10 @@ body
|
|||||||
left: -47px
|
left: -47px
|
||||||
box-shadow: inset 0px 0px 0px 4px rgba(255, 255, 255, 0.34)
|
box-shadow: inset 0px 0px 0px 4px rgba(255, 255, 255, 0.34)
|
||||||
|
|
||||||
a
|
a
|
||||||
color: #FFF
|
color: #FFF
|
||||||
|
|
||||||
.row.fix
|
.row.fix
|
||||||
display: flex
|
display: flex
|
||||||
flex-wrap: wrap
|
flex-wrap: wrap
|
||||||
width: 100%
|
width: 100%
|
||||||
|
|||||||
@@ -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