From: Tom Hughes Date: Sat, 2 Feb 2013 13:04:27 +0000 (+0000) Subject: Improve display of anonymous note comments X-Git-Tag: live~5068^2~44 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/2ef58f47a232c8a8156dd148616c198790e489d2 Improve display of anonymous note comments --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9676e6ee1..3771acf37 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -99,12 +99,4 @@ module ApplicationHelper def friendly_date(date) content_tag(:span, time_ago_in_words(date), :title => l(date, :format => :friendly)) end - - def note_author(object, link_options = {}) - if object.author.nil? - "" - else - link_to h(object.author.display_name), link_options.merge({:controller => "user", :action => "view", :display_name => object.author.display_name}) - end - end end diff --git a/app/helpers/note_helper.rb b/app/helpers/note_helper.rb new file mode 100644 index 000000000..bfd7f493d --- /dev/null +++ b/app/helpers/note_helper.rb @@ -0,0 +1,13 @@ +module NoteHelper + def note_event(at, by) + if by.nil? + I18n.t("browse.note.at_html", :when => friendly_date(at)).html_safe + else + I18n.t("browse.note.at_by_html", :when => friendly_date(at), :user => note_author(by)).html_safe + end + end + + def note_author(author, link_options = {}) + link_to h(author.display_name), link_options.merge({:controller => "user", :action => "view", :display_name => author.display_name}) + end +end diff --git a/app/views/browse/note.html.erb b/app/views/browse/note.html.erb index ec4f8d3ae..a89ad07e5 100644 --- a/app/views/browse/note.html.erb +++ b/app/views/browse/note.html.erb @@ -18,18 +18,18 @@

<%= t "browse.note.opened" %>

-

<%= t "browse.note.at_by_html", :when => friendly_date(@note.created_at), :user => note_author(@note) %>

+

<%= note_event(@note.created_at, @note.author) %>

<% if @note.status == "closed" %>

<%= t "browse.note.closed" %>

-

<%= t "browse.note.at_by_html", :when => friendly_date(@note.closed_at), :user => note_author(@note.comments.last) %>

+

<%= note_event(@note.closed_at, @note.comments.last.author) %>

<% elsif @note.comments.length > 1 %>

<%= t "browse.note.last_modified" %>

-

<%= t "browse.note.at_by_html", :when => friendly_date(@note.updated_at), :user => note_author(@note.comments.last) %>

+

<%= note_event(@note.updated_at, @note.comments.last.author) %>

<% end %> @@ -51,7 +51,7 @@ <% @note.comments[1..-1].each do |comment| %>
  • <%= comment.body.to_html %> - <%= t "browse.note.at_by_html", :when => friendly_date(comment.created_at), :user => note_author(comment) %> + <%= note_event(comment.created_at, comment.author) %>
  • <% end %> diff --git a/app/views/notes/_description.html.erb b/app/views/notes/_description.html.erb index 596d63269..435f263c6 100644 --- a/app/views/notes/_description.html.erb +++ b/app/views/notes/_description.html.erb @@ -1,7 +1,11 @@
    <% description.comments.each do |comment| -%>
    -
    <%= t "note.description.#{comment.event}_at_by", :when => friendly_date(comment.created_at), :user => note_author(comment, :only_path => false) %>
    + <% if comment.author.nil> -%> +
    <%= t "note.description.#{comment.event}_at", :when => friendly_date(comment.created_at) %>
    + <% else -%> +
    <%= t "note.description.#{comment.event}_at_by", :when => friendly_date(comment.created_at), :user => note_author(comment.author, :only_path => false) %>
    + <% end -%>
    <%= comment.body %>
    <% end -%> diff --git a/config/locales/en.yml b/config/locales/en.yml index 8d45dfe26..f64b833b0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -288,6 +288,7 @@ en: opened: "Opened:" last_modified: "Last modified:" closed: "Closed:" + at_html: "%{when} ago" at_by_html: "%{when} ago by %{user}" description: "Description:" comments: "Comments:" @@ -1979,9 +1980,13 @@ en: needs_view: "The user needs to log in before this block will be cleared." note: description: + opened_at: "Created %{when} ago" opened_at_by: "Created %{when} ago by %{user}" + commented_at: "Updated %{when} ago" commented_at_by: "Updated %{when} ago by %{user}" + closed_at: "Resolved %{when} ago" closed_at_by: "Resolved %{when} ago by %{user}" + reopened_at: "Reactivated %{when} ago" reopened_at_by: "Reactivated %{when} ago by %{user}" rss: title: "OpenStreetMap Notes"