Project

General

Profile

Feature #2529 » feature_2529.patch

Mizuki ISHIKAWA, 2018-09-14 10:31

View differences:

app/controllers/reports_controller.rb
28 28
    @authors = @project.users.sort
29 29
    @subprojects = @project.descendants.visible
30 30

  
31
    @issues_by_tracker = Issue.by_tracker(@project)
32
    @issues_by_version = Issue.by_version(@project)
33
    @issues_by_priority = Issue.by_priority(@project)
34
    @issues_by_category = Issue.by_category(@project)
35
    @issues_by_assigned_to = Issue.by_assigned_to(@project)
36
    @issues_by_author = Issue.by_author(@project)
31
    @issues_by_tracker = Issue.count_and_group_by(report_options(:tracker))
32

  
33
    @issues_by_version = Issue.count_and_group_by(report_options(:fixed_version))
34
    @issues_by_priority = Issue.count_and_group_by(report_options(:priority))
35
    @issues_by_category = Issue.count_and_group_by(report_options(:category))
36
    @issues_by_assigned_to = Issue.count_and_group_by(report_options(:assigned_to))
37
    @issues_by_author = Issue.count_and_group_by(report_options(:author))
37 38
    @issues_by_subproject = Issue.by_subproject(@project) || []
38 39

  
39 40
    render :template => "reports/issue_report"
40 41
  end
41 42

  
42 43
  def issue_report_details
44
    @subprojects = Setting.display_subprojects_issues? ? @project.descendants.visible : nil
43 45
    case params[:detail]
44 46
    when "tracker"
45 47
      @field = "tracker_id"
46 48
      @rows = @project.rolled_up_trackers(false).visible
47
      @data = Issue.by_tracker(@project)
49
      @data = Issue.count_and_group_by(report_options(:tracker))
48 50
      @report_title = l(:field_tracker)
49 51
    when "version"
50 52
      @field = "fixed_version_id"
51 53
      @rows = @project.shared_versions.sort
52
      @data = Issue.by_version(@project)
54
      @data = Issue.count_and_group_by(report_options(:fixed_version))
53 55
      @report_title = l(:field_version)
54 56
    when "priority"
55 57
      @field = "priority_id"
56 58
      @rows = IssuePriority.all.reverse
57
      @data = Issue.by_priority(@project)
59
      @data = Issue.count_and_group_by(report_options(:priority))
58 60
      @report_title = l(:field_priority)
59 61
    when "category"
60 62
      @field = "category_id"
......
64 66
    when "assigned_to"
65 67
      @field = "assigned_to_id"
66 68
      @rows = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
67
      @data = Issue.by_assigned_to(@project)
69
      @data = Issue.count_and_group_by(report_options(:assigned_to))
68 70
      @report_title = l(:field_assigned_to)
69 71
    when "author"
70 72
      @field = "author_id"
71 73
      @rows = @project.users.sort
72
      @data = Issue.by_author(@project)
74
      @data = Issue.count_and_group_by(report_options(:author))
73 75
      @report_title = l(:field_author)
74 76
    when "subproject"
75 77
      @field = "project_id"
......
86 88
  def find_issue_statuses
87 89
    @statuses = @project.rolled_up_statuses.sorted.to_a
88 90
  end
91

  
92
  def report_options(association)
93
    with_subprojects = Setting.display_subprojects_issues? ? @subprojects : nil
94
    {:project => @project, :association => association, :with_subprojects => with_subprojects}
95
  end
89 96
end
app/views/reports/_details.html.erb
14 14
<tbody>
15 15
<% for row in rows %>
16 16
<tr>
17
  <td class="name"><%= link_to row.name, aggregate_path(@project, field_name, row) %></td>
17
  <td class="name"><%= link_to row.name, aggregate_path(@project, field_name, row, :subproject_id => nil) %></td>
18 18
  <% for status in @statuses %>
19
    <td><%= aggregate_link data, { field_name => row.id, "status_id" => status.id }, aggregate_path(@project, field_name, row, :status_id => status.id) %></td>
19
    <td><%= aggregate_link data, { field_name => row.id, "status_id" => status.id }, aggregate_path(@project, field_name, row, :status_id => status.id, :subproject_id => nil) %></td>
20 20
  <% end %>
21
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 0 }, aggregate_path(@project, field_name, row, :status_id => "o") %></td>
22
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 1 }, aggregate_path(@project, field_name, row, :status_id => "c") %></td>
23
  <td><%= aggregate_link data, { field_name => row.id }, aggregate_path(@project, field_name, row, :status_id => "*") %></td>
21
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 0 }, aggregate_path(@project, field_name, row, :status_id => "o", :subproject_id => nil) %></td>
22
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 1 }, aggregate_path(@project, field_name, row, :status_id => "c", :subproject_id => nil) %></td>
23
  <td><%= aggregate_link data, { field_name => row.id }, aggregate_path(@project, field_name, row, :status_id => "*", :subproject_id => nil) %></td>
24 24
</tr>
25 25
<% end %>
26 26
</tbody>
app/views/reports/_simple.html.erb
11 11
<tbody>
12 12
<% for row in rows %>
13 13
<tr>
14
  <td class="name"><%= link_to row.name, aggregate_path(@project, field_name, row) %></td>
15
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 0 }, aggregate_path(@project, field_name, row, :status_id => "o") %></td>
16
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 1 }, aggregate_path(@project, field_name, row, :status_id => "c") %></td>
17
  <td><%= aggregate_link data, { field_name => row.id }, aggregate_path(@project, field_name, row, :status_id => "*") %></td>
14
  <td class="name"><%= link_to row.name, aggregate_path(@project, field_name, row, :subproject_id => nil) %></td>
15
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 0 }, aggregate_path(@project, field_name, row, :status_id => "o", :subproject_id => nil) %></td>
16
  <td><%= aggregate_link data, { field_name => row.id, "closed" => 1 }, aggregate_path(@project, field_name, row, :status_id => "c", :subproject_id => nil) %></td>
17
  <td><%= aggregate_link data, { field_name => row.id }, aggregate_path(@project, field_name, row, :status_id => "*", :subproject_id => nil) %></td>
18 18
</tr>
19 19
<% end %>
20 20
</tbody>
test/functional/reports_controller_test.rb
34 34
    assert_response :success
35 35
  end
36 36

  
37
  def test_issue_report_when_displaying_subprojects_issues
38
    Setting.stubs(:display_subprojects_issues?).returns(true)
39
    get :issue_report, :params => {
40
        :id => 1
41
      }
42

  
43
    assert_response :success
44
    # Count subprojects issues
45
    assert_select 'table.list tbody :nth-child(1):first' do
46
      assert_select 'td', :text => 'Bug'
47
      assert_select ':nth-child(2)', :text => '5' # open
48
      assert_select ':nth-child(3)', :text => '3' # closed
49
      assert_select ':nth-child(4)', :text => '8' # total
50
    end
51
  end
52

  
53
  def test_issue_report_when_not_displaying_subprojects_issues
54
    Setting.stubs(:display_subprojects_issues?).returns(false)
55
    get :issue_report, :params => {
56
        :id => 1
57
      }
58

  
59
    assert_response :success
60
    # Do not count subprojects issues
61
    assert_select 'table.list tbody :nth-child(1):first' do
62
      assert_select 'td', :text => 'Bug'
63
      assert_select ':nth-child(2)', :text => '3' # open
64
      assert_select ':nth-child(3)', :text => '3' # closed
65
      assert_select ':nth-child(4)', :text => '6' # total
66
    end
67
  end
68

  
37 69
  def test_get_issue_report_details
38 70
    %w(tracker version priority category assigned_to author subproject).each do |detail|
39 71
      get :issue_report_details, :params => {
......
45 77
  end
46 78

  
47 79
  def test_get_issue_report_details_by_tracker_should_show_only_statuses_used_by_the_project
80
    Setting.stubs(:display_subprojects_issues?).returns(false)
48 81
    WorkflowTransition.delete_all
49 82
    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
50 83
    WorkflowTransition.create(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
......
70 103
    end
71 104
  end
72 105

  
106
  def test_get_issue_report_details_by_tracker_when_displaying_subprojects_issues
107
    Setting.stubs(:display_subprojects_issues?).returns(true)
108
    get :issue_report_details, :params => {
109
        :id => 1,
110
        :detail => 'tracker'
111
      }
112

  
113
    assert_response :success
114
    # Count subprojects issues
115
    assert_select 'table.list tbody :nth-child(1)' do
116
      assert_select 'td', :text => 'Bug'
117
      assert_select ':nth-child(2)', :text => '5' # status:1
118
      assert_select ':nth-child(3)', :text => '-' # status:2
119
      assert_select ':nth-child(4)', :text => '-' # status:3
120
      assert_select ':nth-child(5)', :text => '-' # status:4
121
      assert_select ':nth-child(6)', :text => '3' # status:5
122
      assert_select ':nth-child(7)', :text => '-' # status:6
123
      assert_select ':nth-child(8)', :text => '5' # open
124
      assert_select ':nth-child(9)', :text => '3' # closed
125
      assert_select ':nth-child(10)', :text => '8' # total
126
    end
127
  end
128

  
129
  def test_get_issue_report_details_by_tracker_when_not_displaying_subprojects_issues
130
    Setting.stubs(:display_subprojects_issues?).returns(false)
131
    get :issue_report_details, :params => {
132
      :id => 1,
133
      :detail => 'tracker'
134
    }
135

  
136
    assert_response :success
137
    # Do not count subprojects issues
138
    assert_select 'table.list tbody :nth-child(1)' do
139
      assert_select 'td', :text => 'Bug'
140
      assert_select ':nth-child(2)', :text => '3' # status:1
141
      assert_select ':nth-child(3)', :text => '-' # status:2
142
      assert_select ':nth-child(4)', :text => '-' # status:3
143
      assert_select ':nth-child(5)', :text => '-' # status:4
144
      assert_select ':nth-child(6)', :text => '3' # status:5
145
      assert_select ':nth-child(7)', :text => '-' # status:6
146
      assert_select ':nth-child(8)', :text => '3' # open
147
      assert_select ':nth-child(9)', :text => '3' # closed
148
      assert_select ':nth-child(10)', :text => '6' # total
149
    end
150
  end
151

  
73 152
  def test_get_issue_report_details_by_tracker_should_show_issue_count
74 153
    Issue.delete_all
75 154
    Issue.generate!(:tracker_id => 1)
(1-1/4)