Organisations are now also displayed on the map. Refs #71

recurrent
echarp 7 years ago
parent 94afdadef3
commit f02c0b10f2
  1. 2
      Gemfile.lock
  2. 46
      app/assets/javascripts/maps.js.coffee
  3. 4
      app/assets/stylesheets/maps.sass
  4. 2
      app/controllers/events_controller.rb
  5. 8
      app/controllers/maps_controller.rb
  6. 20
      app/models/orga.rb
  7. 4
      app/views/events/index.json.jbuilder
  8. 3
      app/views/events/show.json.jbuilder
  9. 24
      app/views/maps/index.html.haml
  10. 6
      app/views/orgas/index.json.jbuilder
  11. 2
      app/views/orgas/show.json.jbuilder
  12. 2
      config/locales/views/en.yml
  13. 2
      config/locales/views/fr.yml
  14. 2
      config/routes.rb
  15. 82
      db/schema.rb
  16. 2
      public/assets/.sprockets-manifest-397b105f7cb4ee89aa946a40a070819a.json
  17. 75324
      public/assets/application-d61d53fc0a7f815db732faf5c4ccc3fc36e4aa5742abec9ccc16e8b77f2f6dd0.js
  18. BIN
      public/assets/application-d61d53fc0a7f815db732faf5c4ccc3fc36e4aa5742abec9ccc16e8b77f2f6dd0.js.gz
  19. 13228
      public/assets/application-e08384d7ca80213e0d6c24b1b649a0b64d6e7281a61f79c0002ca9ebfd248fc7.css
  20. BIN
      public/assets/application-e08384d7ca80213e0d6c24b1b649a0b64d6e7281a61f79c0002ca9ebfd248fc7.css.gz
  21. BIN
      public/assets/font-awesome/fontawesome-webfont-7b5a4320fba0d4c8f79327645b4b9cc875a2ec617a557e849b813918eb733499.ttf.gz
  22. BIN
      public/assets/font-awesome/fontawesome-webfont-e219ece8f4d3e4ac455ef31cd3a7c7b5057ea68a109937fc26b03c6e99ee9322.eot.gz
  23. 21
      public/assets/tinymce-ec0502c5fab1c527264bf5f4036e349c415a7a1740c9087f00dd11ddddfb5e74.js
  24. BIN
      public/assets/tinymce-ec0502c5fab1c527264bf5f4036e349c415a7a1740c9087f00dd11ddddfb5e74.js.gz
  25. 2
      test/models/event_test.rb

@ -152,7 +152,7 @@ GEM
formtastic (3.1.4)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
geocoder (1.3.3)
geocoder (1.3.4)
globalid (0.3.6)
activesupport (>= 4.1.0)
guard (2.13.0)

@ -1,32 +1,38 @@
# Setting up OpenStreeMap from a generic #map element
$(document).ready ->
$('#map.events, #map.orgas').each ->
$('#map.list').each ->
map = L.map 'map'
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a>'
).addTo map
url = $(this).data 'url'
if location.search && url.indexOf('?') >= 0
url += '&' + location.search.substr 1
else
url += location.search
controls = L.control.layers(null, null).addTo map
$.getJSON url, (json) ->
layer = L.geoJson json,
onEachFeature: (feature, layer) ->
# Does this feature have a property named popupContent?
if (feature.properties && feature.properties.popupContent)
layer.bindPopup feature.properties.popupContent
$('li a', this).each ->
url = $(this).attr 'href'
text = $(this).html()
if location.search && url.indexOf('?') >= 0
url += '&' + location.search.substr 1
else
url += location.search
map.addLayer L.markerClusterGroup( maxClusterRadius: 30 ).addLayer layer
$.getJSON url, (json) ->
if json
count = 0
layer = L.markerClusterGroup(maxClusterRadius: 30).addLayer L.geoJson json,
onEachFeature: (feature, layer) ->
# Does this feature have a property named popupContent?
if (feature.properties && feature.properties.popupContent)
layer.bindPopup feature.properties.popupContent
count++
if (layer.getBounds()._northEast && layer.getBounds()._southWest)
# Automatic focus to all displayed events
map.fitBounds layer.getBounds()
else
$('#map.events, #map.orgas').remove()
map.addLayer layer
controls.addOverlay layer, text + ' - ' + count
if (url.contains('maps.json') && layer.getBounds()._northEast && layer.getBounds()._southWest)
# Automatic focus to all displayed events
map.fitBounds layer.getBounds()
$('#map.event, #map.orga').each ->
coord = [$(this).data('latitude'), $(this).data('longitude')]
@ -44,12 +50,12 @@ $(document).ready ->
url += location.search
$.getJSON url, (json) ->
layer = L.geoJson json,
layer = L.markerClusterGroup(maxClusterRadius: 30).addLayer L.geoJson json,
onEachFeature: (feature, layer) ->
# Does this feature have a property named popupContent?
if (feature.properties && feature.properties.popupContent)
layer.bindPopup(feature.properties.popupContent)
map.addLayer L.markerClusterGroup( maxClusterRadius: 30 ).addLayer layer
map.addLayer layer
marker = L.marker([coord[0], coord[1]]).addTo map

@ -20,6 +20,10 @@
margin: 1.6em 2%
+inline-block()
// Left align the map controls place in the top right corner
form.leaflet-control-layers-list label
text-align: left
html.iframe #map
width: 100%
max-width: 100%

@ -17,7 +17,7 @@ class EventsController < ApplicationController
format.json { @events = @events.future }
format.rss { @events = @events.future.order('id desc').limit 20 }
format.ics { @events = @events.last_year }
format.xml { @events = @events }
format.xml
end
end

@ -13,4 +13,12 @@ class MapsController < ApplicationController
format.json { render json: apply_scopes(Event.moderated.geo) }
end
end
def show
kind = Kind.find_by_name params[:id]
orgas = apply_scopes(Orga.moderated.geo).joins(:kind).find_by(kind: kind)
respond_to do |format|
format.json { render json: orgas }
end
end
end

@ -1,7 +1,8 @@
# Organisations related to this agenda
class Orga < ActiveRecord::Base
strip_attributes
has_paper_trail ignore: [:last_updated, :secret, :submitter]
has_paper_trail ignore: [:last_updated, :secret, :submitter, :decision_time,
:lock_version, :latitude, :longitude]
belongs_to :region
belongs_to :kind
@ -23,7 +24,15 @@ class Orga < ActiveRecord::Base
scope :moderated, -> { where moderated: true }
scope :unmoderated, -> { where moderated: false }
# Only present to simplify maps_controller, to have the same scopes as events
scope :locality, -> {}
scope :daylimit, -> {}
scope :future, -> {}
scope :period, ->(year, week) {}
scope :region, ->(region) { where region: region unless region == 'all' }
scope :tag, ->(tag) { where 'tags like ?', "%#{tag}%" }
scope :geo, -> { where 'latitude is not null and longitude is not null' }
before_validation do
unless submitter.blank?
@ -60,6 +69,15 @@ class Orga < ActiveRecord::Base
name.gsub(/\AL'/, '').gsub(/[\s\*']/, '-').delete ':'
end
def as_json(_options = {})
{ type: 'Feature', properties: {
id: id, name: name,
place_name: place_name, address: address, city: city,
tags: tags,
popupContent: "<a href=\"/orgas/#{id}\">#{self}</a>"
}, geometry: { type: 'Point', coordinates: [longitude, latitude] } }
end
def full_address
[address, city, region.try(:name)].compact.join ', '
end

@ -1,8 +1,6 @@
json.array!(@events) do |event|
json.extract! event, :id, :title, :description, :start_time, :end_time,
:place_name, :address, :city, :region_id, :locality, :url,
:contact, :submitter, :moderated, :tags, :secret,
:decision_time, :submission_time, :moderator_mail_id,
:submitter_mail_id
:contact, :tags
json.url event_url(event, format: :json)
end

@ -1,4 +1,3 @@
json.extract! @event, :id, :title, :description, :start_time, :end_time,
:place_name, :address, :city, :region, :locality, :url, :contact,
:contact, :submitter, :moderated, :tags, :secret, :decision_time,
:submission_time, :moderator_mail_id, :submitter_mail_id
:tags

@ -6,17 +6,13 @@
%em= params[:tag]
»
#map.events(data-url="#{maps_path format: :json}")
%nav
= link_to events_path format: :rss, tag: params[:tag] do
%em.fa.fa-rss
RSS
\/
= link_to events_path format: :ics, tag: params[:tag] do
%em.fa.fa-th-list
iCal
\/
= link_to maps_path format: :json, tag: params[:tag] do
%em.fa.fa-dot-circle-o
GeoJSON
%ul#map.list
%li
= link_to maps_path format: :json do
%em.fa.fa-calendar
= Event.model_name.human.pluralize
- Kind.all.each do |kind|
%li
= link_to map_path kind.name, format: :json do
%em.fa{ class: "fa-#{kind.icon}" }
= Kind.human_attribute_name("name_#{kind.name}")

@ -0,0 +1,6 @@
json.array!(@orgas) do |orga|
json.extract! orga, :id, :name, :description,
:place_name, :address, :city, :region_id, :url,
:contact, :tags
json.url orga_url(orga, format: :json)
end

@ -0,0 +1,2 @@
json.extract! @orga, :id, :name, :description,
:place_name, :address, :city, :region, :url, :contact, :tags

@ -226,7 +226,7 @@ description."
ko: Moderation
maps:
index:
title: Events map
title: Events and organisations map
events: Events
orgas: Organiser
users:

@ -227,7 +227,7 @@ description plus complète."
ko: Modération
maps:
index:
title: Carte des événements
title: Carte des événements et organisations
events: Événements
orgas: Orga
users:

@ -21,7 +21,7 @@ Rails.application.routes.draw do
resources :regions, only: [:index]
get 'tags/orgas', to: 'tags#orgas'
resources :tags, only: [:index, :show]
resources :maps, only: [:index]
resources :maps, only: [:index, :show]
resources :orgas do
get :cancel, :validate, :refuse, on: :member
put :accept, on: :member

@ -24,9 +24,9 @@ ActiveRecord::Schema.define(version: 20160409131029) do
t.datetime "updated_at"
end
add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace"
add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree
add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree
add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree
create_table "admin_users", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
@ -43,8 +43,8 @@ ActiveRecord::Schema.define(version: 20160409131029) do
t.datetime "updated_at"
end
add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true
add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true, using: :btree
add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree
create_table "cities", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 20160409131029) do
t.float "longitude", limit: 24
end
add_index "cities", ["name"], name: "cities_name"
add_index "cities", ["name"], name: "cities_name", using: :btree
create_table "events", force: :cascade do |t|
t.string "title", limit: 255, default: "", null: false
@ -72,8 +72,8 @@ ActiveRecord::Schema.define(version: 20160409131029) do
t.integer "moderated", limit: 4, default: 0, null: false
t.string "tags", limit: 255, default: "", null: false
t.string "secret", limit: 255, default: "", null: false
t.datetime "decision_time"
t.datetime "submission_time"
t.datetime "decision_time", null: false
t.datetime "submission_time", null: false
t.string "moderator_mail_id", limit: 32
t.string "submitter_mail_id", limit: 32
t.text "address", limit: 65535
@ -83,7 +83,7 @@ ActiveRecord::Schema.define(version: 20160409131029) do
t.string "place_name", limit: 255
end
add_index "events", ["start_time", "end_time"], name: "events_date"
add_index "events", ["start_time", "end_time"], name: "events_date", using: :btree
create_table "kinds", force: :cascade do |t|
t.string "name", limit: 255, null: false
@ -100,66 +100,64 @@ ActiveRecord::Schema.define(version: 20160409131029) do
end
create_table "orgas", force: :cascade do |t|
t.integer "region_id", limit: 4, default: 0, null: false
t.string "department", limit: 4, default: "0", null: false
t.string "name", limit: 255, default: "", null: false
t.string "url", limit: 255, default: "", null: false
t.string "city", limit: 255, default: ""
t.integer "region_id", limit: 4, default: 0, null: false
t.string "department", limit: 255
t.string "name", limit: 255, default: "", null: false
t.string "url", limit: 255, default: "", null: false
t.string "city", limit: 255, default: ""
t.integer "kind_id", limit: 4
t.string "feed", limit: 255
t.string "contact", limit: 255
t.string "submitter", limit: 255
t.boolean "moderated", limit: 1, default: false
t.boolean "moderated", default: false
t.datetime "submission_time"
t.datetime "decision_time"
t.string "secret", limit: 255
t.boolean "deleted", limit: 1, default: false, null: false
t.boolean "active", default: true, null: false
t.text "description"
t.boolean "deleted", default: false, null: false
t.boolean "active", default: true, null: false
t.text "description", limit: 65535
t.datetime "created_at"
t.datetime "updated_at"
t.text "tag"
t.text "tags", default: ""
t.text "diaspora"
t.text "object_changes"
t.text "place_name"
t.text "address"
t.float "latitude"
t.float "longitude"
t.string "tags", limit: 255, default: ""
t.text "diaspora", limit: 65535
t.text "place_name", limit: 65535
t.text "address", limit: 65535
t.float "latitude", limit: 24
t.float "longitude", limit: 24
end
add_index "orgas", ["kind_id"], name: "index_orgas_on_kind_id"
add_index "orgas", ["kind_id"], name: "index_orgas_on_kind_id", using: :btree
create_table "regions", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
end
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.integer "tag_id", limit: 4
t.integer "taggable_id", limit: 4
t.string "taggable_type", limit: 255
t.integer "tagger_id"
t.integer "tagger_id", limit: 4
t.string "tagger_type", limit: 255
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree
create_table "tags", force: :cascade do |t|
t.string "name", limit: 255
t.integer "taggings_count", default: 0
t.integer "taggings_count", limit: 4, default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
create_table "translations", force: :cascade do |t|
t.string "locale", limit: 255
t.string "key", limit: 255
t.text "value", limit: 65535
t.text "interpolations", limit: 65535
t.boolean "is_proc", limit: 1, default: false
t.boolean "is_proc", default: false
end
create_table "users", force: :cascade do |t|
@ -171,15 +169,15 @@ ActiveRecord::Schema.define(version: 20160409131029) do
end
create_table "versions", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.string "item_type", limit: 255, null: false
t.integer "item_id", limit: 4, null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object", limit: 65535
t.datetime "created_at"
t.text "object_changes", limit: 1073741823
t.text "object_changes", limit: 4294967295
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
end

File diff suppressed because one or more lines are too long

@ -0,0 +1,21 @@
(function() {
$(document).ready(function() {
return tinyMCE.init({
schema: 'html5',
menubar: false,
language: 'fr_FR',
selector: 'textarea.description',
content_css: '/assets/application-e08384d7ca80213e0d6c24b1b649a0b64d6e7281a61f79c0002ca9ebfd248fc7.css',
entity_encoding: 'raw',
add_unload_trigger: true,
browser_spellcheck: true,
toolbar: [' bold italic strikethrough | bullist numlist outdent indent | alignleft aligncenter alignright alignjustify | link image media insertdatetime charmap table | undo redo | searchreplace | code visualblocks preview fullscreen'],
plugins: 'lists, advlist, autolink, link, image, charmap, paste, print, preview, table, fullscreen, searchreplace, media, insertdatetime, visualblocks, visualchars, wordcount, contextmenu, code'
});
});
$(document).on('page:receive', function() {
return tinymce.remove();
});
}).call(this);

@ -118,6 +118,6 @@ class EventTest < ActiveSupport::TestCase
@event.city = 'world'
# Region is no longer used for geocoding..;
# @event.region.name = 'all'
assert_equal 'hello, world', @event.full_address
assert_equal 'hello, world, Alsace', @event.full_address
end
end

Loading…
Cancel
Save