Skip to content

Commit

Permalink
Simplify request_types translations a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
tumido committed Jan 22, 2018
1 parent 05252be commit 35485ed
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/controllers/miq_request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,13 @@ def prov_scope(opts)
scope << [:with_requester, opts[:user_choice]] if opts[:user_choice] && opts[:user_choice] != "all"

scope << [:with_approval_state, opts[:applied_states]] if opts[:applied_states].present?
scope << [:with_type, request_types_for_model.keys]
scope << [:with_type, MiqRequest::MODEL_REQUEST_TYPES[model_request_type_from_layout].keys]
scope << [:with_request_type, opts[:type_choice]] if opts[:type_choice] && opts[:type_choice] != "all"
scope << [:with_reason_like, opts[:reason_text]] if opts[:reason_text].present?

scope
end

def request_types_for_model # FIXME
MiqRequest::MODEL_REQUEST_TYPES[model_request_type_from_layout].map { |k, v| [k, v.map { |x, y| [x, _(y)] }.to_h] }.to_h
end

def model_request_type_from_layout
case @layout
when "miq_request_ae" then :Automate
Expand All @@ -426,7 +422,9 @@ def model_request_type_from_layout
end

def request_types_for_dropdown
request_types_for_model.values.each_with_object({}) { |t, h| t.each { |k, v| h[k] = v } }
MiqRequest::MODEL_REQUEST_TYPES[model_request_type_from_layout].values.reduce({}) do |hash, item|
hash.merge(item) { |key, val| _(val) }
end
end

# Set all task options to default
Expand All @@ -438,7 +436,7 @@ def prov_set_default_options
opts[:types] = request_types_for_dropdown

opts[:users] = Rbac::Filterer.filtered(MiqRequest.where(
:type => request_types_for_model.keys,
:type => MiqRequest::MODEL_REQUEST_TYPES[model_request_type_from_layout].keys,
:created_on => (30.days.ago.utc)..(Time.now.utc)
)).each_with_object({}) do |r, h|
h[r.requester_id] = if r.requester.nil?
Expand Down

0 comments on commit 35485ed

Please sign in to comment.