app/models/foreman_tasks/task.rb in foreman-tasks-0.9.1 vs app/models/foreman_tasks/task.rb in foreman-tasks-0.9.2
- old
+ new
@@ -36,14 +36,14 @@
scoped_search :on => :start_at, :complete_value => false
scoped_search :on => :ended_at, :complete_value => false
scoped_search :on => :parent_task_id, :complete_value => true
scoped_search :relation => :locks, :on => :resource_type, :complete_value => true, :rename => 'resource_type', :ext_method => :search_by_generic_resource
scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'resource_id', :ext_method => :search_by_generic_resource
- scoped_search :relation => :owners,
- :on => :id,
- :complete_value => true,
- :rename => 'owner.id',
+ scoped_search :relation => :owners,
+ :on => :id,
+ :complete_value => true,
+ :rename => 'owner.id',
:ext_method => :search_by_owner,
:validator => ->(value) { ScopedSearch::Validators::INTEGER.call(value) || value == 'current_user' }
scoped_search :relation => :owners, :on => :login, :complete_value => true, :rename => 'owner.login', :ext_method => :search_by_owner
scoped_search :relation => :owners, :on => :firstname, :complete_value => true, :rename => 'owner.firstname', :ext_method => :search_by_owner
scoped_search :relation => :task_groups, :on => :id, :complete_value => true, :rename => 'task_group.id', :validator => ScopedSearch::Validators::INTEGER
@@ -170,10 +170,12 @@
groups = [groups] unless groups.is_a? Array
(groups - task_groups).each { |group| task_groups << group }
end
def sub_tasks_counts
- result = %w(cancelled error pending success warning).zip([0].cycle).to_h
+ result = %w(cancelled error pending success warning).inject({}) do |hash, state|
+ hash.update(state => 0)
+ end
result.update sub_tasks.group(:result).count
sum = result.values.reduce(:+)
if respond_to?(:main_action) && main_action.respond_to?(:total_count)
result[:total] = main_action.total_count
# In case of batch planning there might be some plans still unplanned (not present in database).