end
@issue_count = Issue.count(:include => [:status, :project], :conditions => @query.statement)
@issue_pages = Paginator.new self, @issue_count, limit, params['page']
- @issues = Issue.find :all, :order => sort_clause,
+ @issues = Issue.find :all, :order => [@query.group_by_sort_order, sort_clause].compact.join(','),
:include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
:conditions => @query.statement,
:limit => limit,
:offset => @issue_pages.current.offset
respond_to do |format|
- format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
+ format.html {
+ if @query.grouped?
+ # Retrieve the issue count by group
+ @issue_count_by_group = begin
+ Issue.count(:group => @query.group_by, :include => [:status, :project], :conditions => @query.statement)
+ # Rails will raise an (unexpected) error if there's only a nil group value
+ rescue ActiveRecord::RecordNotFound
+ {nil => @issue_count}
+ end
+ end
+ render :template => 'issues/index.rhtml', :layout => !request.xhr?
+ }
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
format.csv { send_data(issues_to_csv(@issues, @project).read, :type => 'text/csv; header=present', :filename => 'export.csv') }
- format.pdf { send_data(issues_to_pdf(@issues, @project), :type => 'application/pdf', :filename => 'export.pdf') }
+ format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
end
else
# Send html if the query is not valid
@query.add_short_filter(field, params[field]) if params[field]
end
end
- session[:query] = {:project_id => @query.project_id, :filters => @query.filters}
+ @query.group_by = params[:group_by]
+ session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by}
else
@query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
- @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters])
+ @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by])
@query.project = @project
end
end
params[:fields].each do |field|
@query.add_filter(field, params[:operators][field], params[:values][field])
end if params[:fields]
+ @query.group_by ||= params[:group_by]
if request.post? && params[:confirm] && @query.save
flash[:notice] = l(:notice_successful_create)
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class QueryColumn
- attr_accessor :name, :sortable, :default_order
+ attr_accessor :name, :sortable, :groupable, :default_order
include Redmine::I18n
def initialize(name, options={})
self.name = name
self.sortable = options[:sortable]
+ self.groupable = options[:groupable] || false
self.default_order = options[:default_order]
end
cattr_reader :operators_by_filter_type
@@available_columns = [
- QueryColumn.new(:project, :sortable => "#{Project.table_name}.name"),
- QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position"),
- QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position"),
- QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc'),
+ QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
+ QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true),
+ QueryColumn.new(:status, :sortable => "#{IssueStatus.table_name}.position", :groupable => true),
+ QueryColumn.new(:priority, :sortable => "#{Enumeration.table_name}.position", :default_order => 'desc', :groupable => true),
QueryColumn.new(:subject, :sortable => "#{Issue.table_name}.subject"),
QueryColumn.new(:author),
- QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname"]),
+ QueryColumn.new(:assigned_to, :sortable => ["#{User.table_name}.lastname", "#{User.table_name}.firstname", "#{User.table_name}.id"], :groupable => true),
QueryColumn.new(:updated_on, :sortable => "#{Issue.table_name}.updated_on", :default_order => 'desc'),
- QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name"),
- QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc'),
+ QueryColumn.new(:category, :sortable => "#{IssueCategory.table_name}.name", :groupable => true),
+ QueryColumn.new(:fixed_version, :sortable => ["#{Version.table_name}.effective_date", "#{Version.table_name}.name"], :default_order => 'desc', :groupable => true),
QueryColumn.new(:start_date, :sortable => "#{Issue.table_name}.start_date"),
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date"),
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours"),
- QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio"),
+ QueryColumn.new(:done_ratio, :sortable => "#{Issue.table_name}.done_ratio", :groupable => true),
QueryColumn.new(:created_on, :sortable => "#{Issue.table_name}.created_on", :default_order => 'desc'),
]
cattr_reader :available_columns
).collect {|cf| QueryCustomFieldColumn.new(cf) }
end
+ # Returns an array of columns that can be used to group the results
+ def groupable_columns
+ available_columns.select {|c| c.groupable}
+ end
+
def columns
if has_default_columns?
available_columns.select do |c|
sort_criteria && sort_criteria[arg] && sort_criteria[arg].last
end
+ # Returns the SQL sort order that should be prepended for grouping
+ def group_by_sort_order
+ if grouped? && (column = group_by_column)
+ column.sortable.is_a?(Array) ?
+ column.sortable.collect {|s| "#{s} #{column.default_order}"}.join(',') :
+ "#{column.sortable} #{column.default_order}"
+ end
+ end
+
+ # Returns true if the query is a grouped query
+ def grouped?
+ !group_by.blank?
+ end
+
+ def group_by_column
+ groupable_columns.detect {|c| c.name.to_s == group_by}
+ end
+
def project_statement
project_clauses = []
if project && !@project.descendants.active.empty?
<%= column_header(column) %>
<% end %>
</tr></thead>
+ <% group = false %>
<tbody>
<% issues.each do |issue| -%>
+ <% if @query.grouped? && issue.send(@query.group_by) != group %>
+ <% group = issue.send(@query.group_by) %>
+ <% reset_cycle %>
+ <tr class="group">
+ <td colspan="<%= query.columns.size + 2 %>">
+ <%= group.blank? ? 'None' : group %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
+ </td>
+ </tr>
+ <% end %>
<tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %>">
<td class="checkbox"><%= check_box_tag("ids[]", issue.id, false, :id => nil) %></td>
<td><%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %></td>
<% form_tag({ :controller => 'queries', :action => 'new' }, :id => 'query_form') do %>
<%= hidden_field_tag('project_id', @project.to_param) if @project %>
+ <div id="query_form_content">
<fieldset id="filters"><legend><%= l(:label_filter_plural) %></legend>
<%= render :partial => 'queries/filters', :locals => {:query => @query} %>
+ </fieldset>
+ <p><%= l(:field_group_by) %>
+ <%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %></p>
+ </div>
<p class="buttons">
+
<%= link_to_remote l(:button_apply),
{ :url => { :set_filter => 1 },
:update => "content",
<%= link_to l(:button_save), {}, :onclick => "$('query_form').submit(); return false;", :class => 'icon icon-save' %>
<% end %>
</p>
- </fieldset>
<% end %>
<% else %>
<div class="contextual">
<div id="query_form"></div>
<% html_title @query.name %>
<% end %>
+
<%= error_messages_for 'query' %>
<% if @query.valid? %>
<% if @issues.empty? %>
<p><label for="query_default_columns"><%=l(:label_default_columns)%></label>
<%= check_box_tag 'default_columns', 1, @query.has_default_columns?, :id => 'query_default_columns',
:onclick => 'if (this.checked) {Element.hide("columns")} else {Element.show("columns")}' %></p>
+
+<p><label for="query_group_by"><%= l(:field_group_by) %></label>
+<%= select 'query', 'group_by', @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, :include_blank => true %></p>
</div>
<fieldset><legend><%= l(:label_filter_plural) %></legend>
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages\r
text_wiki_page_destroy_children: Delete child pages and all their descendants\r
setting_password_min_length: Minimum password length\r
+ field_group_by: Group results by\r
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
field_watcher: Watcher
field_identity_url: OpenID URL
field_content: Content
+ field_group_by: Group results by
setting_app_title: Application title
setting_app_subtitle: Application subtitle
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
field_watcher: Observateur
field_identity_url: URL OpenID
field_content: Contenu
+ field_group_by: Grouper par
setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
text_wiki_page_nullify_children: Keep child pages as root pages
text_wiki_page_destroy_children: Delete child pages and all their descendants
setting_password_min_length: Minimum password length
+ field_group_by: Group results by
--- /dev/null
+class AddQueriesGroupBy < ActiveRecord::Migration
+ def self.up
+ add_column :queries, :group_by, :string
+ end
+
+ def self.down
+ remove_column :queries, :group_by
+ end
+end
end
# Returns a PDF string of a list of issues
- def issues_to_pdf(issues, project)
+ def issues_to_pdf(issues, project, query)
pdf = IFPDF.new(current_language)
title = project ? "#{project} - #{l(:label_issue_plural)}" : "#{l(:label_issue_plural)}"
pdf.SetTitle(title)
# rows
pdf.SetFontStyle('',9)
pdf.SetFillColor(255, 255, 255)
- issues.each do |issue|
+ group = false
+ issues.each do |issue|
+ if query.grouped? && issue.send(query.group_by) != group
+ group = issue.send(query.group_by)
+ pdf.SetFontStyle('B',10)
+ pdf.Cell(0, row_height, "#{group.blank? ? 'None' : group.to_s}", 0, 1, 'L')
+ pdf.Line(10, pdf.GetY, 287, pdf.GetY)
+ pdf.SetY(pdf.GetY() + 0.5)
+ pdf.Line(10, pdf.GetY, 287, pdf.GetY)
+ pdf.SetY(pdf.GetY() + 1)
+ pdf.SetFontStyle('',9)
+ end
pdf.Cell(15, row_height, issue.id.to_s, 0, 0, 'L', 1)
pdf.Cell(30, row_height, issue.tracker.name, 0, 0, 'L', 1)
pdf.Cell(30, row_height, issue.status.name, 0, 0, 'L', 1)
table.list td { vertical-align: top; }
table.list td.id { width: 2%; text-align: center;}
table.list td.checkbox { width: 15px; padding: 0px;}
-
+
tr.project td.name a { padding-left: 16px; white-space:nowrap; }
tr.project.parent td.name a { background: url('../images/bullet_toggle_minus.png') no-repeat; }
table.plugins span.description { display: block; font-size: 0.9em; }
table.plugins span.url { display: block; font-size: 0.9em; }
+table.list tbody tr.group td { padding: 0.8em 0 0.5em 0.3em; font-weight: bold; border-bottom: 1px solid #ccc; }
+table.list tbody tr.group span.count { color: #aaa; font-size: 80%; }
+
table.list tbody tr:hover { background-color:#ffffdd; }
+table.list tbody tr.group:hover { background-color:inherit; }
table td {padding:2px;}
table p {margin:0;}
.odd {background-color:#f6f7f8;}
p.subtitle { font-size: 0.9em; margin: -6px 0 12px 0; font-style: italic; }
p.footnote { font-size: 0.9em; margin-top: 0px; margin-bottom: 0px; }
+#query_form_content { font-size: 0.9em; padding: 4px; background: #f6f6f6; border: 1px solid #e4e4e4; }
+#query_form_content fieldset#filters { border-left: 0; border-right: 0; }
+#query_form_content p { margin-top: 0.5em; margin-bottom: 0.5em; }
+
fieldset#filters, fieldset#date-range { padding: 0.7em; margin-bottom: 8px; }
fieldset#filters p { margin: 1.2em 0 0.8em 2px; }
fieldset#filters table { border-collapse: collapse; }
fieldset#filters table td { padding: 0; vertical-align: middle; }
fieldset#filters tr.filter { height: 2em; }
fieldset#filters td.add-filter { text-align: right; vertical-align: top; }
-.buttons { font-size: 0.9em; }
+.buttons { font-size: 0.9em; margin-bottom: 1.4em; }
div#issue-changesets {float:right; width:45%; margin-left: 1em; margin-bottom: 1em; background: #fff; padding-left: 1em; font-size: 90%;}
div#issue-changesets .changeset { padding: 4px;}
is_public: true\r
name: Open issues by priority and tracker\r
filters: |\r
+ --- \r
status_id: \r
:values: \r
- "1"\r
- desc\r
- - tracker\r
- asc\r
+queries_006: \r
+ id: 6\r
+ project_id: \r
+ is_public: true\r
+ name: Open issues grouped by tracker\r
+ filters: |\r
+ --- \r
+ status_id: \r
+ :values: \r
+ - "1"\r
+ :operator: o\r
+\r
+ user_id: 1\r
+ column_names: \r
+ group_by: tracker\r
+ sort_criteria: |\r
+ --- \r
+ - - priority\r
+ - desc\r
\ No newline at end of file
assert_not_nil assigns(:issues)
end
+ def test_index_with_query
+ get :index, :project_id => 1, :query_id => 5
+ assert_response :success
+ assert_template 'index.rhtml'
+ assert_not_nil assigns(:issues)
+ assert_nil assigns(:issue_count_by_group)
+ end
+
+ def test_index_with_grouped_query
+ get :index, :project_id => 1, :query_id => 6
+ assert_response :success
+ assert_template 'index.rhtml'
+ assert_not_nil assigns(:issues)
+ assert_not_nil assigns(:issue_count_by_group)
+ end
+
def test_index_csv_with_project
get :index, :format => 'csv'
assert_response :success
assert_response :success
assert_not_nil assigns(:issues)
assert_equal 'application/pdf', @response.content_type
+
+ get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
+ assert_response :success
+ assert_not_nil assigns(:issues)
+ assert_equal 'application/pdf', @response.content_type
end
def test_index_sort