Digest week working even with no week number

This commit is contained in:
echarp 2019-06-09 17:52:47 +02:00
parent 30386b5c1b
commit 8da40221cf
3 changed files with 7 additions and 2 deletions

View File

@ -20,6 +20,8 @@ class DigestsController < ApplicationController
private private
def set_week def set_week
return unless params[:period][:week].present?
@week = Date.commercial params[:period][:year].to_i, @week = Date.commercial params[:period][:year].to_i,
params[:period][:week].to_i params[:period][:week].to_i
end end

View File

@ -58,7 +58,10 @@ class Event < ApplicationRecord
start_date.to_date.end_of_month.end_of_week.end_of_day start_date.to_date.end_of_month.end_of_week.end_of_day
end) end)
scope :period, (lambda do |year, week| scope :period, (lambda do |year, week|
start_date = Date.commercial(year.to_i, week.to_i) start_date = Date.commercial(
year.to_i,
(week || (Time.zone.today + 7.days).cweek).to_i
)
where '? <= end_time and start_time <= ?', where '? <= end_time and start_time <= ?',
start_date, start_date.end_of_week.end_of_day start_date, start_date.end_of_week.end_of_day
end) end)

View File

@ -1,4 +1,4 @@
- title = t '.title', week: @week.cweek, year: @week.year - title = t '.title', week: @week.cweek, year: (@week + 4.days).year
- description = capture_haml do - description = capture_haml do
= t '.week', count: @events.count, count_by_country: count_by_country(@events) = t '.week', count: @events.count, count_by_country: count_by_country(@events)