agenda-libre-ruby/app/controllers/digests_controller.rb

33 lines
942 B
Ruby
Raw Normal View History

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
has_scope :region, :locality, :tag
has_scope :near, type: :hash, using: %i[location distance]
has_scope :period, allow_blank: true, type: :hash, using: %i[year week],
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
before_action :set_week, if: -> { params[:period].present? }
2015-11-10 23:29:05 +01:00
before_action :set_events, only: [:show]
def show
render :markdown
2015-11-10 23:29:05 +01:00
end
private
def set_week
return if params[:period][:week].blank?
@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
@events = apply_scopes Event.moderated
2015-11-10 23:29:05 +01:00
end
end