From: Andy Allan Date: Wed, 28 Feb 2018 04:15:45 +0000 (+0800) Subject: Refactor reportable_url to just return the url X-Git-Tag: live~3651^2~51 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/3bd06529c7f9920c4f71498277f453bf1b8dd030?ds=inline Refactor reportable_url to just return the url Allows removal of the largely duplicate instance_url helper (which returned the same urls, but with a hard-coded title). --- diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 456507d4c..36837d228 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -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 diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index c5e83dce8..4b7a2de50 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -39,7 +39,7 @@ <% if issue.user_updated %> <%= issue.user_updated.display_name %> <% else %> - <% end %> <%= link_to reportable_title(issue.reportable), issue %> <%= link_to issue.reported_user.display_name , :controller => :user, :action => :view, :display_name => issue.reported_user.display_name %> - <%= instance_url(issue.reportable) %> + <%= link_to t(".show_instance"), reportable_url(issue.reportable) %> <% end %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index fa8afa233..b69203c43 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -1,6 +1,6 @@ <% content_for :heading do %>

<%= t ".title", :status => @issue.status.humanize, :issue_id => @issue.id %>

-

<%= @issue.reportable.model_name.human %> : <%= reportable_url(@issue.reportable) %>

+

<%= @issue.reportable.model_name.human %> : <%= link_to reportable_title(@issue.reportable), reportable_url(@issue.reportable) %>

<%= @issue.assigned_role %> diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb index 7acf91d9c..f3bda8880 100644 --- a/app/views/reports/new.html.erb +++ b/app/views/reports/new.html.erb @@ -1,5 +1,5 @@ <% content_for :heading do %> -

<%= t ".title_html", :link => reportable_url(@report.issue.reportable) %>

+

<%= t ".title_html", :link => link_to(reportable_title(@report.issue.reportable), reportable_url(@report.issue.reportable)) %>

<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 506f73c5f..3e8af685c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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