Extract the EventsTimeline controller concern
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
module EventsTimeline
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
include BucketFilterable
|
||||
|
||||
included do
|
||||
before_action :set_activity_day
|
||||
end
|
||||
|
||||
private
|
||||
def set_activity_day
|
||||
@activity_day = if params[:day].present?
|
||||
Time.zone.parse(params[:day])
|
||||
else
|
||||
Time.zone.now
|
||||
end
|
||||
rescue ArgumentError
|
||||
raise ActionController::RoutingError
|
||||
end
|
||||
|
||||
def events_for_activity_day
|
||||
user_events.where(created_at: @activity_day.all_day).
|
||||
group_by { |event| [ event.created_at.hour, helpers.event_column(event) ] }.
|
||||
map { |hour_col, events|
|
||||
[ hour_col,
|
||||
events.uniq { |e| e.action == "boosted" ? [ e.creator_id, e.bubble_id ] : e.id }
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def latest_event_before_activity_day
|
||||
user_events.where(created_at: ...@activity_day.beginning_of_day).chronologically.last
|
||||
end
|
||||
|
||||
def user_events
|
||||
Event.where(bubble: user_bubbles, creator: Current.account.users)
|
||||
end
|
||||
|
||||
def user_bubbles
|
||||
Current.user.accessible_bubbles
|
||||
.published_or_drafted_by(Current.user)
|
||||
.where(bucket_id: bucket_filter)
|
||||
end
|
||||
end
|
||||
@@ -1,47 +1,13 @@
|
||||
class EventsController < ApplicationController
|
||||
include BucketFilterable
|
||||
before_action :set_activity_day
|
||||
include EventsTimeline
|
||||
|
||||
def index
|
||||
update_bucket_filter
|
||||
|
||||
@buckets = Current.user.buckets.alphabetically
|
||||
@events = events_by_hour_and_column
|
||||
@filters = Current.user.filters.all
|
||||
@next_day = latest_event_before_today&.created_at
|
||||
|
||||
@events = events_for_activity_day
|
||||
@next_day = latest_event_before_activity_day&.created_at
|
||||
end
|
||||
|
||||
private
|
||||
def events_by_hour_and_column
|
||||
user_events.where(created_at: @activity_day.all_day).
|
||||
group_by { |event| [ event.created_at.hour, helpers.event_column(event) ] }.
|
||||
map { |hour_col, events|
|
||||
[ hour_col,
|
||||
events.uniq { |e| e.action == "boosted" ? [ e.creator_id, e.bubble_id ] : e.id }
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
def latest_event_before_today
|
||||
user_events.where(created_at: ...@activity_day.beginning_of_day).chronologically.last
|
||||
end
|
||||
|
||||
def user_events
|
||||
Event.where(bubble: user_bubbles, creator: Current.account.users)
|
||||
end
|
||||
|
||||
def user_bubbles
|
||||
Current.user.accessible_bubbles
|
||||
.published_or_drafted_by(Current.user)
|
||||
.where(bucket_id: bucket_filter)
|
||||
end
|
||||
|
||||
def set_activity_day
|
||||
@activity_day = if params[:day].present?
|
||||
Time.zone.parse(params[:day])
|
||||
else
|
||||
Time.zone.now
|
||||
end
|
||||
rescue ArgumentError
|
||||
raise ActionController::RoutingError
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user