]> source.dussan.org Git - redmine.git/commitdiff
Extracts the rendering of related issues to an helper (#3425).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Nov 2016 10:03:27 +0000 (10:03 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 19 Nov 2016 10:03:27 +0000 (10:03 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@15981 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issue_relations_controller.rb
app/helpers/issues_helper.rb
app/views/issues/_relations.html.erb

index 9c8c2fe1d940f86acfe32e0b935b981db0e57da9..7d37a3e20f4b7110b3f24ff63c1eb08ff612f4b0 100644 (file)
@@ -16,6 +16,8 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 class IssueRelationsController < ApplicationController
+  helper :issues
+
   before_action :find_issue, :authorize, :only => [:index, :create]
   before_action :find_relation, :only => [:show, :destroy]
 
index 72f33da1d0cf9a34164919c0966a0a670c862938..eaa42f9de3ee4d5df044e62b5d7fba357e4e487f 100644 (file)
@@ -106,6 +106,37 @@ module IssuesHelper
     s.html_safe
   end
 
+  # Renders the list of related issues on the issue details view
+  def render_issue_relations(issue, relations)
+    manage_relations = User.current.allowed_to?(:manage_issue_relations, issue.project)
+
+    s = ''.html_safe
+    relations.each do |relation|
+      other_issue = relation.other_issue(issue)
+      css = "issue hascontextmenu #{other_issue.css_classes}"
+      link = manage_relations ? link_to(l(:label_relation_delete),
+                                  relation_path(relation),
+                                  :remote => true,
+                                  :method => :delete,
+                                  :data => {:confirm => l(:text_are_you_sure)},
+                                  :title => l(:label_relation_delete),
+                                  :class => 'icon-only icon-link-break'
+                                 ) : nil
+
+      s << content_tag('tr',
+             content_tag('td', check_box_tag("ids[]", other_issue.id, false, :id => nil), :class => 'checkbox') +
+             content_tag('td', relation.to_s(@issue) {|other| link_to_issue(other, :project => Setting.cross_project_issue_relations?)}.html_safe, :class => 'subject', :style => 'width: 50%') +
+             content_tag('td', other_issue.status, :class => 'status') +
+             content_tag('td', other_issue.start_date, :class => 'start_date') +
+             content_tag('td', other_issue.due_date, :class => 'due_date') +
+             content_tag('td', link, :class => 'buttons'),
+             :id => "relation-#{relation.id}",
+             :class => css)
+    end
+
+    content_tag('table', s, :class => 'list issues')
+  end
+
   def issue_estimated_hours_details(issue)
     if issue.total_estimated_hours.present?
       if issue.total_estimated_hours == issue.estimated_hours
index cab1d0c1a083ec020295b76a962e5286884648c9..3825fe64fd8fc2d7f5a93f2ad9307d7d38fdd4c4 100644 (file)
@@ -8,28 +8,7 @@
 
 <% if @relations.present? %>
 <%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %>
-<table class="list issues">
-<% @relations.each do |relation| %>
-  <% other_issue = relation.other_issue(@issue) -%>
-  <tr class="issue hascontextmenu <%= other_issue.css_classes %>" id="relation-<%= relation.id %>">
-  <td class="checkbox"><%= check_box_tag("ids[]", other_issue.id, false, :id => nil) %></td>
-  <td class="subject" style="width: 50%">
-    <%= relation.to_s(@issue) {|other| link_to_issue(other, :project => Setting.cross_project_issue_relations?)}.html_safe %>
-  </td>
-  <td class="status"><%= other_issue.status.name %></td>
-  <td class="start_date"><%= format_date(other_issue.start_date) %></td>
-  <td class="due_date"><%= format_date(other_issue.due_date) %></td>
-  <td class="buttons"><%= link_to(l(:label_relation_delete),
-                                  relation_path(relation),
-                                  :remote => true,
-                                  :method => :delete,
-                                  :data => {:confirm => l(:text_are_you_sure)},
-                                  :title => l(:label_relation_delete),
-                                  :class => 'icon-only icon-link-break'
-                                 ) if User.current.allowed_to?(:manage_issue_relations, @project) %></td>
-  </tr>
-<% end %>
-</table>
+  <%= render_issue_relations(@issue, @relations) %>
 <% end %>
 <% end %>