Improves notes_description helper routine

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.
This commit is contained in:
Nenad Vujicic 2025-02-19 16:07:45 +01:00
parent bdf3abeb07
commit f8fb850e8c
4 changed files with 6 additions and 3 deletions

View 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

View 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>

View 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 %>">

View 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}"