Merge pull request #324 from basecamp/flavorjones-refactor-events-index
Extract pagination for "Latest activity" to `Events::PagesController`
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
|
||||
@@ -0,0 +1,8 @@
|
||||
class Events::DaysController < ApplicationController
|
||||
include EventsTimeline
|
||||
|
||||
def index
|
||||
@events = events_for_activity_day
|
||||
@next_day = latest_event_before_activity_day&.created_at
|
||||
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
|
||||
|
||||
@@ -29,7 +29,7 @@ module EventsHelper
|
||||
def event_next_page_link(next_day)
|
||||
if next_day
|
||||
tag.div id: "next_page",
|
||||
data: { controller: "fetch-on-visible", fetch_on_visible_url_value: events_path(day: next_day.strftime("%Y-%m-%d")) }
|
||||
data: { controller: "fetch-on-visible", fetch_on_visible_url_value: events_days_path(day: next_day.strftime("%Y-%m-%d")) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<% events.each do | hour_column, cluster| %>
|
||||
<%= event_cluster_tag(*hour_column) do %>
|
||||
<%= render cluster.sort_by(&:created_at).reverse %>
|
||||
<%= render partial: "events/event", collection: cluster.sort_by(&:created_at).reverse %>
|
||||
|
||||
<%= local_datetime_tag cluster.first.created_at, class: "event__timestamp txt-small translucent" %>
|
||||
<% end %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="panel shadow center margin-block-double <%= "shake" if flash[:alert] %>" style="--panel-size: 55ch;">
|
||||
<h1 class="txt-xx-large margin-block-end-double">Fizzy</h1>
|
||||
|
||||
<%= form_with model: User.new, url: first_run_path, class: "flex flex-column gap txt-large", data: { turbo: false } do |form| %>
|
||||
<%= form_with model: User.new, url: first_run_path, class: "flex flex-column gap txt-large" do |form| %>
|
||||
<div class="flex align-center gap">
|
||||
<%= translation_button :user_name %>
|
||||
<label class="flex align-center gap input input--actor txt-large">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="panel shadow center margin-block-double <%= "shake" if flash[:alert] %>" style="--panel-size: 55ch;">
|
||||
<h1 class="txt-xx-large margin-block-end-double">Fizzy</h1>
|
||||
|
||||
<%= form_with url: session_path, class: "flex flex-column gap txt-large", data: { turbo: false } do |form| %>
|
||||
<%= form_with url: session_path, class: "flex flex-column gap txt-large" do |form| %>
|
||||
<div class="flex align-center gap">
|
||||
<%= translation_button :email_address %>
|
||||
<label class="flex align-center gap input input--actor">
|
||||
|
||||
+5
-1
@@ -65,7 +65,11 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resources :events
|
||||
resources :events, only: :index
|
||||
namespace :events do
|
||||
resources :days
|
||||
end
|
||||
|
||||
resources :filters
|
||||
resource :first_run
|
||||
resources :qr_codes
|
||||
|
||||
Reference in New Issue
Block a user