2595-without-tests.patch

Takenori TAKAKI, 2018-11-08 17:20

Download (15.2 KB)

View differences:

app/controllers/reports_controller.rb
17 17

  
18 18
class ReportsController < ApplicationController
19 19
  menu_item :issues
20
  before_action :find_project, :authorize, :find_issue_statuses
20
  before_action :find_project, :authorize, :if => proc { params[:id].present? }
21
  before_action :find_issue_statuses
21 22

  
22 23
  def issue_report
23
    @trackers = @project.rolled_up_trackers(false).visible
24
    @versions = @project.shared_versions.sort
25
    @priorities = IssuePriority.all.reverse
26
    @categories = @project.issue_categories
27
    @assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
28
    @authors = @project.users.sort
29
    @subprojects = @project.descendants.visible
24
    if @project
25
      @trackers = @project.rolled_up_trackers(false).visible
26
      @versions = @project.shared_versions.sort
27
      @priorities = IssuePriority.all.reverse
28
      @categories = @project.issue_categories
29
      @assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
30
      @authors = @project.users.sort
31
      @subprojects = @project.descendants.visible
32

  
33
      @issues_by_subproject = Issue.by_subproject(@project) || []
34
    else
35
      @trackers = Tracker.visible.sorted
36
      @versions = []
37
      @priorities = IssuePriority.all.reverse
38
      @categories = []
39
      @assignees = (Setting.issue_group_assignment? ? Principal.active : User.active).sort
40
      @authors = User.active.sort
41
      @projects = Project.visible.sorted
42

  
43
      @issues_by_project = Issue.count_and_group_by(:association => :project)
44
    end
45

  
30 46
    with_subprojects = Setting.display_subprojects_issues?
31 47
    @issues_by_tracker = Issue.by_tracker(@project, with_subprojects)
32 48
    @issues_by_version = Issue.by_version(@project, with_subprojects)
......
34 50
    @issues_by_category = Issue.by_category(@project, with_subprojects)
35 51
    @issues_by_assigned_to = Issue.by_assigned_to(@project, with_subprojects)
36 52
    @issues_by_author = Issue.by_author(@project, with_subprojects)
37
    @issues_by_subproject = Issue.by_subproject(@project) || []
38 53

  
39 54
    render :template => "reports/issue_report"
40 55
  end
......
44 59
    case params[:detail]
45 60
    when "tracker"
46 61
      @field = "tracker_id"
47
      @rows = @project.rolled_up_trackers(false).visible
62
      @rows = @project ? @project.rolled_up_trackers(false).visible : Tracker.visible.sorted
48 63
      @data = Issue.by_tracker(@project, with_subprojects)
49 64
      @report_title = l(:field_tracker)
50 65
    when "version"
66
      (render_404; return) unless @project.present?
51 67
      @field = "fixed_version_id"
52 68
      @rows = @project.shared_versions.sort
53 69
      @data = Issue.by_version(@project, with_subprojects)
......
58 74
      @data = Issue.by_priority(@project, with_subprojects)
59 75
      @report_title = l(:field_priority)
60 76
    when "category"
77
      (render_404; return) unless @project.present?
61 78
      @field = "category_id"
62 79
      @rows = @project.issue_categories
63 80
      @data = Issue.by_category(@project, with_subprojects)
64 81
      @report_title = l(:field_category)
65 82
    when "assigned_to"
66 83
      @field = "assigned_to_id"
67
      @rows = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
84
      @rows = @project ? (Setting.issue_group_assignment? ? @project.principals : @project.users).sort :
85
                         (Setting.issue_group_assignment? ? Principal.active : User.active).sort
68 86
      @data = Issue.by_assigned_to(@project, with_subprojects)
69 87
      @report_title = l(:field_assigned_to)
70 88
    when "author"
71 89
      @field = "author_id"
72
      @rows = @project.users.sort
90
      @rows = @project ? @project.users.sort : User.active.sort
73 91
      @data = Issue.by_author(@project, with_subprojects)
74 92
      @report_title = l(:field_author)
75 93
    when "subproject"
94
      (render_404; return) unless @project.present?
76 95
      @field = "project_id"
77 96
      @rows = @project.descendants.visible
78 97
      @data = Issue.by_subproject(@project) || []
79 98
      @report_title = l(:field_subproject)
99
    when "project"
100
      @field = "project_id"
101
      @rows = Project.visible.sorted
102
      @data = Issue.count_and_group_by(:association => :project)
103
      @report_title = l(:field_project)
80 104
    else
81 105
      render_404
82 106
    end
......
85 109
  private
86 110

  
87 111
  def find_issue_statuses
88
    @statuses = @project.rolled_up_statuses.sorted.to_a
112
    @statuses = @project ? @project.rolled_up_statuses.sorted.to_a : IssueStatus.sorted.to_a
89 113
  end
90 114
end
app/helpers/reports_helper.rb
38 38

  
39 39
  def aggregate_path(project, field, row, options={})
40 40
    parameters = {:set_filter => 1, :subproject_id => '!*', field => row.id}.merge(options)
41
    project_issues_path(row.is_a?(Project) ? row : project, parameters)
41
    parameters[:subproject_id] = nil if project
42
    return project_issues_path(row, parameters) if row.is_a?(Project)
43
    return project_issues_path(project, parameters) if project.is_a?(Project)
44
    return issues_path(parameters)
45
  end
46

  
47
  def report_details_path(project, options)
48
    if project
49
      project_issues_report_details_path(project, options)
50
    else
51
      issues_report_details_path(options)
52
    end
42 53
  end
43 54
end
app/models/issue.rb
1486 1486
  # * with_subprojects - Includes subprojects issues if set to true.
1487 1487
  # * association - Symbol. Association for grouping.
1488 1488
  def self.count_and_group_by(options)
1489
    visible_conditions = {:project => options[:project], :with_subprojects => options[:with_subprojects]}
1490
    visible_conditions.delete(:project) if options[:project].nil?
1489 1491
    assoc = reflect_on_association(options[:association])
1490 1492
    select_field = assoc.foreign_key
1491 1493

  
1492 1494
    Issue.
1493
      visible(User.current, :project => options[:project], :with_subprojects => options[:with_subprojects]).
1495
      visible(User.current, visible_conditions).
1494 1496
      joins(:status, assoc.name).
1495 1497
      group(:status_id, :is_closed, select_field).
1496 1498
      count.
app/views/issues/_sidebar.html.erb
2 2

  
3 3
<ul>
4 4
<li><%= link_to l(:label_issue_view_all), _project_issues_path(@project, :set_filter => 1) %></li>
5
<% if @project %>
6
<li><%= link_to l(:field_summary), project_issues_report_path(@project) %></li>
7
<% end %>
5
<li><%= link_to l(:field_summary), @project ? project_issues_report_path(@project) : issues_report_path %></li>
8 6

  
9 7
<% if User.current.allowed_to?(:import_issues, @project, :global => true) %>
10 8
<li><%= link_to l(:button_import), new_issues_import_path %></li>
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, :subproject_id => nil) %></td>
17
  <td class="name"><%= link_to row.name, aggregate_path(@project, field_name, row) %></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, :subproject_id => nil) %></td>
19
    <td><%= aggregate_link data, { field_name => row.id, "status_id" => status.id }, aggregate_path(@project, field_name, row, {:status_id => status.id}) %></td>
20 20
  <% end %>
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>
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>
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, :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>
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>
18 18
</tr>
19 19
<% end %>
20 20
</tbody>
app/views/reports/issue_report.html.erb
4 4
<h3>
5 5
  <%=l(:field_tracker)%>&nbsp;
6 6
  <%= link_to l(:label_details),
7
        project_issues_report_details_path(@project, :detail => 'tracker'),
7
        report_details_path(@project, :detail => 'tracker'),
8 8
        :class => 'icon-only icon-zoom-in',
9 9
        :title => l(:label_details) %>
10 10
</h3>
......
13 13
<h3>
14 14
  <%=l(:field_priority)%>&nbsp;
15 15
  <%= link_to l(:label_details),
16
        project_issues_report_details_path(@project, :detail => 'priority'),
16
        report_details_path(@project, :detail => 'priority'),
17 17
        :class => 'icon-only icon-zoom-in',
18 18
        :title => l(:label_details) %>
19 19
</h3>
......
22 22
<h3>
23 23
  <%=l(:field_assigned_to)%>&nbsp;
24 24
  <%= link_to l(:label_details),
25
        project_issues_report_details_path(@project, :detail => 'assigned_to'),
25
        report_details_path(@project, :detail => 'assigned_to'),
26 26
        :class => 'icon-only icon-zoom-in',
27 27
        :title => l(:label_details) %>
28 28
</h3>
......
31 31
<h3>
32 32
  <%=l(:field_author)%>&nbsp;
33 33
  <%= link_to l(:label_details),
34
        project_issues_report_details_path(@project, :detail => 'author'),
34
        report_details_path(@project, :detail => 'author'),
35 35
        :class => 'icon-only icon-zoom-in',
36 36
        :title => l(:label_details) %>
37 37
</h3>
......
41 41
</div>
42 42

  
43 43
<div class="splitcontentright">
44
<% if @issues_by_version.present? && @versions.present? %>
44 45
<h3>
45 46
  <%=l(:field_version)%>&nbsp;
46 47
  <%= link_to l(:label_details),
47
        project_issues_report_details_path(@project, :detail => 'version'),
48
        report_details_path(@project, :detail => 'version'),
48 49
        :class => 'icon-only icon-zoom-in',
49 50
        :title => l(:label_details) %>
50 51
</h3>
51 52
<%= render :partial => 'simple', :locals => { :data => @issues_by_version, :field_name => "fixed_version_id", :rows => @versions } %>
52 53
<br />
53
<% if @project.children.any? %>
54
<% end %>
55
<% if @project && @project.children.any? %>
54 56
<h3>
55 57
  <%=l(:field_subproject)%>&nbsp;
56 58
  <%= link_to l(:label_details),
57
        project_issues_report_details_path(@project, :detail => 'subproject'),
59
        report_details_path(@project, :detail => 'subproject'),
58 60
        :class => 'icon-only icon-zoom-in',
59 61
        :title => l(:label_details) %>
60 62
</h3>
61 63
<%= render :partial => 'simple', :locals => { :data => @issues_by_subproject, :field_name => "project_id", :rows => @subprojects } %>
62 64
<br />
63 65
<% end %>
66
<% if @issues_by_category.present? && @categories.present? %>
64 67
<h3>
65 68
  <%=l(:field_category)%>&nbsp;
66 69
  <%= link_to l(:label_details),
67
        project_issues_report_details_path(@project, :detail => 'category'),
70
        report_details_path(@project, :detail => 'category'),
68 71
        :class => 'icon-only icon-zoom-in',
69 72
        :title => l(:label_details) %>
70 73
</h3>
71 74
<%= render :partial => 'simple', :locals => { :data => @issues_by_category, :field_name => "category_id", :rows => @categories } %>
72 75
<br />
76
<% end %>
77
<% if @issues_by_project.present? && @projects.present? %>
78
<h3>
79
  <%=l(:field_project)%>&nbsp;
80
  <%= link_to l(:label_details),
81
        report_details_path(@project, :detail => 'project'),
82
        :class => 'icon-only icon-zoom-in',
83
        :title => l(:label_details) %>
84
</h3>
85
<%= render :partial => 'simple', :locals => { :data => @issues_by_project, :field_name => "project_id", :rows => @projects } %>
86
<br />
87
<% end %>
73 88
<%= call_hook(:view_reports_issue_report_split_content_right, :project => @project) %>
74 89
</div>
75 90

  
app/views/reports/issue_report_details.html.erb
3 3
<h3><%=@report_title%></h3>
4 4
<%= render :partial => 'details', :locals => { :data => @data, :field_name => @field, :rows => @rows } %>
5 5
<br />
6
<%= link_to l(:button_back), project_issues_report_path(@project) %>
6
<%= link_to l(:button_back), @project ? project_issues_report_path(@project) : issues_report_path %>
7 7

  
config/routes.rb
61 61

  
62 62
  get 'projects/:id/issues/report', :to => 'reports#issue_report', :as => 'project_issues_report'
63 63
  get 'projects/:id/issues/report/:detail', :to => 'reports#issue_report_details', :as => 'project_issues_report_details'
64
  get 'issues/report', :to => 'reports#issue_report', :as => 'issues_report'
65
  get 'issues/report/:detail', :to => 'reports#issue_report_details', :as => 'issues_report_details'
64 66

  
65 67
  get   '/issues/imports/new', :to => 'imports#new', :as => 'new_issues_import'
66 68
  post  '/imports', :to => 'imports#create', :as => 'imports'