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'
}
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.addLayer eventsLayer

View File

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

View File

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

View File

@ -1,19 +1,7 @@
class MapsController < ApplicationController
def index
@events = Event
if (params[:region] && params[:region].present? && params[:region] != 'all')
@events = @events.region(params[:region])
end
@events = @events.tag(params[:tag]) if (params[:tag])
@cities_event = City.joins(:events).where('start_time > ?', 360.days.ago)
@events = @events.where('start_time > ?', 360.days.ago).order :id
@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 }
@cities_lug = City.joins :lugs
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
has_many :events, foreign_key: :city, primary_key: :name
has_many :lugs, foreign_key: :city, primary_key: :name
end

View File

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

View File

@ -1,9 +1,4 @@
class Lug < ActiveRecord::Base
belongs_to :region, foreign_key: 'region'
def related_city
if city.present?
City.find_by_majname city.gsub('-', ' ').upcase
end
end
has_one :related_city, foreign_key: :name, primary_key: :city, class_name: City
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.tag! 'dc:identifier', "#{event.id}@agendadulibre.org"
xml.tag! 'dc:date', event.start_time
city = event.related_city
xml.tag! 'georss:point', "#{city.latitude} #{city.longitude}" rescue nil
xml.tag! 'georss:point', "#{event.related_city.latitude} #{event.related_city.longitude}" rescue nil
@event = event
content = render file: '/events/show.html', locals: { rss: true }

View File

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

View File

@ -10,10 +10,9 @@
- for city in @cities_event
:coffee
marker = new OpenLayers.Marker(
eventsLayer.addMarker new OpenLayers.Marker(
new OpenLayers.LonLat(#{city.longitude}, #{city.latitude})
)
eventsLayer.addMarker marker
:javascript
var lugsLayer = new OpenLayers.Layer.Markers("#{t '.lugs'}");
@ -23,8 +22,7 @@
- for city in @cities_lug
:coffee
marker = new OpenLayers.Marker(
lugsLayer.addMarker new OpenLayers.Marker(
new OpenLayers.LonLat(#{city.longitude}, #{city.latitude})
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
one:
name: MyString
majname: MyString
name: Jolie ville
majname: JOLIE VILLE
postalcode: 1
inseecode: 1
regioncode: 1
@ -10,8 +10,8 @@ one:
longitude: 1.5
two:
name: MyString
majname: MyString
name: Une autre ville
majname: UNE AUTRE VILLE
postalcode: 1
inseecode: 1
regioncode: 1

View File

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