]> git.openstreetmap.org Git - rails.git/commitdiff
Refactor reportable_url to just return the url
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Feb 2018 04:15:45 +0000 (12:15 +0800)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Feb 2018 05:30:17 +0000 (13:30 +0800)
Allows removal of the largely duplicate instance_url helper (which
returned the same urls, but with a hard-coded title).

app/helpers/issues_helper.rb
app/views/issues/index.html.erb
app/views/issues/show.html.erb
app/views/reports/new.html.erb
config/locales/en.yml

index 456507d4caa1856963c2e391c9795cef653cc6a1..36837d228ced3e365b5188c1eb60210545691d2f 100644 (file)
@@ -1,17 +1,16 @@
 module IssuesHelper
   def reportable_url(reportable)
-    class_name = reportable.class.name
-    case class_name
-    when "DiaryEntry"
-      link_to reportable.title, :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id
-    when "User"
-      link_to reportable.display_name.to_s, :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.display_name
-    when "DiaryComment"
-      link_to "#{reportable.diary_entry.title}, Comment id ##{reportable.id}", :controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :anchor => "comment#{reportable.id}"
-    when "Changeset"
-      link_to "Changeset ##{reportable.id}", :controller => :browse, :action => :changeset, :id => reportable.id
-    when "Note"
-      link_to "Note ##{reportable.id}", :controller => :browse, :action => :note, :id => reportable.id
+    case reportable
+    when DiaryEntry
+      url_for(:controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id)
+    when User
+      url_for(:controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.display_name)
+    when DiaryComment
+      url_for(:controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :anchor => "comment#{reportable.id}")
+    when Changeset
+      url_for(:controller => :browse, :action => :changeset, :id => reportable.id)
+    when Note
+      url_for(:controller => :browse, :action => :note, :id => reportable.id)
     end
   end
 
@@ -29,20 +28,4 @@ module IssuesHelper
       "Note ##{reportable.id}"
     end
   end
-
-  def instance_url(reportable)
-    class_name = reportable.class.name
-    case class_name
-    when "DiaryEntry"
-      link_to "Show Instance", :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.user.display_name, :id => reportable.id
-    when "User"
-      link_to "Show Instance", :controller => reportable.class.name.underscore, :action => :view, :display_name => reportable.display_name
-    when "DiaryComment"
-      link_to "Show Instance", :controller => reportable.diary_entry.class.name.underscore, :action => :view, :display_name => reportable.diary_entry.user.display_name, :id => reportable.diary_entry.id, :anchor => "comment#{reportable.id}"
-    when "Changeset"
-      link_to "Show Instance", :controller => :browse, :action => :changeset, :id => reportable.id
-    when "Note"
-      link_to "Show Instance", :controller => :browse, :action => :note, :id => reportable.id
-    end
-  end
 end
index c5e83dce802e592181a35e0de263e5f2f40d9be2..4b7a2de507ee7f47fef10cc68e571f0023ce6bce 100644 (file)
@@ -39,7 +39,7 @@
         <td><% if issue.user_updated %> <%= issue.user_updated.display_name %> <% else %> - <% end %></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>
+        <td><%= link_to t(".show_instance"), reportable_url(issue.reportable) %></td>
       </tr>
     <% end %>
   </tbody>
index fa8afa2331dc20f647abcb209bfd6b35d26c2f65..b69203c4382d98e7b13188940b2a37c4a9cbdcdc 100644 (file)
@@ -1,6 +1,6 @@
 <% content_for :heading do %>
 <h2><%= t ".title", :status => @issue.status.humanize, :issue_id => @issue.id %></h2>
-<p><%= @issue.reportable.model_name.human %> : <%= reportable_url(@issue.reportable) %></p>
+<p><%= @issue.reportable.model_name.human %> : <%= link_to reportable_title(@issue.reportable), reportable_url(@issue.reportable) %></p>
 <p class="deemphasize">
   <small>
     <%= @issue.assigned_role %>
index 7acf91d9c40354b858753d1f83280dda6a7eaca5..f3bda8880222cc684bf82355cee11501d1755c8f 100644 (file)
@@ -1,5 +1,5 @@
 <% content_for :heading do %>
-  <h1><%= t ".title_html", :link => reportable_url(@report.issue.reportable) %></h1>
+  <h1><%= t ".title_html", :link => link_to(reportable_title(@report.issue.reportable), reportable_url(@report.issue.reportable)) %></h1>
 <% end %>
 
 <div class="disclaimer">
index 506f73c5f4f38ef5015d3e3a5db3ae4e6ac15f45..3e8af685c392d3562302488da78e4657104e7a04 100644 (file)
@@ -925,6 +925,7 @@ en:
       user_not_found: User does not exist
       issues_not_found: No such issues found
       status: Status
+      show_instance: Show Instance
       number_of_reports: Number of Reports
       last_updated_at: Last Updated At
       last_updated_by: Last Updated By