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
|
||||
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 "binding_of_caller"
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
@import "donations"
|
||||
@import "nav"
|
||||
|
||||
*:focus
|
||||
*:focus
|
||||
outline: 0
|
||||
-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
|
||||
@@ -38,6 +38,10 @@
|
||||
.alert-notice
|
||||
@extend .alert-info
|
||||
|
||||
.form-inline > *
|
||||
margin: 5px
|
||||
|
||||
|
||||
body.admin
|
||||
background: repeating-linear-gradient(45deg, yellow, yellow 50px, black 50px, black 100px)
|
||||
|
||||
@@ -51,7 +55,7 @@ body
|
||||
padding: 20px
|
||||
margin-top: 10px
|
||||
background: #FFF
|
||||
|
||||
|
||||
.anouncement
|
||||
margin-top: 10px
|
||||
|
||||
@@ -64,38 +68,38 @@ body
|
||||
h1
|
||||
font-size: 20px
|
||||
margin-top: 35px
|
||||
|
||||
|
||||
.navbar
|
||||
.container
|
||||
padding-left: 0px
|
||||
|
||||
|
||||
header > .row
|
||||
margin-bottom: 12px
|
||||
|
||||
|
||||
main > h1
|
||||
margin-top: 0px
|
||||
|
||||
ul#topnav
|
||||
font-size: 1.2em
|
||||
|
||||
|
||||
li
|
||||
text-transform: uppercase
|
||||
|
||||
|
||||
ul
|
||||
li
|
||||
li
|
||||
text-transform: none
|
||||
|
||||
|
||||
li.active
|
||||
border-bottom: 1px solid #66903F
|
||||
|
||||
|
||||
.lead
|
||||
font-weight: normal
|
||||
|
||||
|
||||
#new_supporter
|
||||
label.required
|
||||
abbr
|
||||
display: none
|
||||
|
||||
|
||||
#counter
|
||||
background-color: $brand-success
|
||||
margin-top: 24px
|
||||
@@ -103,7 +107,7 @@ body
|
||||
border: 1px solid $brand-success
|
||||
border-radius: 5px
|
||||
color: white
|
||||
|
||||
|
||||
.counter_char
|
||||
background-color: white
|
||||
width: 20px
|
||||
@@ -114,7 +118,7 @@ body
|
||||
display: inline-block
|
||||
text-align: center
|
||||
color: $brand-success
|
||||
|
||||
|
||||
.text-success
|
||||
color: $brand-success
|
||||
|
||||
@@ -122,18 +126,18 @@ body
|
||||
display: block
|
||||
float: left
|
||||
margin: 12px
|
||||
|
||||
|
||||
.table-inherit
|
||||
width: inherit
|
||||
|
||||
footer
|
||||
|
||||
footer
|
||||
h2
|
||||
margin: 0px
|
||||
font-size: $font-size-base
|
||||
|
||||
ol
|
||||
ol
|
||||
padding-left: 1em
|
||||
|
||||
|
||||
.donation_button
|
||||
height: 50px
|
||||
background: $brand-success
|
||||
@@ -149,10 +153,10 @@ body
|
||||
left: -47px
|
||||
box-shadow: inset 0px 0px 0px 4px rgba(255, 255, 255, 0.34)
|
||||
|
||||
a
|
||||
a
|
||||
color: #FFF
|
||||
|
||||
.row.fix
|
||||
.row.fix
|
||||
display: flex
|
||||
flex-wrap: wrap
|
||||
width: 100%
|
||||
|
||||
@@ -5,7 +5,22 @@ class Network::SignatureCollectionsController < ApplicationController
|
||||
# GET /network/signature_collections
|
||||
# GET /network/signature_collections.json
|
||||
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_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
|
||||
|
||||
# GET /network/signature_collections/1
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
class Network::SignatureCollection
|
||||
include Mongoid::Document
|
||||
include Geocoder::Model::Mongoid
|
||||
|
||||
field :location_name, type: String
|
||||
field :location_zip, type: Integer
|
||||
field :location_zip_s, type: String
|
||||
field :location_address, type: String
|
||||
field :event_date_start, 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
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
h1 = title t('.title')
|
||||
#signature_collections_table
|
||||
input.search.form-control.string placeholder="#{t('.search')}"
|
||||
css:
|
||||
.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
|
||||
thead
|
||||
tr
|
||||
@@ -30,10 +45,3 @@ h1 = title t('.title')
|
||||
br
|
||||
|
||||
= 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
|
||||
title: Unterschriftensammlungen
|
||||
search: Suche
|
||||
location: Ort
|
||||
routes:
|
||||
initiative_text: initiativtext
|
||||
arguments: argumentarium
|
||||
|
||||
+2
-1
@@ -7,8 +7,9 @@
|
||||
# Mayor.create(name: 'Emanuel', city: cities.first)
|
||||
|
||||
@cities = CSV.read Rails.root.join('db', 'plz_ch.csv')
|
||||
|
||||
@cities.sample(122).each do |city|
|
||||
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)
|
||||
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