Feature #37862 » 0001-estimated-remaining-hours-issue-query-column_5.1.2.patch
| app/helpers/queries_helper.rb | ||
|---|---|---|
|
def total_tag(column, value)
|
||
|
label = content_tag('span', "#{column.caption}:")
|
||
|
value =
|
||
|
if [:hours, :spent_hours, :total_spent_hours, :estimated_hours, :total_estimated_hours].include? column.name
|
||
|
if [:hours, :spent_hours, :total_spent_hours, :estimated_hours, :total_estimated_hours, :estimated_remaining_hours].include? column.name
|
||
|
format_hours(value)
|
||
|
else
|
||
|
format_object(value)
|
||
| ... | ... | |
|
'span',
|
||
|
value.to_s(item) {|other| link_to_issue(other, :subject => false, :tracker => false)}.html_safe,
|
||
|
:class => value.css_classes_for(item))
|
||
|
when :hours, :estimated_hours, :total_estimated_hours
|
||
|
when :hours, :estimated_hours, :total_estimated_hours, :estimated_remaining_hours
|
||
|
format_hours(value)
|
||
|
when :spent_hours
|
||
|
link_to_if(value > 0, format_hours(value), project_time_entries_path(item.project, :issue_id => "#{item.id}"))
|
||
| app/models/issue_query.rb | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class IssueQuery < Query
|
||
|
class EstimatedRemainingHoursColumn < QueryColumn
|
||
|
COLUMN_SQL = Arel.sql("COALESCE(#{Issue.table_name}.estimated_hours, 0) * (100 - COALESCE(#{Issue.table_name}.done_ratio, 0)) / 100")
|
||
|
def initialize
|
||
|
super :estimated_remaining_hours, totalable: true, sortable: COLUMN_SQL
|
||
|
end
|
||
|
def value(object)
|
||
|
(object.estimated_hours || 0) * (100 - (object.done_ratio || 0)) / 100
|
||
|
end
|
||
|
def value_object(object)
|
||
|
value(object)
|
||
|
end
|
||
|
end
|
||
|
self.queried_class = Issue
|
||
|
self.view_permission = :view_issues
|
||
| ... | ... | |
|
QueryColumn.new(:due_date, :sortable => "#{Issue.table_name}.due_date", :groupable => true),
|
||
|
QueryColumn.new(:estimated_hours, :sortable => "#{Issue.table_name}.estimated_hours",
|
||
|
:totalable => true),
|
||
|
EstimatedRemainingHoursColumn.new,
|
||
|
QueryColumn.new(
|
||
|
:total_estimated_hours,
|
||
|
:sortable =>
|
||
| ... | ... | |
|
end
|
||
|
disabled_fields = Tracker.disabled_core_fields(trackers).map {|field| field.sub(/_id$/, '')}
|
||
|
disabled_fields << "total_estimated_hours" if disabled_fields.include?("estimated_hours")
|
||
|
if disabled_fields.include?("estimated_hours")
|
||
|
disabled_fields += %w[total_estimated_hours estimated_remaining_hours]
|
||
|
end
|
||
|
@available_columns.reject! do |column|
|
||
|
disabled_fields.include?(column.name.to_s)
|
||
|
end
|
||
| ... | ... | |
|
map_total(scope.sum(:estimated_hours)) {|t| t.to_f.round(2)}
|
||
|
end
|
||
|
def total_for_estimated_remaining_hours(scope)
|
||
|
map_total(scope.sum(EstimatedRemainingHoursColumn::COLUMN_SQL)) {|t| t.to_f.round(2)}
|
||
|
end
|
||
|
# Returns sum of all the issue's time entries hours
|
||
|
def total_for_spent_hours(scope)
|
||
|
total = scope.joins(:time_entries).
|
||
| config/locales/de.yml | ||
|---|---|---|
|
field_watcher: Beobachter
|
||
|
field_default_assigned_to: Standardbearbeiter
|
||
|
field_unique_id: Eindeutige ID
|
||
|
field_estimated_remaining_hours: Geschätzter verbleibender Aufwand
|
||
|
general_csv_decimal_separator: ','
|
||
|
general_csv_encoding: ISO-8859-1
|
||
| config/locales/en.yml | ||
|---|---|---|
|
field_default_project_query: Default project query
|
||
|
field_default_time_entry_activity: Default spent time activity
|
||
|
field_any_searchable: Any searchable text
|
||
|
field_estimated_remaining_hours: Estimated remaining time
|
||
|
setting_app_title: Application title
|
||
|
setting_welcome_text: Welcome text
|
||
| test/unit/query_test.rb | ||
|---|---|---|
|
assert_include :estimated_hours, q.available_totalable_columns.map(&:name)
|
||
|
end
|
||
|
def test_available_totalable_columns_should_include_estimated_remaining_hours
|
||
|
q = IssueQuery.new
|
||
|
assert_include :estimated_remaining_hours, q.available_totalable_columns.map(&:name)
|
||
|
end
|
||
|
def test_available_totalable_columns_should_include_spent_hours
|
||
|
User.current = User.find(1)
|
||
| ... | ... | |
|
)
|
||
|
end
|
||
|
def test_total_for_estimated_remaining_hours
|
||
|
Issue.delete_all
|
||
|
Issue.generate!(:estimated_hours => 5.5, :done_ratio => 50)
|
||
|
Issue.generate!(:estimated_hours => 1.1, :done_ratio => 100)
|
||
|
Issue.generate!
|
||
|
q = IssueQuery.new
|
||
|
assert_equal 2.75, q.total_for(:estimated_remaining_hours)
|
||
|
end
|
||
|
def test_total_by_group_for_estimated_remaining_hours
|
||
|
Issue.delete_all
|
||
|
Issue.generate!(:estimated_hours => 5.5, :assigned_to_id => 2, :done_ratio => 50)
|
||
|
Issue.generate!(:estimated_hours => 1.1, :assigned_to_id => 3, :done_ratio => 100)
|
||
|
Issue.generate!(:estimated_hours => 3.5, :done_ratio => 0)
|
||
|
q = IssueQuery.new(:group_by => 'assigned_to')
|
||
|
assert_equal(
|
||
|
{nil => 3.5, User.find(2) => 2.75, User.find(3) => 0},
|
||
|
q.total_by_group_for(:estimated_remaining_hours)
|
||
|
)
|
||
|
end
|
||
|
def test_total_for_spent_hours
|
||
|
TimeEntry.delete_all
|
||
|
TimeEntry.generate!(:hours => 5.5)
|
||