Improve display of anonymous note comments
authorTom Hughes <tom@compton.nu>
Sat, 2 Feb 2013 13:04:27 +0000 (13:04 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 2 Feb 2013 13:04:27 +0000 (13:04 +0000)
app/helpers/application_helper.rb
app/helpers/note_helper.rb [new file with mode: 0644]
app/views/browse/note.html.erb
app/views/notes/_description.html.erb
config/locales/en.yml

index 9676e6e..3771acf 100644 (file)
@@ -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 (file)
index 0000000..bfd7f49
--- /dev/null
@@ -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
index ec4f8d3..a89ad07 100644 (file)
   <div class='browse-section common'>
     <div>
       <h4><%= t "browse.note.opened" %></h4>
-      <p><%= t "browse.note.at_by_html", :when => friendly_date(@note.created_at), :user => note_author(@note) %></p>
+      <p><%= note_event(@note.created_at, @note.author) %></p>
     </div>
 
     <% if @note.status == "closed" %>
       <div>
         <h4><%= t "browse.note.closed" %></h4>
-        <p><%= t "browse.note.at_by_html", :when => friendly_date(@note.closed_at), :user => note_author(@note.comments.last) %></p>
+        <p><%= note_event(@note.closed_at, @note.comments.last.author) %></p>
       </div>  
     <% elsif @note.comments.length > 1 %>
       <div>
         <h4><%= t "browse.note.last_modified" %></h4>
-        <p><%= t "browse.note.at_by_html", :when => friendly_date(@note.updated_at), :user => note_author(@note.comments.last) %></p>
+        <p><%= note_event(@note.updated_at, @note.comments.last.author) %></p>
       </div>  
     <% end %>
 
@@ -51,7 +51,7 @@
         <% @note.comments[1..-1].each do |comment| %>
           <li>
             <%= comment.body.to_html %>
-            <small class="deemphasize"><%= t "browse.note.at_by_html", :when => friendly_date(comment.created_at), :user => note_author(comment) %></small>
+            <small class="deemphasize"><%= note_event(comment.created_at, comment.author) %></small>
           </li>
         <% end %>
       </ul>
index 596d632..435f263 100644 (file)
@@ -1,7 +1,11 @@
 <div>
   <% description.comments.each do |comment| -%>
   <div class="note-comment" style="margin-top: 5px">
-    <div class="note-comment-description" style="font-size: smaller; color: #999999"><%= t "note.description.#{comment.event}_at_by", :when => friendly_date(comment.created_at), :user => note_author(comment, :only_path => false) %></div>
+    <% if comment.author.nil> -%>
+    <div class="note-comment-description" style="font-size: smaller; color: #999999"><%= t "note.description.#{comment.event}_at", :when => friendly_date(comment.created_at) %></div>
+    <% else -%>
+    <div class="note-comment-description" style="font-size: smaller; color: #999999"><%= t "note.description.#{comment.event}_at_by", :when => friendly_date(comment.created_at), :user => note_author(comment.author, :only_path => false) %></div>
+    <% end -%>
     <div class="note-comment-text"><%= comment.body %></div>
   </div>
   <% end -%>
index 8d45dfe..f64b833 100644 (file)
@@ -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"