estimated_hour_exclude_parent.diff

RedminePro Yang, 2011-04-19 14:40

Download (3.37 KB)

View differences:

app/models/query.rb (working copy)
503 503
    raise StatementInvalid.new(e.message)
504 504
  end
505 505
  
506
   # Returns sum of all the issue's estimated_hours 
507
  def issue_sum
508
    Issue.sum(:estimated_hours, :include => [:status, :project],
509
    :conditions => Issue.merge_conditions(statement , "#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"))
510
  rescue ::ActiveRecord::StatementInvalid => e
511
    raise StatementInvalid.new(e.message)  
512
  end   
513
  
506 514
  # Returns the issue count by group or nil if query is not grouped
507 515
  def issue_count_by_group
508 516
    r = nil
......
523 531
    raise StatementInvalid.new(e.message)
524 532
  end
525 533
  
534
   # Returns  sum of the issue's estimated_hours by group or nil if query is not grouped
535
  def issue_sum_by_group
536
    r = nil
537
    if grouped?
538
      begin
539
        r = Issue.sum(:estimated_hours, :group => group_by_statement, :include => [:status, :project], 
540
        :conditions => Issue.merge_conditions(statement ,  "#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"))
541
      rescue ActiveRecord::RecordNotFound
542
        r= {r => issue_sum}
543
      end
544
      
545
      c = group_by_column
546
      if c.is_a?(QueryCustomFieldColumn)
547
        r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
548
      end
549
    end
550
    r
551
  rescue ::ActiveRecord::StatementInvalid => e
552
    raise StatementInvalid.new(e.message)
553
  end
554
  
526 555
  # Returns the issues
527 556
  # Valid options are :order, :offset, :limit, :include, :conditions
528 557
  def issues(options={})
app/controllers/issues_controller.rb (working copy)
85 85
                              :order => sort_clause, 
86 86
                              :offset => @offset, 
87 87
                              :limit => @limit)
88
      @issue_count_by_group = @query.issue_count_by_group
88
      @issue_count_by_group = @query.issue_count_by_group                        
89
      @issue_sum_by_group = @query.issue_sum_by_group
89 90
      
90 91
      respond_to do |format|
91 92
        format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
app/views/issues/_list.rhtml (working copy)
19 19
    <tr class="group open">
20 20
    	<td colspan="<%= query.columns.size + 2 %>">
21 21
    		<span class="expander" onclick="toggleRowGroup(this); return false;">&nbsp;</span>
22
      	<%= group.blank? ? 'None' : column_content(@query.group_by_column, issue) %> <span class="count">(<%= @issue_count_by_group[group] %>)</span>
22
      	<%= 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>
23 23
    	</td>
24 24
		</tr>
25 25
		<% previous_group = group %>
......
34 34
</table>
35 35
</div>
36 36
<% end -%>
37
<p align="right"
38
    Current page: <b><%=issues.reject{|issue| issue.children?}.collect(&:estimated_hours).reject {|hours| hours.nil?}.sum %></b>
39
    <%= l(:label_total) %>: <b><%=@query.issue_sum %></b>
40
</p>