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.
module NoteHelper
include ActionView::Helpers::TranslationHelper
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"))
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"))
</td>
<td><%= link_to note.id, note %></td>
<td><%= note_author(note.author) %></td>
</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>
<td><%= friendly_date_ago(note.created_at) %></td>
<td><%= friendly_date_ago(note.updated_at) %></td>
</tr>
<div>
<h4><%= t(".description") %></h4>
<div class="overflow-hidden ms-2">
<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 %>">
</div>
<div class="details" data-coordinates="<%= @note.lat %>,<%= @note.lon %>" data-status="<%= @note.status %>">
closed_title: "Resolved note #%{note_name}"
hidden_title: "Hidden note #%{note_name}"
description_when_author_is_deleted: "deleted"
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}"
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}"