Extract events loading from overloaded UsersController
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
class Users::EventsController < ApplicationController
|
||||
include FilterScoped
|
||||
|
||||
before_action :set_user, :set_filter, :set_user_filtering
|
||||
|
||||
def show
|
||||
@filter = Current.user.filters.new(creator_ids: [ @user.id ])
|
||||
@day_timeline = Current.user.timeline_for(day_param, filter: @filter)
|
||||
end
|
||||
|
||||
private
|
||||
def set_user
|
||||
@user = User.active.find(params[:user_id])
|
||||
end
|
||||
|
||||
def day_param
|
||||
if params[:day].present?
|
||||
Time.zone.parse(params[:day])
|
||||
else
|
||||
Time.current
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,14 +1,9 @@
|
||||
class UsersController < ApplicationController
|
||||
include FilterScoped
|
||||
|
||||
require_access_without_a_user only: %i[ new create ]
|
||||
|
||||
before_action :set_join_code, only: %i[ new create]
|
||||
before_action :ensure_join_code_is_valid, only: %i[ new create ]
|
||||
before_action :set_join_code, :ensure_join_code_is_valid, only: %i[ new create ]
|
||||
before_action :set_user, only: %i[ show edit update destroy ]
|
||||
before_action :ensure_permission_to_change_user, only: %i[ update destroy ]
|
||||
before_action :set_filter, only: %i[ edit show ]
|
||||
before_action :set_user_filtering, only: %i[ edit show]
|
||||
|
||||
def new
|
||||
end
|
||||
@@ -25,8 +20,6 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
@filter = Current.user.filters.new(creator_ids: [ @user.id ])
|
||||
@day_timeline = Current.user.timeline_for(day_param, filter: @filter)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -58,14 +51,6 @@ class UsersController < ApplicationController
|
||||
head :forbidden unless Current.user.can_change?(@user)
|
||||
end
|
||||
|
||||
def day_param
|
||||
if params[:day].present?
|
||||
Time.zone.parse(params[:day])
|
||||
else
|
||||
Time.current
|
||||
end
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.expect(user: [ :name, :avatar ])
|
||||
end
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<turbo-frame id="user_events">
|
||||
<h1 class="font-weight-black txt-large margin-block-double"><%= "What #{Current.user == @user ? "have you" : "has #{@user.first_name}"} been up to?" %></h1>
|
||||
|
||||
<div class="events margin-block-double" id="activity" data-controller="pagination" data-pagination-paginate-on-intersection-value="true">
|
||||
<%= day_timeline_pagination_frame_tag @day_timeline do %>
|
||||
<%= render "events/day", day_timeline: @day_timeline %>
|
||||
|
||||
<% if @day_timeline.next_day %>
|
||||
<%= link_to "Load more…", user_events_path(@user, day: @day_timeline.next_day.strftime("%Y-%m-%d"), **@filter.as_params),
|
||||
class: "day-timeline-pagination-link", data: { frame: day_timeline_pagination_frame_id_for(@day_timeline.next_day), pagination_target: "paginationLink" } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</turbo-frame>
|
||||
@@ -1,8 +1,5 @@
|
||||
<% @page_title = @user.name %>
|
||||
|
||||
<% content_for :header do %>
|
||||
<%= render "my/menus/menu" %>
|
||||
<% end %>
|
||||
<% me_or_you = Current.user == @user ? "me" : @user.first_name %>
|
||||
|
||||
<div class="profile-layout">
|
||||
<section class="panel shadow txt-align-center" style="--panel-size: 45ch;">
|
||||
@@ -30,8 +27,10 @@
|
||||
</div>
|
||||
|
||||
<div class="flex-inline center justify-center flex-wrap gap">
|
||||
<%= link_to "Which cards are assigned to #{ Current.user == @user ? "me" : @user.first_name }?", cards_path(assignee_ids: [@user.id], sorted_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
|
||||
<%= link_to "Which cards were added by #{ Current.user == @user ? "me" : @user.first_name }?", cards_path(creator_ids: [@user.id], sorted_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
|
||||
<%= link_to "Which cards are assigned to #{me_or_you}?",
|
||||
cards_path(assignee_ids: [ @user.id ], sorted_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
|
||||
<%= link_to "Which cards were added by #{me_or_you}?",
|
||||
cards_path(creator_ids: [ @user.id ], sorted_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -49,10 +48,4 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h1 class="font-weight-black txt-large margin-block-double"><%= "What #{ Current.user == @user ? "have you" : "has #{ @user.first_name }" } been up to?" %></h1>
|
||||
|
||||
<%= render "users/activity_timeline", user: @user, day_timeline: @day_timeline, filter: @filter %>
|
||||
<%= turbo_frame_tag "user_events", src: user_events_path(@user) %>
|
||||
|
||||
+5
-2
@@ -7,8 +7,11 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
resources :users do
|
||||
resource :role, module: :users
|
||||
resources :push_subscriptions, module: :users
|
||||
scope module: :users do
|
||||
resource :role
|
||||
resource :events
|
||||
resources :push_subscriptions
|
||||
end
|
||||
end
|
||||
|
||||
resources :collections do
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
require "test_helper"
|
||||
|
||||
class Users::EventsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
end
|
||||
|
||||
test "show self" do
|
||||
get user_events_path(users(:kevin))
|
||||
assert_in_body "What have you been up to?"
|
||||
end
|
||||
|
||||
test "show other" do
|
||||
get user_events_path(users(:david))
|
||||
assert_in_body "What has David been up to?"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user