From 78c2752670aef4d799150b06c7af7e1d5bd869db Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Thu, 17 Oct 2024 14:28:06 +0300 Subject: [PATCH] Replace submitted note table color with created/resolved --- app/assets/stylesheets/common.scss | 8 +++- app/helpers/note_helper.rb | 13 ++++++ app/views/notes/index.html.erb | 14 ++++--- config/locales/en.yml | 8 ++-- test/controllers/notes_controller_test.rb | 11 ++++++ test/helpers/note_helper_test.rb | 48 +++++++++++++++++++++++ 6 files changed, 92 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index c1728f870..c5761eeb6 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -64,7 +64,13 @@ time[title] { .table-success { --bs-table-bg: rgb(var(--bs-success-rgb), .25); } - .table-primary, .table-secondary, .table-success { + .table-warning { + --bs-table-bg: rgb(var(--bs-warning-rgb), .25); + } + .table-danger { + --bs-table-bg: rgb(var(--bs-danger-rgb), .25); + } + .table-primary, .table-secondary, .table-success, .table-warning, .table-danger { --bs-table-color: initial; border-color: inherit; } diff --git a/app/helpers/note_helper.rb b/app/helpers/note_helper.rb index 7a75a4ff5..d32a11589 100644 --- a/app/helpers/note_helper.rb +++ b/app/helpers/note_helper.rb @@ -32,4 +32,17 @@ module NoteHelper :class => "mw-100 d-inline-block align-bottom text-truncate text-wrap", :dir => "auto" end end + + def note_list_row_class(note, user) + opened_by_user = note.author == user + closed_by_user = note.comments.last&.author == user && note.comments.last&.event == "closed" + + if opened_by_user && closed_by_user + "table-warning" + elsif opened_by_user + "table-danger" + elsif closed_by_user + "table-success" + end + end end diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index 4bd7d499d..bc1a069eb 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -1,9 +1,11 @@ <% content_for :heading do %>

<%= t ".heading", :user => @user.display_name %>

-

<%= t ".subheading_html", - :user => link_to(@user.display_name, @user), - :submitted => tag.span(t(".subheading_submitted"), :class => "px-2 py-1 bg-primary bg-opacity-25"), - :commented => tag.span(t(".subheading_commented"), :class => "px-2 py-1 bg-body") %>

+

<%= t ".legend_html", + :user => link_to(@user.display_name, @user), + :created => tag.span(t(".legend_created"), :class => "px-2 py-1 bg-danger bg-opacity-25"), + :created_and_resolved => tag.span(t(".legend_created_and_resolved"), :class => "px-2 py-1 bg-warning bg-opacity-25"), + :resolved => tag.span(t(".legend_resolved"), :class => "px-2 py-1 bg-success bg-opacity-25"), + :interacted => tag.span(t(".legend_interacted"), :class => "px-2 py-1 bg-body") %>

<% end %> <%= form_with :url => user_notes_path(@user), :method => :get, :data => { :turbo => true } do %> @@ -38,7 +40,7 @@ <% @notes.each do |note| -%> - class="table-primary"<% end %>> + <%= tag.tr :class => note_list_row_class(note, @user) do %> <% if note.closed? %> <%= image_tag("closed_note_marker.svg", :alt => "closed", :width => 25, :height => 40) %> @@ -51,7 +53,7 @@ <%= note_description(note.author, note.description, current_user&.moderator? ? note.comments.unscope(:where => :visible).first : note.comments.first).to_html %> <%= friendly_date_ago(note.created_at) %> <%= friendly_date_ago(note.updated_at) %> - + <% end %> <% end -%> diff --git a/config/locales/en.yml b/config/locales/en.yml index b56fb6410..12fedbd5c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3083,9 +3083,11 @@ en: index: title: "Notes submitted or commented on by %{user}" heading: "%{user}'s Notes" - subheading_html: "Notes %{submitted} or %{commented} by %{user}" - subheading_submitted: "submitted" - subheading_commented: "commented on" + legend_html: "Notes %{created}, %{created_and_resolved}, %{resolved} or %{interacted} by %{user}" + legend_created: "created" + legend_created_and_resolved: "created and resolved" + legend_resolved: "resolved" + legend_interacted: "with other interactions" no_notes: No notes id: "Id" creator: "Creator" diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index 0185c6741..57b0378d0 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -67,6 +67,17 @@ class NotesControllerTest < ActionDispatch::IntegrationTest assert_response :not_found end + def test_index_interaction_created_and_resolved + user = create(:user) + note = create(:note) + create(:note_comment, :note => note, :author => user) + create(:note_comment, :note => note, :author => user, :event => "closed") + + get user_notes_path(user) + assert_response :success + assert_dom "table.note_list tbody tr:not(.table-danger).table-warning:not(.table-success)", :count => 1 + end + def test_index_paged user = create(:user) diff --git a/test/helpers/note_helper_test.rb b/test/helpers/note_helper_test.rb index 8b8173694..b8e515128 100644 --- a/test/helpers/note_helper_test.rb +++ b/test/helpers/note_helper_test.rb @@ -47,4 +47,52 @@ class NoteHelperTest < ActionView::TestCase assert_dom "> @href", "http://test.host/user/#{ERB::Util.u(user.display_name)}" end end + + def test_note_list_row_class_created + user = create(:user) + note = create(:note) + create(:note_comment, :note => note, :author => user) + + assert_equal "table-danger", note_list_row_class(note, user) + end + + def test_note_list_row_class_created_and_resolved + user = create(:user) + note = create(:note) + create(:note_comment, :note => note, :author => user) + create(:note_comment, :note => note, :author => user, :event => "closed") + + assert_equal "table-warning", note_list_row_class(note, user) + end + + def test_note_list_row_class_resolved + user = create(:user) + other_user = create(:user) + note = create(:note) + create(:note_comment, :note => note, :author => other_user) + create(:note_comment, :note => note, :author => user, :event => "closed") + + assert_equal "table-success", note_list_row_class(note, user) + end + + def test_note_list_row_class_resolved_and_reopened_by_other_user + user = create(:user) + other_user = create(:user) + note = create(:note) + create(:note_comment, :note => note, :author => other_user) + create(:note_comment, :note => note, :author => user, :event => "closed") + create(:note_comment, :note => note, :author => other_user, :event => "reopened") + + assert_nil note_list_row_class(note, user) + end + + def test_note_list_row_class_commented + user = create(:user) + other_user = create(:user) + note = create(:note) + create(:note_comment, :note => note, :author => other_user) + create(:note_comment, :note => note, :author => user, :event => "commented") + + assert_nil note_list_row_class(note, user) + end end