summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-08-23 12:59:48 +0000
committerGo MAEDA <maeda@farend.jp>2021-08-23 12:59:48 +0000
commitd276dca5c5a397d2e69286d80a27d82998eedf55 (patch)
tree970cbfec41c638bdcd2a830e8d2a81fb77ec1847
parentfc03ef428238ebafe0d10558a01eb6ae7ebd54c3 (diff)
downloadredmine-d276dca5c5a397d2e69286d80a27d82998eedf55.tar.gz
redmine-d276dca5c5a397d2e69286d80a27d82998eedf55.zip
Query links for related issues on issue page (#35559).
Patch by Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@21200 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/helpers/issues_helper.rb32
-rw-r--r--app/views/issues/_relations.html.erb5
-rw-r--r--public/stylesheets/application.css4
-rw-r--r--test/helpers/issues_helper_test.rb38
4 files changed, 64 insertions, 15 deletions
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index b8e1dd414..81b23acb3 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -152,36 +152,44 @@ module IssuesHelper
open_subtasks = subtasks_grouped[false].to_i
closed_subtasks = subtasks_grouped[true].to_i
- all_subtasks = open_subtasks + closed_subtasks
+ render_issues_stats(open_subtasks, closed_subtasks, {:parent_id => "~#{issue.id}"})
+ end
+
+ # Renders relations stats (total relations (open - closed)) with query links
+ def render_relations_stats(issue, relations)
+ open_relations = relations.count{|r| (r.other_issue(issue).closed?)==false}
+ closed_relations = relations.count{|r| r.other_issue(issue).closed?}
+ render_issues_stats(open_relations, closed_relations, {:issue_id => relations.map{|r| r.other_issue(issue).id}.join(',')})
+ end
- return if all_subtasks == 0
+ # Renders issues stats (total relations (open - closed)) with query links
+ def render_issues_stats(open_issues=0, closed_issues=0, issues_path_attr={})
+ total_issues = open_issues + closed_issues
+ return if total_issues == 0
all_block = content_tag(
'span',
- link_to(all_subtasks, issues_path(parent_id: "~#{issue.id}", set_filter: true, status_id: '*')),
+ link_to(total_issues, issues_path(issues_path_attr.merge({:set_filter => true, :status_id => '*'}))),
class: 'badge badge-issues-count'
)
-
closed_block = content_tag(
'span',
link_to_if(
- closed_subtasks > 0,
- l(:label_x_closed_issues_abbr, count: closed_subtasks),
- issues_path(parent_id: "~#{issue.id}", set_filter: true, status_id: 'c')
+ closed_issues > 0,
+ l(:label_x_closed_issues_abbr, count: closed_issues),
+ issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'c'}))
),
class: 'closed'
)
-
open_block = content_tag(
'span',
link_to_if(
- open_subtasks > 0,
- l(:label_x_open_issues_abbr, :count => open_subtasks),
- issues_path(:parent_id => "~#{issue.id}", :set_filter => true, :status_id => 'o')
+ open_issues > 0,
+ l(:label_x_open_issues_abbr, :count => open_issues),
+ issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'o'}))
),
class: 'open'
)
-
content_tag(
'span',
"#{all_block} (#{open_block} &#8212; #{closed_block})".html_safe,
diff --git a/app/views/issues/_relations.html.erb b/app/views/issues/_relations.html.erb
index 3825fe64f..902292a7f 100644
--- a/app/views/issues/_relations.html.erb
+++ b/app/views/issues/_relations.html.erb
@@ -4,7 +4,10 @@
<% end %>
</div>
-<p><strong><%=l(:label_related_issues)%></strong></p>
+<p>
+ <strong><%=l(:label_related_issues)%></strong>
+ <%= render_relations_stats(@issue, @relations) if @relations.present? %>
+</p>
<% if @relations.present? %>
<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %>
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index b0e50c886..9f6b4dc3d 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -550,8 +550,8 @@ body.controller-issues h2.inline-flex {padding-right: 0}
#issue_tree td.checkbox, #relations td.checkbox {display:none;}
#issue_tree td.subject, #relations td.subject {width: 50%;}
#issue_tree td.buttons, #relations td.buttons {padding:0;}
-#issue_tree .issues-stat {font-size: 80%}
-#issue_tree .issues-stat .badge {bottom: initial;}
+#issue_tree .issues-stat, #relations .issues-stat {font-size: 80%}
+#issue_tree .issues-stat .badge, #relations .issues-stat .badge {bottom: initial;}
#trackers_description {display:none;}
#trackers_description dt {font-weight: bold; text-decoration: underline;}
diff --git a/test/helpers/issues_helper_test.rb b/test/helpers/issues_helper_test.rb
index 28a520b3e..0b3325ad7 100644
--- a/test/helpers/issues_helper_test.rb
+++ b/test/helpers/issues_helper_test.rb
@@ -397,4 +397,42 @@ class IssuesHelperTest < Redmine::HelperTest
end
end
end
+
+ def test_render_issues_stats
+ html = render_issues_stats(1, 1, {:issue_id => '15,16'})
+
+ assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=%2A">2</a>', html
+ assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=o">1 open</a>', html
+ assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=c">1 closed</a>', html
+ end
+
+ def test_render_descendants_stats
+ parent = Issue.generate!(:status_id => 1)
+ child = Issue.generate!(:parent_issue_id => parent.id, :status_id => 1)
+ Issue.generate!(:parent_issue_id => child.id, :status_id => 5)
+ parent.reload
+ html = render_descendants_stats(parent)
+
+ assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=%2A\">2</a>", html
+ assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=o\">1 open</a>", html
+ assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=c\">1 closed</a>", html
+ end
+
+ def test_render_relations_stats
+ issue = Issue.generate!(:status_id => 1)
+ relations = []
+ open_issue = Issue.generate!(:status_id => 1)
+ relations << IssueRelation.create!(:issue_from => open_issue,
+ :issue_to => issue,
+ :relation_type => IssueRelation::TYPE_RELATES)
+ closed_issue = Issue.generate!(:status_id => 5)
+ relations << IssueRelation.create!(:issue_from => closed_issue,
+ :issue_to => issue,
+ :relation_type => IssueRelation::TYPE_FOLLOWS)
+ html = render_relations_stats(issue, relations)
+
+ assert_include "<a href=\"/issues?issue_id=#{open_issue.id}%2C#{closed_issue.id}&amp;set_filter=true&amp;status_id=%2A\">2</a></span>", html
+ assert_include "<a href=\"/issues?issue_id=#{open_issue.id}%2C#{closed_issue.id}&amp;set_filter=true&amp;status_id=o\">1 open</a>", html
+ assert_include "<a href=\"/issues?issue_id=#{open_issue.id}%2C#{closed_issue.id}&amp;set_filter=true&amp;status_id=c\">1 closed</a>", html
+ end
end