diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index a63ffae82..30560dcfb 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -53,7 +53,6 @@ class TimelogController < ApplicationController @entry_count = scope.count @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] @entries = scope.offset(@entry_pages.offset).limit(@entry_pages.per_page).to_a - @total_hours = scope.sum(:hours).to_f render :layout => !request.xhr? } diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 8d23d95cd..42470d14b 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -33,28 +33,13 @@ module IssuesHelper end def grouped_issue_list(issues, query, issue_count_by_group, &block) - previous_group, first = false, true - totals_by_group = query.totalable_columns.inject({}) do |h, column| - h[column] = query.total_by_group_for(column) - h - end - issue_list(issues) do |issue, level| - group_name = group_count = nil - if query.grouped? - group = query.group_by_column.value(issue) - if first || group != previous_group - if group.blank? && group != false - group_name = "(#{l(:label_blank_value)})" - else - group_name = format_object(group) - end - group_name ||= "" - group_count = issue_count_by_group[group] - group_totals = totals_by_group.map {|column, t| total_tag(column, t[group] || 0)}.join(" ").html_safe - end + ancestors = [] + grouped_query_results(issues, query, issue_count_by_group) do |issue, group_name, group_count, group_totals| + while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) + ancestors.pop end - yield issue, level, group_name, group_count, group_totals - previous_group, first = group, false + yield issue, ancestors.size, group_name, group_count, group_totals + ancestors << issue unless issue.leaf? end end diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index e2e09c7de..6bf8b3177 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -78,6 +78,11 @@ module QueriesHelper query_filters_hidden_tags(query) + query_columns_hidden_tags(query) end + def group_by_column_select_tag(query) + options = [[]] + query.groupable_columns.collect {|c| [c.caption, c.name.to_s]} + select_tag('group_by', options_for_select(options, @query.group_by)) + end + def available_block_columns_tags(query) tags = ''.html_safe query.available_block_columns.each do |column| @@ -108,6 +113,32 @@ module QueriesHelper render :partial => 'queries/columns', :locals => {:query => query, :tag_name => tag_name} end + def grouped_query_results(items, query, item_count_by_group, &block) + previous_group, first = false, true + totals_by_group = query.totalable_columns.inject({}) do |h, column| + h[column] = query.total_by_group_for(column) + h + end + items.each do |item| + group_name = group_count = nil + if query.grouped? + group = query.group_by_column.value(item) + if first || group != previous_group + if group.blank? && group != false + group_name = "(#{l(:label_blank_value)})" + else + group_name = format_object(group) + end + group_name ||= "" + group_count = item_count_by_group ? item_count_by_group[group] : nil + group_totals = totals_by_group.map {|column, t| total_tag(column, t[group] || 0)}.join(" ").html_safe + end + end + yield item, group_name, group_count, group_totals + previous_group, first = group, false + end + end + def render_query_totals(query) return unless query.totalable_columns.present? totals = query.totalable_columns.map do |column| diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index e13c46a2f..0846d7096 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -249,6 +249,10 @@ class IssueQuery < Query end end + def default_totalable_names + Setting.issue_list_default_totals.map(&:to_sym) + end + def base_scope Issue.visible.joins(:status, :project).where(statement) end diff --git a/app/models/query.rb b/app/models/query.rb index 5e8e0cd90..9a1dc0d5a 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -76,11 +76,11 @@ end class QueryCustomFieldColumn < QueryColumn - def initialize(custom_field) + def initialize(custom_field, options={}) self.name = "cf_#{custom_field.id}".to_sym self.sortable = custom_field.order_statement || false self.groupable = custom_field.group_statement || false - self.totalable = custom_field.totalable? + self.totalable = options.key?(:totalable) ? !!options[:totalable] : custom_field.totalable? @inline = true @cf = custom_field end @@ -120,8 +120,8 @@ end class QueryAssociationCustomFieldColumn < QueryCustomFieldColumn - def initialize(association, custom_field) - super(custom_field) + def initialize(association, custom_field, options={}) + super(custom_field, options) self.name = "#{association}.cf_#{custom_field.id}".to_sym # TODO: support sorting/grouping by association custom field self.sortable = false @@ -546,6 +546,10 @@ class Query < ActiveRecord::Base [] end + def default_totalable_names + [] + end + def column_names=(names) if names names = names.select {|n| n.is_a?(Symbol) || !n.blank? } @@ -583,7 +587,7 @@ class Query < ActiveRecord::Base end def totalable_names - options[:totalable_names] || Setting.issue_list_default_totals.map(&:to_sym) || [] + options[:totalable_names] || default_totalable_names || [] end def sort_criteria=(arg) diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index dde34264a..c667fb651 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -28,7 +28,7 @@ class TimeEntryQuery < Query QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true), QueryColumn.new(:issue, :sortable => "#{Issue.table_name}.id"), QueryColumn.new(:comments), - QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours"), + QueryColumn.new(:hours, :sortable => "#{TimeEntry.table_name}.hours", :totalable => true), ] def initialize(attributes=nil, *args) @@ -105,7 +105,7 @@ class TimeEntryQuery < Query @available_columns += TimeEntryCustomField.visible. map {|cf| QueryCustomFieldColumn.new(cf) } @available_columns += IssueCustomField.visible. - map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf) } + map {|cf| QueryAssociationCustomFieldColumn.new(:issue, cf, :totalable => false) } @available_columns end @@ -113,6 +113,14 @@ class TimeEntryQuery < Query @default_columns_names ||= [:project, :spent_on, :user, :activity, :issue, :comments, :hours] end + def default_totalable_names + [:hours] + end + + def base_scope + TimeEntry.visible.where(statement) + end + def results_scope(options={}) order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?) @@ -123,6 +131,11 @@ class TimeEntryQuery < Query includes(:activity). references(:activity) end + + # Returns sum of all the spent hours + def total_for_hours(scope) + map_total(scope.sum(:hours)) {|t| t.to_f.round(2)} + end def sql_for_issue_id_field(field, operator, value) case operator diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index d120ce71e..d0fd943f0 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -7,65 +7,10 @@
<%= l(:label_no_data) %>
diff --git a/app/views/queries/_query_form.html.erb b/app/views/queries/_query_form.html.erb new file mode 100644 index 000000000..bf0b0c257 --- /dev/null +++ b/app/views/queries/_query_form.html.erb @@ -0,0 +1,62 @@ +<%= hidden_field_tag 'set_filter', '1' %> +<%= hidden_field_tag 'type', @query.type, :disabled => true, :id => 'query_type' %> + + + +<%= error_messages_for @query %> diff --git a/app/views/timelog/_date_range.html.erb b/app/views/timelog/_date_range.html.erb index 91b96d8b7..db07c465e 100644 --- a/app/views/timelog/_date_range.html.erb +++ b/app/views/timelog/_date_range.html.erb @@ -1,44 +1,4 @@ - +<%= render :partial => 'queries/query_form' %>