]> git.openstreetmap.org Git - rails.git/commitdiff
Refactor reportable_url helper to focus on just the title choices.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Feb 2018 03:53:43 +0000 (11:53 +0800)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Feb 2018 03:53:43 +0000 (11:53 +0800)
app/helpers/issues_helper.rb
app/views/issues/index.html.erb
app/views/issues/show.html.erb

index b0e598d7095779d34ce3059cf8702985f35a808e..456507d4caa1856963c2e391c9795cef653cc6a1 100644 (file)
@@ -15,19 +15,18 @@ module IssuesHelper
     end
   end
 
-  def reports_url(issue)
-    class_name = issue.reportable.class.name
-    case class_name
-    when "DiaryEntry"
-      link_to issue.reportable.title, issue
-    when "User"
-      link_to issue.reportable.display_name.to_s, issue
-    when "DiaryComment"
-      link_to "#{issue.reportable.diary_entry.title}, Comment id ##{issue.reportable.id}", issue
-    when "Changeset"
-      link_to "Changeset ##{issue.reportable.id}", issue
-    when "Note"
-      link_to "Note ##{issue.reportable.id}", issue
+  def reportable_title(reportable)
+    case reportable
+    when DiaryEntry
+      reportable.title
+    when User
+      reportable.display_name
+    when DiaryComment
+      "#{reportable.diary_entry.title}, Comment id ##{reportable.id}"
+    when Changeset
+      "Changeset ##{reportable.id}"
+    when Note
+      "Note ##{reportable.id}"
     end
   end
 
index 653cd462e7edb5b117a1c416ffa9247b503b1ccb..c5e83dce802e592181a35e0de263e5f2f40d9be2 100644 (file)
@@ -37,7 +37,7 @@
         <td style="text-align:center;"><%= issue.reports_count %></td>
         <td><%= l(issue.updated_at.to_datetime, :format => :friendly) %></td>
         <td><% if issue.user_updated %> <%= issue.user_updated.display_name %> <% else %> - <% end %></td>
-        <td><%= reports_url(issue) %></td>
+        <td><%= link_to reportable_title(issue.reportable), issue %></td>
         <td><%= link_to issue.reported_user.display_name , :controller => :user, :action => :view, :display_name => issue.reported_user.display_name %></td>
         <td><%= instance_url(issue.reportable) %></td>
       </tr>
index 05ce1b9f1f149c047b0b39048b55b8e6d1c9af51..fa8afa2331dc20f647abcb209bfd6b35d26c2f65 100644 (file)
@@ -46,7 +46,7 @@
       <% if @related_issues.count > 1 %>
         <% @related_issues.each do |issue| %>
           <% if issue.id != @issue.id %>
-            <%= reports_url(issue) %> <br/>
+            <%= link_to reportable_title(issue.reportable), issue %> <br/>
           <% end %>
         <% end %>
       <% else %>