Skip to content

Commit

Permalink
Merge pull request #2585 from tumido/miq_task_status_as_scope
Browse files Browse the repository at this point in the history
Add status and state scopes, fix time for MiqTask list
  • Loading branch information
martinpovolny committed Nov 2, 2017
2 parents 7a133b7 + 3a6cc45 commit 3a8b739
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/controllers/miq_task_controller.rb
Expand Up @@ -355,15 +355,28 @@ def tasks_scopes(opts, use_times = true)
scope << [:with_userid, opts[:user_choice]]
end

# Add status scope
status = (opts.compact.symbolize_keys.keys & %i(ok queued error warn running))
if status.any?
status_scope_mapping = { :ok => :completed_ok, :warn => :completed_warn, :error => :completed_error } # remap reserved names
status.map! { |s| status_scope_mapping[s] ? status_scope_mapping[s] : s }
scope << [:with_status_in, *status]
else
scope << :no_status_selected
end

# Add time scope
if use_times
t = format_timezone(opts[:time_period].to_i != 0 ? opts[:time_period].days.ago : Time.now, Time.zone, "raw")
scope << [:with_updated_on_between, t.beginning_of_day..t.end_of_day]
scope << [:with_updated_on_between, t.beginning_of_day, t.end_of_day]
end

# Add zone scope
scope << [:with_zone, opts[:zone]] if opts[:zone] && opts[:zone] != "<all>"

# Add state scope
scope << [:with_state, opts[:state_choice]] if opts[:state_choice] != "all"

scope
end

Expand Down

0 comments on commit 3a8b739

Please sign in to comment.