Les relations allant d'event à city et de lug à city sont maintenant des relations appropriées

This commit is contained in:
echarp 2014-05-10 11:38:39 +02:00
parent 3f5759ec87
commit f202c23116
12 changed files with 23 additions and 43 deletions

View File

@ -11,7 +11,7 @@ $(document).ready ->
layers: 'basic' layers: 'basic'
} }
map.addLayer layer map.addLayer layer
map.setCenter new OpenLayers.LonLat(2.5, 47), 6 map.setCenter new OpenLayers.LonLat(2.5, 46.4), 7
map.addControl new OpenLayers.Control.LayerSwitcher() map.addControl new OpenLayers.Control.LayerSwitcher()
map.addLayer eventsLayer map.addLayer eventsLayer

View File

@ -1,3 +1,3 @@
#map #map
width: 100% width: 100%
height: 40em height: 60em

View File

@ -19,7 +19,7 @@ class EventsController < InheritedResources::Base
} }
format.rss { format.rss {
@events = @events.future_30 @events = @events.future_30.includes(:related_city)
@events = @events.limit params[:daylimit] if params[:daylimit] @events = @events.limit params[:daylimit] if params[:daylimit]
} }

View File

@ -1,19 +1,7 @@
class MapsController < ApplicationController class MapsController < ApplicationController
def index def index
@events = Event @cities_event = City.joins(:events).where('start_time > ?', 360.days.ago)
if (params[:region] && params[:region].present? && params[:region] != 'all')
@events = @events.region(params[:region])
end
@events = @events.tag(params[:tag]) if (params[:tag])
@events = @events.where('start_time > ?', 360.days.ago).order :id @cities_lug = City.joins :lugs
@cities_event = @events.collect { |event|
event.related_city
}.uniq.keep_if { |city| city }
@cities_lug = Lug.all.collect { |lug|
lug.related_city
}.uniq.keep_if { |city| city }
end end
end end

View File

@ -1,2 +1,8 @@
# This class is linked to events and lugs
#
# It is mainly used to manage coordinates
#
class City < ActiveRecord::Base class City < ActiveRecord::Base
has_many :events, foreign_key: :city, primary_key: :name
has_many :lugs, foreign_key: :city, primary_key: :name
end end

View File

@ -1,6 +1,7 @@
class Event < ActiveRecord::Base class Event < ActiveRecord::Base
belongs_to :region, foreign_key: 'region' belongs_to :region, foreign_key: 'region'
has_many :notes has_many :notes
has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City
validates_presence_of :region validates_presence_of :region
@ -32,10 +33,4 @@ class Event < ActiveRecord::Base
def same_day? def same_day?
start_time.to_date == end_time.to_date start_time.to_date == end_time.to_date
end end
def related_city
if city.present?
City.find_by_majname city.gsub('-', ' ').upcase
end
end
end end

View File

@ -1,9 +1,4 @@
class Lug < ActiveRecord::Base class Lug < ActiveRecord::Base
belongs_to :region, foreign_key: 'region' belongs_to :region, foreign_key: 'region'
has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City
def related_city
if city.present?
City.find_by_majname city.gsub('-', ' ').upcase
end
end
end end

View File

@ -28,8 +28,7 @@ xml.tag! 'rdf:RDF', 'xmlns:rdf' => "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xml.link event_url event xml.link event_url event
xml.tag! 'dc:identifier', "#{event.id}@agendadulibre.org" xml.tag! 'dc:identifier', "#{event.id}@agendadulibre.org"
xml.tag! 'dc:date', event.start_time xml.tag! 'dc:date', event.start_time
city = event.related_city xml.tag! 'georss:point', "#{event.related_city.latitude} #{event.related_city.longitude}" rescue nil
xml.tag! 'georss:point', "#{city.latitude} #{city.longitude}" rescue nil
@event = event @event = event
content = render file: '/events/show.html', locals: { rss: true } content = render file: '/events/show.html', locals: { rss: true }

View File

@ -14,8 +14,7 @@
= link_to t('.add_to_calendar'), root_url = link_to t('.add_to_calendar'), root_url
%h2 %h2
%em= @event.city %em= @event.city + ':'
\:
= @event.title = @event.title
%h3 Date et lieu %h3 Date et lieu

View File

@ -10,10 +10,9 @@
- for city in @cities_event - for city in @cities_event
:coffee :coffee
marker = new OpenLayers.Marker( eventsLayer.addMarker new OpenLayers.Marker(
new OpenLayers.LonLat(#{city.longitude}, #{city.latitude}) new OpenLayers.LonLat(#{city.longitude}, #{city.latitude})
) )
eventsLayer.addMarker marker
:javascript :javascript
var lugsLayer = new OpenLayers.Layer.Markers("#{t '.lugs'}"); var lugsLayer = new OpenLayers.Layer.Markers("#{t '.lugs'}");
@ -23,8 +22,7 @@
- for city in @cities_lug - for city in @cities_lug
:coffee :coffee
marker = new OpenLayers.Marker( lugsLayer.addMarker new OpenLayers.Marker(
new OpenLayers.LonLat(#{city.longitude}, #{city.latitude}) new OpenLayers.LonLat(#{city.longitude}, #{city.latitude})
new OpenLayers.Icon("/assets/team.png", iconSize, iconOffset) new OpenLayers.Icon("/assets/team.png", iconSize, iconOffset)
) )
lugsLayer.addMarker marker

View File

@ -1,8 +1,8 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one: one:
name: MyString name: Jolie ville
majname: MyString majname: JOLIE VILLE
postalcode: 1 postalcode: 1
inseecode: 1 inseecode: 1
regioncode: 1 regioncode: 1
@ -10,8 +10,8 @@ one:
longitude: 1.5 longitude: 1.5
two: two:
name: MyString name: Une autre ville
majname: MyString majname: UNE AUTRE VILLE
postalcode: 1 postalcode: 1
inseecode: 1 inseecode: 1
regioncode: 1 regioncode: 1

View File

@ -5,7 +5,7 @@ one:
description: MyText description: MyText
start_time: 2013-12-28 16:04:56 start_time: 2013-12-28 16:04:56
end_time: 2013-12-28 16:04:56 end_time: 2013-12-28 16:04:56
city: MyString city: Jolie ville
region: region_one region: region_one
locality: 1 locality: 1
url: MyString url: MyString
@ -24,7 +24,7 @@ two:
description: MyText description: MyText
start_time: 2013-12-28 16:04:56 start_time: 2013-12-28 16:04:56
end_time: 2013-12-28 16:04:56 end_time: 2013-12-28 16:04:56
city: MyString city: Une autre ville
region: region_one region: region_one
locality: 1 locality: 1
url: MyString url: MyString