Skip to content
Extraits de code Groupes Projets
Valider 98ef2085 rédigé par echarp's avatar echarp
Parcourir les fichiers

Nettoyage

parent cc8369a0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -11,7 +11,7 @@ class EventsController < ApplicationController ...@@ -11,7 +11,7 @@ class EventsController < ApplicationController
def index def index
respond_to do |format| respond_to do |format|
format.html { render layout: 'iframe' if params[:iframe] } format.html { render layout: 'iframe' if params[:iframe] }
format.rss { @events = @events.future_in params[:daylimit] } format.rss { @events = @events.future.in params[:daylimit] }
format.ics { @events = @events.last_year.order :id } format.ics { @events = @events.last_year.order :id }
format.xml { @events = @events.includes(:related_region).order :id } format.xml { @events = @events.includes(:related_region).order :id }
end end
......
...@@ -22,21 +22,19 @@ class Event < ActiveRecord::Base ...@@ -22,21 +22,19 @@ class Event < ActiveRecord::Base
scope :moderated, -> { where moderated: true } scope :moderated, -> { where moderated: true }
scope :unmoderated, -> { where moderated: false } scope :unmoderated, -> { where moderated: false }
scope :last_year, -> { where '? <= end_time', 360.days.ago } scope :last_year, -> { where '? <= end_time', 1.year.ago }
scope :past, -> { where 'start_time <= ?', DateTime.now } scope :past, -> { where 'start_time <= ?', DateTime.now }
scope :future, -> { where '? <= end_time', DateTime.now } scope :future, -> { where '? <= end_time', DateTime.now }
scope :future_in, (lambda do |days = 30| scope :in, -> days { where 'end_time <= ?', (days || 30).to_i.days.from_now }
future.where('end_time <= ?', days.to_i.days.from_now).order :start_time
end)
scope :year, (lambda do |year| scope :year, (lambda do |year|
where '? <= end_time and start_time <= ?', where '? <= end_time and start_time <= ?',
Date.new(year, 1, 1).beginning_of_week, Date.new(year, 1, 1).beginning_of_week,
Date.new(year, 12, 31).end_of_week Date.new(year, 12, 31).end_of_week
end) end)
scope :month, (lambda do |start_date| scope :month, (lambda do |start_date|
start_date ||= Date.today.beginning_of_month start_date ||= Date.today
where '? <= end_time and start_time <= ?', where '? <= end_time and start_time <= ?',
start_date.beginning_of_week, start_date.beginning_of_month.beginning_of_week,
start_date.end_of_month.end_of_week start_date.end_of_month.end_of_week
end) end)
scope :region, -> region { where 'region = ? or locality', region } scope :region, -> region { where 'region = ? or locality', region }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
- (1..12).each do |i| - (1..12).each do |i|
- params[:start_date] = "#{params[:year]}-#{i}-01" - params[:start_date] = "#{params[:year]}-#{i}-01"
= month_calendar events: @events, = month_calendar day_names: 'date.day_names', events: @events,
previous_link: nil, next_link: nil, previous_link: nil, next_link: nil,
title: ->(start_date) { raw link_to l(start_date, format: :month), title: ->(start_date) { raw link_to l(start_date, format: :month),
root_url(start_date: start_date), class: 'month_selector' } do |date, events| root_url(start_date: start_date), class: 'month_selector' } do |date, events|
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
- else - else
-# One month calendar -# One month calendar
- @events = @events.month params[:start_date].try :to_date - @events = @events.month params[:start_date].try :to_date
= month_calendar events: @events, = month_calendar day_names: 'date.day_names', events: @events,
title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year, title: ->(start_date) { raw "#{I18n.t('date.month_names')[start_date.month]} #{link_to start_date.year,
root_url(year: start_date.year)}" }, root_url(year: start_date.year)}" },
previous_link: ->(param, date_range) { link_to '<<', previous_link: ->(param, date_range) { link_to '<<',
......
fr: fr:
date: date:
abbr_day_names:
- Dimanche
- Lundi
- Mardi
- Mercredi
- Jeudi
- Vendredi
- Samedi
formats: formats:
long: "%A %d %B %Y" long: "%A %d %B %Y"
month: "%B %Y" month: "%B %Y"
......
...@@ -86,10 +86,11 @@ class EventTest < ActiveSupport::TestCase ...@@ -86,10 +86,11 @@ class EventTest < ActiveSupport::TestCase
assert @event.moderated?, @event.errors.messages assert @event.moderated?, @event.errors.messages
end end
test 'named scope future_in' do test 'named scope future.in' do
assert Event.respond_to? :future_in assert Event.respond_to? :future
assert_match(/<= end_time/, Event.future_in.where_values[0]) assert Event.respond_to? :in
assert_match(/end_time <=/, Event.future_in.where_values[1]) assert_match(/<= end_time/, Event.future.in(nil).where_values[0])
assert_match(/end_time <=/, Event.future.in(nil).where_values[1])
end end
test 'named scope year' do test 'named scope year' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter