Project

General

Profile

Patch #4776 » sumEstimatedTimeByGroup.patch

Ewan Makepeace, 2010-02-09 08:25

View differences:

controllers/issues_controller.rb (working copy)
73 73
                              :offset => @issue_pages.current.offset, 
74 74
                              :limit => limit)
75 75
      @issue_count_by_group = @query.issue_count_by_group
76
      @issue_sum_by_group = @query.issue_sum_by_group
76 77
      
77 78
      respond_to do |format|
78 79
        format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
models/query.rb (working copy)
415 415
    raise StatementInvalid.new(e.message)
416 416
  end
417 417
  
418
   # Returns sum of all the issue's estimated_hours 
419
  def issue_sum
420
    Issue.sum(:estimated_hours, :include => [:status, :project], :conditions => statement)
421
  rescue ::ActiveRecord::StatementInvalid => e
422
    raise StatementInvalid.new(e.message)  
423
  end   
424
  
418 425
  # Returns the issue count by group or nil if query is not grouped
419 426
  def issue_count_by_group
420 427
    r = nil
......
435 442
    raise StatementInvalid.new(e.message)
436 443
  end
437 444
  
445
   # Returns  sum of the issue's estimated_hours by group or nil if query is not grouped
446
  def issue_sum_by_group
447
    r = nil
448
    if grouped?
449
      begin
450
        r = Issue.sum(:estimated_hours, :group => group_by_statement, :include => [:status, :project], :conditions => statement)
451
      rescue ActiveRecord::RecordNotFound
452
        r= {r => issue_sum}
453
      end
454
      
455
      c = group_by_column
456
      if c.is_a?(QueryCustomFieldColumn)
457
        r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
458
      end
459
    end
460
    r
461
  rescue ::ActiveRecord::StatementInvalid => e
462
    raise StatementInvalid.new(e.message)
463
  end
464
  
438 465
  # Returns the issues
439 466
  # Valid options are :order, :offset, :limit, :include, :conditions
440 467
  def issues(options={})
views/issues/_list.rhtml (working copy)
18 18
    <tr class="group open">
19 19
    	<td colspan="<%= query.columns.size + 2 %>">
20 20
    		<span class="expander" onclick="toggleRowGroup(this); return false;">&nbsp;</span>
21
      	<%= group.blank? ? 'None' : column_content(@query.group_by_column, issue) %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
21
      	<%= group.blank? ? 'None' : column_content(@query.group_by_column, issue) %> <span class="count">(<%= @issue_count_by_group[group] %>, <%= l(:label_total) %>:<%= @issue_sum_by_group[group] %>)</span>
22 22
    	</td>
23 23
		</tr>
24 24
		<% previous_group = group %>
(4-4/13)