]> git.openstreetmap.org Git - rails.git/commitdiff
Improves notes_description helper routine
authorNenad Vujicic <nenadus@gmail.com>
Wed, 19 Feb 2025 15:07:45 +0000 (16:07 +0100)
committerNenad Vujicic <nenadus@gmail.com>
Fri, 21 Feb 2025 12:31:07 +0000 (13:31 +0100)
Improves notes_description helper routine to return "unknown" for cases when first note's comment doesn't have event set to "opened" or note doesn't have comments. Added new argument (note's first comment), also updated helper routines usages.

app/helpers/note_helper.rb
app/views/notes/index.html.erb
app/views/notes/show.html.erb
config/locales/en.yml

index 0ba5032288b7c7b7ebb9803a00fc230506372775..7a75a4ff53c22ea2b0da5816978e03bf8846ea1a 100644 (file)
@@ -1,9 +1,11 @@
 module NoteHelper
   include ActionView::Helpers::TranslationHelper
 
-  def note_description(author, description)
+  def note_description(author, description, first_comment)
     if !author.nil? && author.status == "deleted"
       RichText.new("text", t("notes.show.description_when_author_is_deleted"))
+    elsif first_comment&.event != "opened"
+      RichText.new("text", t("notes.show.description_when_there_is_no_opening_comment"))
     else
       description
     end
index 0b39234a93e61f2eaf222b0e221906f48bf8c567..4bd7d499d3da7acec77a8996842a450e662c5e26 100644 (file)
@@ -48,7 +48,7 @@
       </td>
       <td><%= link_to note.id, note %></td>
       <td><%= note_author(note.author) %></td>
-      <td><%= note_description(note.author, note.description).to_html %></td>
+      <td><%= note_description(note.author, note.description, current_user&.moderator? ? note.comments.unscope(:where => :visible).first : note.comments.first).to_html %></td>
       <td><%= friendly_date_ago(note.created_at) %></td>
       <td><%= friendly_date_ago(note.updated_at) %></td>
     </tr>
index b65926b5f9df335fd7abbcfda573cfef93ad8c8c..d0dcdeb1b9417354c01f5e9830011b8d980a876b 100644 (file)
@@ -5,7 +5,7 @@
 <div>
   <h4><%= t(".description") %></h4>
   <div class="overflow-hidden ms-2">
-    <%= note_description(@note.author, @note.description).to_html %>
+    <%= note_description(@note.author, @note.description, current_user&.moderator? ? @note.comments.unscope(:where => :visible).first : @note.comments.first).to_html %>
   </div>
 
   <div class="details" data-coordinates="<%= @note.lat %>,<%= @note.lon %>" data-status="<%= @note.status %>">
index dd7ae4033841195b001ab689f0757bdc5d50bd32..f03a6eeb1f6ae418100d83b6c16aa4e8fae4be19 100644 (file)
@@ -3095,6 +3095,7 @@ en:
       closed_title: "Resolved note #%{note_name}"
       hidden_title: "Hidden note #%{note_name}"
       description_when_author_is_deleted: "deleted"
+      description_when_there_is_no_opening_comment: "unknown"
       event_opened_by_html: "Created by %{user} %{time_ago}"
       event_opened_by_anonymous_html: "Created by anonymous %{time_ago}"
       event_commented_by_html: "Comment from %{user} %{time_ago}"