From 7ee65608c96a4eae1aaf9e030f402a5d585bed98 Mon Sep 17 00:00:00 2001 From: Jason Zimdars Date: Thu, 22 May 2025 16:18:28 -0500 Subject: [PATCH] Show user's activity right on their profile screen --- .../concerns/user_timeline_scoped.rb | 12 +++ app/controllers/users_controller.rb | 5 +- app/views/events/_empty_days.html.erb | 2 +- app/views/users/edit.html.erb | 88 +++++++++---------- app/views/users/show.html.erb | 50 ++++++----- 5 files changed, 85 insertions(+), 72 deletions(-) create mode 100644 app/controllers/concerns/user_timeline_scoped.rb diff --git a/app/controllers/concerns/user_timeline_scoped.rb b/app/controllers/concerns/user_timeline_scoped.rb new file mode 100644 index 000000000..6e46ce8d1 --- /dev/null +++ b/app/controllers/concerns/user_timeline_scoped.rb @@ -0,0 +1,12 @@ +module UserTimelineScoped + extend ActiveSupport::Concern + + included do + include FilterScoped + end + + def show + @filter = Current.user.filters.new(creator_ids: [ @user.id ]) + @day_timeline = Current.user.timeline_for(Time.current, filter: @filter) + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3dfd0d26a..2915b81bc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + include UserTimelineScoped require_unauthenticated_access only: %i[ new create ] before_action :set_user, only: %i[ show edit update destroy ] @@ -6,6 +7,7 @@ class UsersController < ApplicationController before_action :ensure_permission_to_change_user, only: %i[ update destroy ] def index + @filters = Current.user.filters.all @users = User.active end @@ -19,9 +21,6 @@ class UsersController < ApplicationController redirect_to root_path end - def show - end - def edit end diff --git a/app/views/events/_empty_days.html.erb b/app/views/events/_empty_days.html.erb index 98b8bd8a4..cb5e6cb27 100644 --- a/app/views/events/_empty_days.html.erb +++ b/app/views/events/_empty_days.html.erb @@ -14,6 +14,6 @@ <% end %> <% else %>
-

No more activity.

+

No more activity

<% end %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 055baab38..536c7d370 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -6,55 +6,53 @@ <% end %> -<%= turbo_frame_tag dom_id(@user) do %> -
-
- <%= form_with model: @user, method: :patch, class: "flex flex-column gap", data: { controller: "form upload-preview" } do |form| %> -
- +
+
+ <%= form_with model: @user, method: :patch, class: "flex flex-column gap", data: { controller: "form upload-preview" } do |form| %> +
+ - + - <% if @user.avatar.attached? %> - <%= tag.button type: :submit, form: "avatar-delete-form", class: "btn btn--negative txt-small", data: { turbo_confirm: "Are you sure you want to remove your avatar? This can't be undone." } do %> - <%= icon_tag "minus" %> - Delete avatar - <% end %> + <% if @user.avatar.attached? %> + <%= tag.button type: :submit, form: "avatar-delete-form", class: "btn btn--negative txt-small", data: { turbo_confirm: "Are you sure you want to remove your avatar? This can't be undone." } do %> + <%= icon_tag "minus" %> + Delete avatar <% end %> -
+ <% end %> +
-
- -
-
- -
-
- -
- +
+ +
+
+ +
+
+ +
+ - <%= link_to "Cancel and go back", user_path(@user), data: { form_target: "cancel", turbo_frame: "_top" }, hidden: true %> - <% end %> + <%= link_to "Cancel and go back", user_path(@user), data: { form_target: "cancel", turbo_frame: "_top" }, hidden: true %> + <% end %> - <%= form_with url: user_avatar_url(@user), method: :delete, id: "avatar-delete-form" %> -
+ <%= form_with url: user_avatar_url(@user), method: :delete, id: "avatar-delete-form" %>
-<% end %> +
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 758c3eeec..eeca42733 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -5,7 +5,7 @@ <%= link_to_back %> <% if Current.user == @user %> - <%= link_to edit_user_path(@user), class: "btn flex-item-justify-end", data: { turbo_frame: dom_id(@user) } do %> + <%= link_to edit_user_path(@user), class: "btn flex-item-justify-end" do %> <%= icon_tag "pencil" %> Edit <% end %> @@ -13,32 +13,29 @@ <% end %> -<%= turbo_frame_tag dom_id(@user) do %> -
-
-
- <%= image_tag user_avatar_path(@user), alt: "Profile avatar for #{@user.name}", class: "avatar", size: 128 %> -
+
+
+
+ <%= image_tag user_avatar_path(@user), alt: "Profile avatar for #{@user.name}", class: "avatar", size: 128 %> +
-
-

<%= @user.name %>

-
- <% if @user.active? %> - <%= mail_to @user.email_address %> - <% else %> - <%= @user.name %> is no longer on this account - <% end %> -
-
- -
- <%= link_to "What #{ Current.user == @user ? "have you" : "#{ @user.first_name } has" } been up to?", events_path(creator_ids: [@user.id]), class: "btn", data: { turbo_frame: "_top" } %> - <%= link_to "Which cards are assigned to #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(assignee_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %> - <%= link_to "Which cards were added by #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(creator_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %> +
+

<%= @user.name %>

+
+ <% if @user.active? %> + <%= mail_to @user.email_address %> + <% else %> + <%= @user.name %> is no longer on this account + <% end %>
+ +
+ <%= link_to "Which cards are assigned to #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(assignee_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %> + <%= link_to "Which cards were added by #{ Current.user == @user ? "you" : @user.first_name }?", cards_path(creator_ids: [@user.id], indexed_by: "newest"), class: "btn", data: { turbo_frame: "_top" } %> +
-<% end %> +
<% if Current.user == @user %>
@@ -52,3 +49,10 @@ <% end %>
<% end %> + +

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

+ +
+ <%= render "events/day", day_timeline: @day_timeline %> + <%= event_next_page_link(@day_timeline.next_day) %> +