2015-12-08 00:43:26 +01:00
|
|
|
# A digest of all events over a period of time
|
2015-11-10 23:29:05 +01:00
|
|
|
class DigestsController < ApplicationController
|
2017-07-28 00:35:14 +02:00
|
|
|
has_scope :region, :locality, :tag
|
|
|
|
has_scope :near, type: :hash, using: %i[location distance]
|
2015-12-08 00:43:26 +01:00
|
|
|
has_scope :moderated, default: nil, allow_blank: true
|
2017-04-22 20:01:47 +02:00
|
|
|
has_scope :period, allow_blank: true, type: :hash, using: %i[year week],
|
2015-12-22 00:29:41 +01:00
|
|
|
default: (
|
|
|
|
lambda do
|
|
|
|
{ year: (Time.zone.today + 7.days).year,
|
|
|
|
week: (Time.zone.today + 7.days).cweek }
|
|
|
|
end)
|
2015-11-10 23:29:05 +01:00
|
|
|
|
2019-06-20 21:59:04 +02:00
|
|
|
before_action :set_week, if: -> { params[:period].present? }
|
2015-11-10 23:29:05 +01:00
|
|
|
before_action :set_events, only: [:show]
|
|
|
|
|
|
|
|
def show
|
2015-11-21 17:29:50 +01:00
|
|
|
render :markdown
|
2015-11-10 23:29:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_week
|
2019-06-20 21:59:04 +02:00
|
|
|
return if params[:period][:week].blank?
|
2019-06-09 17:52:47 +02:00
|
|
|
|
2018-01-27 18:09:58 +01:00
|
|
|
@week = Date.commercial params[:period][:year].to_i,
|
2017-10-21 22:12:19 +02:00
|
|
|
params[:period][:week].to_i
|
2015-11-10 23:29:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_events
|
|
|
|
@week ||= Time.zone.today + 7.days
|
2015-12-08 00:43:26 +01:00
|
|
|
@events = apply_scopes Event
|
2015-11-10 23:29:05 +01:00
|
|
|
end
|
|
|
|
end
|