]> git.openstreetmap.org Git - rails.git/blobdiff - app/helpers/changeset_helper.rb
Merge pull request #14 from tomhughes/routing
[rails.git] / app / helpers / changeset_helper.rb
index b71c353713644afc6a5e82ee340d9fbc6ddbd54b..cae1335c4c1d80e08f3a76d51863d9e1ec2adb54 100644 (file)
@@ -1,24 +1,32 @@
 module ChangesetHelper
-  def changeset_time_ago(changeset)
-    out = ''
-    created_at = distance_of_time_in_words_to_now(changeset.created_at)
-    closed_at = distance_of_time_in_words_to_now(changeset.closed_at)
-    if created_at == closed_at
-      out << t('browse.changeset_details.closed_at') + ' '
-      both_times = t('browse.changeset_details.created_at') + ': ' + l(changeset.created_at)
-      both_times << '&#10;'
-      both_times << t('browse.changeset_details.closed_at') + ': ' + l(changeset.closed_at)
-      out << content_tag(:abbr, t('browse.changeset_details.ago', :ago => created_at), title: both_times.html_safe)
+  def changeset_user_link(changeset)
+    if changeset.user.data_public?
+      link_to(changeset.user.display_name, user_path(changeset.user.display_name))
     else
-      out << t('browse.changeset_details.created_at') + ' '
-      out << content_tag(:abbr, t('browse.changeset_details.ago', :ago => created_at), title: l(changeset.created_at))
-      out << t('browse.changeset_details.closed_at') + ' '
-      out << content_tag(:abbr, t('browse.changeset_details.ago', :ago => closed_at), title: l(changeset.closed_at))
+      t('browse.anonymous')
     end
-    if changeset.user.data_public?
-      out << ' ' + t('browse.changeset_details.by') + ' '
-      out << link_to(h(changeset.user.display_name), :controller => "user", :action => "view", :display_name => changeset.user.display_name)
+  end
+
+  def changeset_details(changeset)
+    if changeset.closed_at > DateTime.now
+      action = :created
+      time = distance_of_time_in_words_to_now(changeset.created_at)
+      title = l(changeset.created_at)
+    else
+      action = :closed
+      time = distance_of_time_in_words_to_now(changeset.closed_at)
+      title = "#{t('browse.created')}: #{l(changeset.created_at)}&#10;#{t('browse.closed')}: #{l(changeset.closed_at)}".html_safe
+    end
+
+    if params.key?(:display_name)
+      t "browse.#{action}_html",
+        :time => time,
+        :title => title
+    else
+      t "browse.#{action}_by_html",
+        :time => time,
+        :title => title,
+        :user => changeset_user_link(changeset)
     end
-    return out.html_safe
   end
 end