From: Nenad Vujicic Date: Wed, 19 Feb 2025 15:07:45 +0000 (+0100) Subject: Improves notes_description helper routine X-Git-Tag: live~6^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f8fb850e8c1b0f9fc20f13bfbc9552fd5f897a76?ds=inline;hp=-c 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. --- f8fb850e8c1b0f9fc20f13bfbc9552fd5f897a76 diff --git a/app/helpers/note_helper.rb b/app/helpers/note_helper.rb index 0ba503228..7a75a4ff5 100644 --- a/app/helpers/note_helper.rb +++ b/app/helpers/note_helper.rb @@ -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 diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index 0b39234a9..4bd7d499d 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -48,7 +48,7 @@ <%= link_to note.id, note %> <%= note_author(note.author) %> - <%= 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 %> <%= friendly_date_ago(note.created_at) %> <%= friendly_date_ago(note.updated_at) %> diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index b65926b5f..d0dcdeb1b 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -5,7 +5,7 @@

<%= t(".description") %>

- <%= 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 %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index dd7ae4033..f03a6eeb1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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}"