]> git.openstreetmap.org Git - rails.git/blob - app/helpers/note_helper.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / app / helpers / note_helper.rb
1 # frozen_string_literal: true
2
3 module NoteHelper
4   include ActionView::Helpers::TranslationHelper
5
6   def note_description(author, description, first_comment)
7     if !author.nil? && author.status == "deleted"
8       RichText.new("text", t("notes.show.description_when_author_is_deleted"))
9     elsif first_comment&.event != "opened"
10       RichText.new("text", t("notes.show.description_when_there_is_no_opening_comment"))
11     else
12       description
13     end
14   end
15
16   def note_event(event, at, by)
17     if by.nil?
18       t("notes.show.event_#{event}_by_anonymous_html",
19         :time_ago => friendly_date_ago(at))
20     else
21       t("notes.show.event_#{event}_by_html",
22         :time_ago => friendly_date_ago(at),
23         :user => note_author(by))
24     end
25   end
26
27   def note_author(author, link_options = {})
28     if author.nil?
29       ""
30     elsif author.status == "deleted"
31       t("users.no_such_user.deleted")
32     else
33       link_to h(author.display_name), link_options.merge(:controller => "/users", :action => "show", :display_name => author.display_name),
34               :class => "mw-100 d-inline-block align-bottom text-truncate text-wrap", :dir => "auto"
35     end
36   end
37 end