@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 => [@query.group_by_sort_order, sort_clause].compact.join(','),
- :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
+ :include => [ :assigned_to, :status, :tracker, :project, :priority, :category, :fixed_version ],
:conditions => @query.statement,
:limit => limit,
:offset => @issue_pages.current.offset
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)
+ Issue.count(:group => @query.group_by_statement, :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}
content_tag('th', column.caption)
end
+ def column_value(column, issue)
+ if column.is_a?(QueryCustomFieldColumn)
+ cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
+ show_value(cv)
+ else
+ value = issue.send(column.name)
+ end
+ end
+
def column_content(column, issue)
if column.is_a?(QueryCustomFieldColumn)
cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
self.name = name
self.sortable = options[:sortable]
self.groupable = options[:groupable] || false
+ if groupable == true
+ self.groupable = name.to_s
+ end
self.default_order = options[:default_order]
end
def initialize(custom_field)
self.name = "cf_#{custom_field.id}".to_sym
self.sortable = custom_field.order_statement || false
+ if %w(list date bool int).include?(custom_field.field_format)
+ self.groupable = custom_field.order_statement
+ end
+ self.groupable ||= false
@cf = custom_field
end
groupable_columns.detect {|c| c.name.to_s == group_by}
end
+ def group_by_statement
+ group_by_column.groupable
+ end
+
def project_statement
project_clauses = []
if project && !@project.descendants.active.empty?
<%= column_header(column) %>
<% end %>
</tr></thead>
- <% group = false %>
+ <% previous_group = false %>
<tbody>
<% issues.each do |issue| -%>
- <% if @query.grouped? && issue.send(@query.group_by) != group %>
- <% group = issue.send(@query.group_by) %>
+ <% if @query.grouped? && (group = column_value(@query.group_by_column, issue) || '') != previous_group %>
<% reset_cycle %>
<tr class="group open">
<td colspan="<%= query.columns.size + 2 %>">
<%= group.blank? ? 'None' : group %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
</td>
</tr>
+ <% previous_group = group %>
<% 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>
user_id: 2
column_names:
+queries_009:
+ id: 9
+ project_id:
+ is_public: true
+ name: Open issues grouped by list custom field
+ filters: |
+ ---
+ status_id:
+ :values:
+ - "1"
+ :operator: o
+
+ user_id: 1
+ column_names:
+ group_by: cf_1
+ sort_criteria: |
+ ---
+ - - priority
+ - desc
assert_nil assigns(:issue_count_by_group)
end
- def test_index_with_grouped_query
+ def test_index_with_query_grouped_by_tracker
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)
+ count_by_group = assigns(:issue_count_by_group)
+ assert_kind_of Hash, count_by_group
+ assert_kind_of Tracker, count_by_group.keys.first
+ assert_not_nil count_by_group[Tracker.find(1)]
+ end
+
+ def test_index_with_query_grouped_by_list_custom_field
+ get :index, :project_id => 1, :query_id => 9
+ assert_response :success
+ assert_template 'index.rhtml'
+ assert_not_nil assigns(:issues)
+ count_by_group = assigns(:issue_count_by_group)
+ assert_kind_of Hash, count_by_group
+ assert_kind_of String, count_by_group.keys.first
+ assert_not_nil count_by_group['MySQL']
end
def test_index_csv_with_project
assert q.has_column?(c)
end
+ def test_groupable_columns_should_include_custom_fields
+ q = Query.new
+ assert q.groupable_columns.detect {|c| c.is_a? QueryCustomFieldColumn}
+ end
+
def test_default_sort
q = Query.new
assert_equal [], q.sort_criteria