From b719252ec4bfc4d6c91d652fe759acde877cfb13 Mon Sep 17 00:00:00 2001 From: Robert Koeze Date: Tue, 29 Apr 2025 22:28:18 -0400 Subject: [PATCH] Add headline to heatmap --- app/controllers/users_controller.rb | 2 ++ app/views/users/show.html.erb | 3 +++ config/locales/en.yml | 3 +++ test/controllers/users_controller_test.rb | 29 +++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 58ed0c48a..bcd9031b4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -43,6 +43,8 @@ class UsersController < ApplicationController } end end + + @changes_count = @heatmap_data.sum { |entry| entry[:total_changes] } else render_unknown_user params[:display_name] end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index ace1d06a4..2dbe72c34 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -248,6 +248,9 @@
<%= @user.description.to_html %>
<% if @heatmap_data.present? %> +

+ <%= t(".contributions", :count => @changes_count) %> +

diff --git a/config/locales/en.yml b/config/locales/en.yml index 1500b2e6a..e13db4acf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2939,6 +2939,9 @@ en: delete_user: "Delete this User" confirm: "Confirm" report: Report this User + contributions: + one: "%{count} contribution in the last year" + other: "%{count} contributions in the last year" go_public: flash success: "All your edits are now public, and you are now allowed to edit." issued_blocks: diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 5066faec3..0dc06a7f9 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -423,4 +423,33 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_equal expected_data, heatmap_data end end + + def test_heatmap_headline_changset_zero + user = create(:user) + + get user_path(user) + + assert_response :success + assert_select "h2.text-body-secondary.fs-5", :count => 0 + end + + def test_heatmap_headline_changeset_singular + user = create(:user) + create(:changeset, :user => user, :created_at => 4.months.ago.beginning_of_day, :num_changes => 1) + + get user_path(user) + + assert_response :success + assert_select "h2.text-body-secondary.fs-5", :text => "1 contribution in the last year" + end + + def test_heatmap_headline_changeset_plural + user = create(:user) + create(:changeset, :user => user, :created_at => 4.months.ago.beginning_of_day, :num_changes => 12) + + get user_path(user) + + assert_response :success + assert_select "h2.text-body-secondary.fs-5", :text => "12 contributions in the last year" + end end -- 2.39.5