diff --git a/app/controllers/users/events_controller.rb b/app/controllers/users/events_controller.rb new file mode 100644 index 000000000..76b85dd58 --- /dev/null +++ b/app/controllers/users/events_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 811261c87..8b89fc0e4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/users/events/show.html.erb b/app/views/users/events/show.html.erb new file mode 100644 index 000000000..17ec2c1b3 --- /dev/null +++ b/app/views/users/events/show.html.erb @@ -0,0 +1,14 @@ + +

<%= "What #{Current.user == @user ? "have you" : "has #{@user.first_name}"} been up to?" %>

+ +
+ <%= 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 %> +
+
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 9e49972f1..1ae06e2c0 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -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 %>
@@ -30,8 +27,10 @@
- <%= 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" } %>
@@ -49,10 +48,4 @@ <% end %> - - - - -

<%= "What #{ Current.user == @user ? "have you" : "has #{ @user.first_name }" } been up to?" %>

- -<%= render "users/activity_timeline", user: @user, day_timeline: @day_timeline, filter: @filter %> +<%= turbo_frame_tag "user_events", src: user_events_path(@user) %> diff --git a/config/routes.rb b/config/routes.rb index dc8df0d44..15c162207 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/controllers/users/events_controller_test.rb b/test/controllers/users/events_controller_test.rb new file mode 100644 index 000000000..97cb85b2e --- /dev/null +++ b/test/controllers/users/events_controller_test.rb @@ -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