Project

General

Profile

Feature #35559 » 35559.patch

Takenori TAKAKI, 2021-07-26 05:16

View differences:

app/helpers/issues_helper.rb
152 152

  
153 153
    open_subtasks = subtasks_grouped[false].to_i
154 154
    closed_subtasks = subtasks_grouped[true].to_i
155
    all_subtasks = open_subtasks + closed_subtasks
155
    render_issues_stats(open_subtasks, closed_subtasks, {:parent_id => "~#{issue.id}"})
156
  end
156 157

  
157
    return if all_subtasks == 0
158
  # Renders relations stats (total relations (open - closed)) with query links
159
  def render_relations_stats(issue, relations)
160
    open_relations = relations.count{|r|(r.other_issue(issue).closed?)==false}
161
    closed_relations = relations.count{|r|r.other_issue(issue).closed?}
162
    render_issues_stats(open_relations, closed_relations, {:issue_id => relations.map{|r|r.other_issue(issue).id}.join(',')})
163
  end
158 164

  
165
  # Renders issues stats (total relations (open - closed)) with query links
166
  def render_issues_stats(open_issues=0, closed_issues=0, issues_path_attr={})
167
    total_issues = open_issues + closed_issues
168
    return if total_issues == 0
159 169
    all_block = content_tag(
160 170
      'span',
161
      link_to(all_subtasks, issues_path(parent_id: "~#{issue.id}", set_filter: true, status_id: '*')),
171
      link_to(total_issues, issues_path(issues_path_attr.merge({:set_filter => true, :status_id => '*'}))),
162 172
      class: 'badge badge-issues-count'
163 173
    )
164

  
165 174
    closed_block = content_tag(
166 175
      'span',
167 176
      link_to_if(
168
        closed_subtasks > 0,
169
        l(:label_x_closed_issues_abbr, count: closed_subtasks),
170
        issues_path(parent_id: "~#{issue.id}", set_filter: true, status_id: 'c')
177
        closed_issues > 0,
178
        l(:label_x_closed_issues_abbr, count: closed_issues),
179
        issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'c'}))
171 180
      ),
172 181
      class: 'closed'
173 182
    )
174

  
175 183
    open_block = content_tag(
176 184
      'span',
177 185
      link_to_if(
178
        open_subtasks > 0,
179
        l(:label_x_open_issues_abbr, :count => open_subtasks),
180
        issues_path(:parent_id => "~#{issue.id}", :set_filter => true, :status_id => 'o')
186
        open_issues > 0,
187
        l(:label_x_open_issues_abbr, :count => open_issues),
188
        issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'o'}))
181 189
      ),
182 190
      class: 'open'
183 191
    )
184

  
185 192
    content_tag(
186 193
      'span',
187 194
      "#{all_block} (#{open_block} — #{closed_block})".html_safe,
app/views/issues/_relations.html.erb
4 4
<% end %>
5 5
</div>
6 6

  
7
<p><strong><%=l(:label_related_issues)%></strong></p>
7
<p>
8
  <strong><%=l(:label_related_issues)%></strong>
9
  <%= render_relations_stats(@issue, @relations) if @relations.present? %>
10
</p>
8 11

  
9 12
<% if @relations.present? %>
10 13
<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %>
public/stylesheets/application.css
547 547
#issue_tree td.checkbox, #relations td.checkbox {display:none;}
548 548
#issue_tree td.subject, #relations td.subject {width: 50%;}
549 549
#issue_tree td.buttons, #relations td.buttons {padding:0;}
550
#issue_tree .issues-stat {font-size: 80%}
551
#issue_tree .issues-stat .badge {bottom: initial;}
550
#issue_tree, #relations .issues-stat {font-size: 80%}
551
#issue_tree, #relations .issues-stat .badge {bottom: initial;}
552 552

  
553 553
#trackers_description {display:none;}
554 554
#trackers_description dt {font-weight: bold; text-decoration: underline;}
test/helpers/issues_helper_test.rb
375 375
    assert_equal new_project_issue_path(issue.project, params),
376 376
                 url_for_new_subtask(issue)
377 377
  end
378

  
379
  def test_render_issues_stats
380
    html = render_issues_stats(1, 1, {:issue_id => '15,16'})
381

  
382
    assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=%2A">2</a>', html
383
    assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=o">1 open</a>', html
384
    assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=c">1 closed</a>', html
385
  end
386

  
387
  def test_render_descendants_stats
388
    parent = Issue.generate!(:status_id => 1)
389
    child = Issue.generate!(:parent_issue_id => parent.id, :status_id => 1)
390
    Issue.generate!(:parent_issue_id => child.id, :status_id => 5)
391
    parent.reload
392
    html = render_descendants_stats(parent)
393

  
394
    assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=%2A\">2</a>", html
395
    assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=o\">1 open</a>", html
396
    assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=c\">1 closed</a>", html
397
  end
398

  
399
  def test_render_relations_stats
400
    issue = Issue.generate!(:status_id => 1)
401
    relations = []
402
    open_issue = Issue.generate!(:status_id => 1)
403
    relations << IssueRelation.create!(:issue_from => open_issue,
404
                                       :issue_to => issue,
405
                                       :relation_type => IssueRelation::TYPE_RELATES)
406
    closed_issue = Issue.generate!(:status_id => 5)
407
    relations << IssueRelation.create!(:issue_from => closed_issue,
408
                                       :issue_to => issue,
409
                                       :relation_type => IssueRelation::TYPE_FOLLOWS)
410
    html = render_relations_stats(issue, relations)
411

  
412
    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
413
    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
414
    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
415
  end
378 416
end
(2-2/3)