diff options
author | Go MAEDA <maeda@farend.jp> | 2021-01-18 07:11:47 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-01-18 07:11:47 +0000 |
commit | 6bca099013adcc5f2fd2828e5538892827932a42 (patch) | |
tree | a143c91d458631307a85c0950273671c5ee11171 /app/helpers/issues_helper.rb | |
parent | 4d3dec2dc0156369b789c8c51557c2c7001854ed (diff) | |
download | redmine-6bca099013adcc5f2fd2828e5538892827932a42.tar.gz redmine-6bca099013adcc5f2fd2828e5538892827932a42.zip |
Some fixes for r20321:
* Include only visible issues in subtasks stats
* Get subtasks using only one query
* Show all subtasks count as badge
* Add tests
Patch by Marius BALTEANU.
git-svn-id: http://svn.redmine.org/redmine/trunk@20718 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers/issues_helper.rb')
-rw-r--r-- | app/helpers/issues_helper.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 4a9e7a2aa..20a708ca0 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -143,6 +143,52 @@ module IssuesHelper s.html_safe end + # Renders descendants stats (total descendants (open - closed)) with query links + def render_descendants_stats(issue) + # Get issue descendants grouped by status type (open/closed) using a single query + subtasks_grouped = issue.descendants.visible.joins(:status).select(:is_closed, :id).group(:is_closed).reorder(:is_closed).count(:id) + # Cast keys to boolean in order to have consistent results between database types + subtasks_grouped.transform_keys! {|k| ActiveModel::Type::Boolean.new.cast(k)} + + open_subtasks = subtasks_grouped[false].to_i + closed_subtasks = subtasks_grouped[true].to_i + all_subtasks = open_subtasks + closed_subtasks + + return if all_subtasks == 0 + + all_block = content_tag( + 'span', + link_to(all_subtasks, issues_path(parent_id: "~#{issue.id}", 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') + ), + 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') + ), + class: 'open' + ) + + content_tag( + 'span', + "#{all_block} (#{open_block} — #{closed_block})".html_safe, + :class => 'issues-stat' + ) + 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) |