Project

General

Profile

Feature #35559 » 35559-v2.patch

Go MAEDA, 2021-08-15 14:10

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
157

  
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
156 164

  
157
    return if all_subtasks == 0
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
158 169

  
159 170
    all_block = content_tag(
160 171
      'span',
161
      link_to(all_subtasks, issues_path(parent_id: "~#{issue.id}", set_filter: true, status_id: '*')),
172
      link_to(total_issues, issues_path(issues_path_attr.merge({:set_filter => true, :status_id => '*'}))),
162 173
      class: 'badge badge-issues-count'
163 174
    )
164

  
165 175
    closed_block = content_tag(
166 176
      'span',
167 177
      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')
178
        closed_issues > 0,
179
        l(:label_x_closed_issues_abbr, count: closed_issues),
180
        issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'c'}))
171 181
      ),
172 182
      class: 'closed'
173 183
    )
174

  
175 184
    open_block = content_tag(
176 185
      'span',
177 186
      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')
187
        open_issues > 0,
188
        l(:label_x_open_issues_abbr, :count => open_issues),
189
        issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'o'}))
181 190
      ),
182 191
      class: 'open'
183 192
    )
184

  
185 193
    content_tag(
186 194
      'span',
187 195
      "#{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
550 550
#issue_tree td.checkbox, #relations td.checkbox {display:none;}
551 551
#issue_tree td.subject, #relations td.subject {width: 50%;}
552 552
#issue_tree td.buttons, #relations td.buttons {padding:0;}
553
#issue_tree .issues-stat {font-size: 80%}
554
#issue_tree .issues-stat .badge {bottom: initial;}
553
#issue_tree .issues-stat, #relations .issues-stat {font-size: 80%}
554
#issue_tree .issues-stat .badge, #relations .issues-stat .badge {bottom: initial;}
555 555

  
556 556
#trackers_description {display:none;}
557 557
#trackers_description dt {font-weight: bold; text-decoration: underline;}
test/helpers/issues_helper_test.rb
397 397
      end
398 398
    end
399 399
  end
400

  
401
  def test_render_issues_stats
402
    html = render_issues_stats(1, 1, {:issue_id => '15,16'})
403

  
404
    assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=%2A">2</a>', html
405
    assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=o">1 open</a>', html
406
    assert_include '<a href="/issues?issue_id=15%2C16&amp;set_filter=true&amp;status_id=c">1 closed</a>', html
407
  end
408

  
409
  def test_render_descendants_stats
410
    parent = Issue.generate!(:status_id => 1)
411
    child = Issue.generate!(:parent_issue_id => parent.id, :status_id => 1)
412
    Issue.generate!(:parent_issue_id => child.id, :status_id => 5)
413
    parent.reload
414
    html = render_descendants_stats(parent)
415

  
416
    assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=%2A\">2</a>", html
417
    assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=o\">1 open</a>", html
418
    assert_include "<a href=\"/issues?parent_id=~#{parent.id}&amp;set_filter=true&amp;status_id=c\">1 closed</a>", html
419
  end
420

  
421
  def test_render_relations_stats
422
    issue = Issue.generate!(:status_id => 1)
423
    relations = []
424
    open_issue = Issue.generate!(:status_id => 1)
425
    relations << IssueRelation.create!(:issue_from => open_issue,
426
                                       :issue_to => issue,
427
                                       :relation_type => IssueRelation::TYPE_RELATES)
428
    closed_issue = Issue.generate!(:status_id => 5)
429
    relations << IssueRelation.create!(:issue_from => closed_issue,
430
                                       :issue_to => issue,
431
                                       :relation_type => IssueRelation::TYPE_FOLLOWS)
432
    html = render_relations_stats(issue, relations)
433

  
434
    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
435
    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
436
    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
437
  end
400 438
end
(3-3/3)