Organisations can now have a detailed place name and address, plus a specific geocoded localisation. Refs #71

This commit is contained in:
echarp 2016-04-09 16:06:22 +02:00
parent 2030a7c0ce
commit 77ba9032d3
16 changed files with 68 additions and 30 deletions

View File

@ -1,6 +1,6 @@
# Setting up OpenStreeMap from a generic #map element # Setting up OpenStreeMap from a generic #map element
$(document).ready -> $(document).ready ->
$('#map.events').each -> $('#map.events, #map.orgas').each ->
map = L.map 'map' map = L.map 'map'
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
@ -26,9 +26,9 @@ $(document).ready ->
# Automatic focus to all displayed events # Automatic focus to all displayed events
map.fitBounds layer.getBounds() map.fitBounds layer.getBounds()
else else
$('#map.events').remove() $('#map.events, #map.orgas').remove()
$('#map.event').each -> $('#map.event, #map.orga').each ->
coord = [$(this).data('latitude'), $(this).data('longitude')] coord = [$(this).data('latitude'), $(this).data('longitude')]
map = L.map('map').setView [coord[0], coord[1]], 16 map = L.map('map').setView [coord[0], coord[1]], 16

View File

@ -55,11 +55,11 @@
.field.description label:before .field.description label:before
content: $fa-var-pencil-square-o content: $fa-var-pencil-square-o
.field.place_name label:before .field.place_name label:before
content: $fa-var-flag content: $fa-var-map-pin
.field.address label:before .field.address label:before
content: $fa-var-map-marker content: $fa-var-map-marker
.field.city label:before, th.city a:before .field.city label:before, th.city a:before
content: $fa-var-compress content: $fa-var-building-o
.field.department label:before, th.department a:before .field.department label:before, th.department a:before
content: $fa-var-puzzle-piece content: $fa-var-puzzle-piece
.field.region label:before, th.region a:before .field.region label:before, th.region a:before

View File

@ -11,7 +11,7 @@
/* Popup are better displayed with this: */ /* Popup are better displayed with this: */
max-width: initial max-width: initial
&.event &.event, &.orga
height: 20em height: 20em
.tags #map .tags #map

View File

@ -89,9 +89,9 @@ class OrgasController < ApplicationController
# through # through
def orga_params def orga_params
params.require(:orga) params.require(:orga)
.permit :lock_version, :kind_id, :name, :description, :city, .permit :lock_version, :kind_id, :name, :description, :place_name,
:department, :region_id, :url, :diaspora, :feed, :contact, :address, :city, :department, :region_id, :url, :diaspora,
:submitter, :tags, :active :feed, :contact, :submitter, :tags, :active
end end
# Check that you can only edit an existing event if you know its secret # Check that you can only edit an existing event if you know its secret

View File

@ -5,9 +5,10 @@ module OrgasHelper
description: strip_tags(@orga.description), description: strip_tags(@orga.description),
DC: { title: @orga.name }, DC: { title: @orga.name },
geo: { geo: {
region: @orga.region,
placename: @orga.city, placename: @orga.city,
position: "#{@orga.city.try :latitude}; #{@orga.city.try :longitude}" region: @orga.region,
position: "#{@orga.latitude};#{@orga.longitude}",
ICBM: "#{@orga.latitude}, #{@orga.longitude}"
} }
end end
end end

View File

@ -97,9 +97,7 @@ class Event < ActiveRecord::Base
end end
def full_address def full_address
# Temporary solution until OSM reverse geocoding can use the new regions [address, city, region.try(:name)].compact.join ', '
# [address, city, region.try(:name)].compact.join ', '
[address, city].compact.join ', '
end end
def hashtags def hashtags

View File

@ -15,6 +15,10 @@ class Orga < ActiveRecord::Base
validates :contact, allow_blank: true, email: true validates :contact, allow_blank: true, email: true
validates :submitter, allow_blank: true, email: true validates :submitter, allow_blank: true, email: true
geocoded_by :full_address
# after_validation :geocode, if: -> (obj) { obj.address_changed? }
after_validation :geocode
scope :active, -> { where active: true } scope :active, -> { where active: true }
scope :moderated, -> { where moderated: true } scope :moderated, -> { where moderated: true }
scope :unmoderated, -> { where moderated: false } scope :unmoderated, -> { where moderated: false }
@ -56,6 +60,10 @@ class Orga < ActiveRecord::Base
name.gsub(/\AL'/, '').gsub(/[\s\*']/, '-').delete ':' name.gsub(/\AL'/, '').gsub(/[\s\*']/, '-').delete ':'
end end
def full_address
[address, city, region.try(:name)].compact.join ', '
end
def to_s def to_s
"[#{kind.name}] #{name}" "[#{kind.name}] #{name}"
end end

View File

@ -21,6 +21,15 @@
.field.description .field.description
= f.label :description = f.label :description
= f.text_area :description, rows: 25, class: :description = f.text_area :description, rows: 25, class: :description
.field.place_name
= f.label :place_name
= f.text_field :place_name
.field.address
.helper
:markdown
#{t '.address_helper'}
= f.label :address
= f.text_field :address
.field.city .field.city
= f.label :city = f.label :city
= f.text_field :city, list: :cities = f.text_field :city, list: :cities

View File

@ -58,6 +58,20 @@
%em.fa.fa-lg.fa-thumbs-down %em.fa.fa-lg.fa-thumbs-down
= t '.cancel' = t '.cancel'
%p.full_address
- if @orga.place_name.present?
%span= @orga.place_name
- if @orga.address.present?
%span= @orga.address
%span= link_to @orga.city,
"http://fr.wikipedia.org/wiki/#{url_encode @orga.city}"
%span= link_to @orga.region.try(:name),
"http://fr.wikipedia.org/wiki/#{url_encode @orga.region.try :name}"
- if @orga.latitude && @orga.longitude
.orga#map{ data: { url: "#{maps_path format: :json}",
latitude: "#{@orga.latitude}", longitude: "#{@orga.longitude}" } }
%h3= t '.description' %h3= t '.description'
.description .description
= description sanitize @orga.description, = description sanitize @orga.description,
@ -65,21 +79,11 @@
attributes: %w(href src width height style) attributes: %w(href src width height style)
%dl %dl
- if @orga.city.present?
%dt
%em.fa.fa-compress
= Orga.human_attribute_name :city
%dd= @orga.city
- if @orga.department.present? - if @orga.department.present?
%dt %dt
%em.fa.fa-puzzle-piece %em.fa.fa-puzzle-piece
= Orga.human_attribute_name :department = Orga.human_attribute_name :department
%dd= @orga.department %dd= @orga.department
- if @orga.region.present?
%dt
%em.fa.fa-shield
= Orga.human_attribute_name :region
%dd= @orga.region
- if @orga.url.present? - if @orga.url.present?
%dt %dt
%em.fa.fa-external-link %em.fa.fa-external-link
@ -123,7 +127,3 @@
- if @events_future && @events_past.any? - if @events_future && @events_past.any?
%dt= t '.past' %dt= t '.past'
%dd= t '.count', count: @events_past.count %dd= t '.count', count: @events_past.count
.events#map{ title: @orga.name_as_tag,
data: { url: maps_path(format: :json, tag: @orga.name_as_tag,
future: false) } }

View File

@ -1,6 +1,8 @@
===================================================== =====================================================
#{Orga.human_attribute_name(:kind).concat(':').ljust 12 } #{@orga.kind.name} #{Orga.human_attribute_name(:kind).concat(':').ljust 12 } #{@orga.kind.name}
#{Orga.human_attribute_name(:name).concat(':').ljust 12 } #{@orga.name} #{Orga.human_attribute_name(:name).concat(':').ljust 12 } #{@orga.name}
#{Orga.human_attribute_name(:place_name).concat(':').ljust 12 } #{@orga.place_name}
#{Orga.human_attribute_name(:address).concat(':').ljust 12 } #{@orga.address}
#{Orga.human_attribute_name(:city).concat(':').ljust 12 } #{@orga.city} #{Orga.human_attribute_name(:city).concat(':').ljust 12 } #{@orga.city}
#{Orga.human_attribute_name(:department).concat(':').ljust 12 } #{@orga.department} #{Orga.human_attribute_name(:department).concat(':').ljust 12 } #{@orga.department}
#{Orga.human_attribute_name(:region).concat(':').ljust 12 } #{@orga.region} #{Orga.human_attribute_name(:region).concat(':').ljust 12 } #{@orga.region}

View File

@ -39,6 +39,8 @@ en:
kind: Type kind: Type
name: Name name: Name
description: Description description: Description
place_name: Place name
address: Address
city: City city: City
department: Department department: Department
region: Region region: Region

View File

@ -39,6 +39,8 @@ fr:
kind: Type kind: Type
name: Nom name: Nom
description: Description description: Description
place_name: Nom du lieu
address: Adresse
city: Ville city: Ville
department: Département department: Département
region: Région region: Région

View File

@ -263,6 +263,9 @@ description plus complète."
update: update:
ok: L'organisation a été mise à jour ok: L'organisation a été mise à jour
form: form:
address_helper: "*Associée à la ville et la région, elle générera une
carte [OpenStreetMap](http://www.openstreetmap.org), affichée aux côtés
de l'organisation*"
url_helper: Lien vers le site web de l'organisation url_helper: Lien vers le site web de l'organisation
feed_helper: Lien **direct** vers un flux de syndication, type RSS ou atom feed_helper: Lien **direct** vers un flux de syndication, type RSS ou atom
contact_helper: Adresse e-mail de contact, affichée de manière peu contact_helper: Adresse e-mail de contact, affichée de manière peu

View File

@ -0,0 +1,9 @@
# Add more data to orgas, with an optionnal place name and address
class AddPlaceNameToOrgas < ActiveRecord::Migration
def change
add_column :orgas, :place_name, :text
add_column :orgas, :address, :text
add_column :orgas, :latitude, :float
add_column :orgas, :longitude, :float
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160111124855) do ActiveRecord::Schema.define(version: 20160409131029) do
create_table "active_admin_comments", force: :cascade do |t| create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace", limit: 255 t.string "namespace", limit: 255
@ -122,6 +122,10 @@ ActiveRecord::Schema.define(version: 20160111124855) do
t.text "tags", default: "" t.text "tags", default: ""
t.text "diaspora" t.text "diaspora"
t.text "object_changes" t.text "object_changes"
t.text "place_name"
t.text "address"
t.float "latitude"
t.float "longitude"
end end
add_index "orgas", ["kind_id"], name: "index_orgas_on_kind_id" add_index "orgas", ["kind_id"], name: "index_orgas_on_kind_id"

View File

@ -45,7 +45,7 @@ regions = {
u'Corse' : 9, u'Corse' : 9,
u'Île-de-France' : 12, u'Île-de-France' : 12,
u'Languedoc-Roussillon-Midi-Pyrénées' : 13, u'Languedoc-Roussillon-Midi-Pyrénées' : 13,
u'Nord-Pas-de-Calais-Picardie' : 17, u'Hauts-de-France' : 17,
u'Provence-Alpes-Côte-d\'Azur' : 21, u'Provence-Alpes-Côte-d\'Azur' : 21,
u'Pays de la Loire' : 18, u'Pays de la Loire' : 18,
u'Guadeloupe' : 23, u'Guadeloupe' : 23,