Project

General

Profile

Patch #4776 » estimatedTime.diff

Diff file for Redmine 2.3.3 - Olivier Houdas, 2013-10-17 13:20

View differences:

models/issue_query.rb (working copy)
232 232
    raise StatementInvalid.new(e.message)
233 233
  end
234 234

  
235
  # Returns sum of all the issue's estimated_hours 
236
  def issue_sum
237
    Issue.sum(:estimated_hours, :include => [:status, :project],
238
    :conditions => statement << " AND #{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1")
239
  rescue ::ActiveRecord::StatementInvalid => e
240
    raise StatementInvalid.new(e.message)  
241
  end
242

  
235 243
  # Returns the issue count by group or nil if query is not grouped
236 244
  def issue_count_by_group
237 245
    r = nil
......
252 260
    raise StatementInvalid.new(e.message)
253 261
  end
254 262

  
263
  # Returns  sum of the issue's estimated_hours by group or nil if query is not grouped
264
  def issue_sum_by_group
265
    r = nil
266
    if grouped?
267
      begin
268
        r = Issue.sum(:estimated_hours, :group => group_by_statement, :include => [:status, :project], 
269
        :conditions => statement << " AND #{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1")
270
      rescue ActiveRecord::RecordNotFound
271
        r= {r => issue_sum}
272
      end
273
      
274
      c = group_by_column
275
      if c.is_a?(QueryCustomFieldColumn)
276
        r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
277
      end
278
    end
279
    r
280
  rescue ::ActiveRecord::StatementInvalid => e
281
    raise StatementInvalid.new(e.message)
282
  end
283

  
255 284
  # Returns the issues
256 285
  # Valid options are :order, :offset, :limit, :include, :conditions
257 286
  def issues(options={})
controllers/issues_controller.rb (working copy)
78 78
                              :offset => @offset,
79 79
                              :limit => @limit)
80 80
      @issue_count_by_group = @query.issue_count_by_group
81
      @issue_sum_by_group = @query.issue_sum_by_group
81 82

  
82 83
      respond_to do |format|
83 84
        format.html { render :template => 'issues/index', :layout => !request.xhr? }
views/issues/_list.html.erb (working copy)
22 22
    <tr class="group open">
23 23
      <td colspan="<%= query.inline_columns.size + 2 %>">
24 24
        <span class="expander" onclick="toggleRowGroup(this);">&nbsp;</span>
25
        <%= group.blank? ? l(:label_none) : column_content(@query.group_by_column, issue) %> <span class="count"><%= @issue_count_by_group[group] %></span>
25
        <%= group.blank? ? l(:label_none) : column_content(@query.group_by_column, issue) %> <span class="count"><%= @issue_count_by_group[group] %> (<%= l(:field_estimated_hours) %>: <%= l(:label_f_hour_plural, :value => @issue_sum_by_group[group]) %>)</span>
26 26
        <%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
27 27
                             "toggleAllRowGroups(this)", :class => 'toggle-all') %>
28 28
      </td>
......
45 45
</table>
46 46
</div>
47 47
<% end -%>
48
<p align="right"
49
    current page: <b><%=issues.reject{|issue| issue.children?}.collect(&:estimated_hours).reject {|hours| hours.nil?}.sum %></b>
50
    <%= l(:field_estimated_hours) %>: <b><%= l(:label_f_hour_plural, :value => @query.issue_sum) %></b>
51
</p>
(9-9/13)