Browse Source

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

recurrent
echarp 8 years ago
parent
commit
f202c23116
  1. 2
      app/assets/javascripts/maps.js.coffee
  2. 2
      app/assets/stylesheets/maps.css.sass
  3. 2
      app/controllers/events_controller.rb
  4. 16
      app/controllers/maps_controller.rb
  5. 6
      app/models/city.rb
  6. 7
      app/models/event.rb
  7. 7
      app/models/lug.rb
  8. 3
      app/views/events/index.rss.builder
  9. 3
      app/views/events/show.html.haml
  10. 6
      app/views/maps/index.html.haml
  11. 8
      test/fixtures/cities.yml
  12. 4
      test/fixtures/events.yml

2
app/assets/javascripts/maps.js.coffee

@ -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

2
app/assets/stylesheets/maps.css.sass

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

2
app/controllers/events_controller.rb

@ -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]
}

16
app/controllers/maps_controller.rb

@ -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

6
app/models/city.rb

@ -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

7
app/models/event.rb

@ -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

7
app/models/lug.rb

@ -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

3
app/views/events/index.rss.builder

@ -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 }

3
app/views/events/show.html.haml

@ -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

6
app/views/maps/index.html.haml

@ -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

8
test/fixtures/cities.yml vendored

@ -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

4
test/fixtures/events.yml vendored

@ -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

Loading…
Cancel
Save