Skip to content

Commit

Permalink
Use copy_params_if_present in report, miq_policy and pxe controllers
Browse files Browse the repository at this point in the history
Issue: #6105
  • Loading branch information
Hilda Stastna committed Sep 5, 2019
1 parent a359b69 commit 2da9a2b
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 55 deletions.
12 changes: 4 additions & 8 deletions app/controllers/miq_ae_tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,28 +422,24 @@ def get_form_vars
if params[:readonly]
@resolve[:new][:readonly] = (params[:readonly] != "1")
end
@resolve[:new][:instance_name] = params[:instance_name] if params.key?(:instance_name)
@resolve[:new][:other_name] = params[:other_name] if params.key?(:other_name)
@resolve[:new][:object_message] = params[:object_message] if params.key?(:object_message)
@resolve[:new][:object_request] = params[:object_request] if params.key?(:object_request)

copy_params_if_present(@resolve[:new], params, %i[instance_name other_name object_message object_request target_class target_id])

ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
f = ("attribute_" + (i + 1).to_s)
v = ("value_" + (i + 1).to_s)
@resolve[:new][:attrs][i][0] = params[f] if params[f.to_sym]
@resolve[:new][:attrs][i][1] = params[v] if params[v.to_sym]
end
@resolve[:new][:target_class] = params[:target_class] if params[:target_class]
# @resolve[:new][:target_attr_name] = params[:target_attr_name] if params.has_key?(:target_attr_name)
if params.key?(:target_class)
@resolve[:new][:target_class] = params[:target_class]
targets = Rbac.filtered(params[:target_class]).select(:id, *columns_for_klass(params[:target_class])) if params[:target_class].present?
unless targets.nil?
@resolve[:targets] = targets.sort_by { |t| t.name.downcase }.collect { |t| [t.name, t.id.to_s] }
@resolve[:new][:target_id] = nil
end
end
@resolve[:new][:target_id] = nil if params[:target_class] == ""
@resolve[:new][:target_id] = params[:target_id] if params.key?(:target_id)
@resolve[:new][:target_id] = nil unless params[:target_class]
@resolve[:button_text] = params[:button_text] if params.key?(:button_text)
@resolve[:button_number] = params[:button_number] if params.key?(:button_number)
@resolve[:throw_ready] = ready_to_throw
Expand Down
41 changes: 16 additions & 25 deletions app/controllers/miq_policy_controller/alerts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ def alert_field_changed
return unless load_edit("alert_edit__#{params[:id]}", "replace_cell__explorer")
@alert = @edit[:alert_id] ? MiqAlert.find(@edit[:alert_id]) : MiqAlert.new

@edit[:new][:description] = params[:description].presence if params[:description]
copy_params_if_present(@edit[:new], params, %i[description event_name])
@edit[:new][:enabled] = params[:enabled_cb] == "1" if params.key?(:enabled_cb)
@edit[:new][:severity] = params[:miq_alert_severity] if params.key?(:miq_alert_severity)
if params[:exp_event]
@edit[:new][:exp_event] = params[:exp_event] == "_hourly_timer_" ? params[:exp_event] : params[:exp_event].to_i
@edit[:new][:repeat_time] = alert_default_repeat_time
end
@edit[:new][:repeat_time] = params[:repeat_time].to_i if params[:repeat_time]
@edit[:new][:event_name] = params[:event_name] if params[:event_name]

if params[:miq_alert_db]
@edit[:new][:db] = params[:miq_alert_db]
Expand Down Expand Up @@ -127,31 +126,35 @@ def alert_field_changed
@edit[:new][:repeat_time] = alert_default_repeat_time if apply_default_repeat_time?
end

copy_params_if_present(@edit[:new][:expression][:options], params, %i[freq_threshold
perf_column
value_threshold
trend_direction
trend_steepness
event_log_message_filter_value
event_log_name
event_log_level
event_log_event_id
event_log_source
debug_trace
value_mw_greater_than
value_mw_less_than
value_mw_garbage_collector
value_mw_threshold])
@edit[:new][:expression][:options][:event_types] = [params[:event_types]].reject(&:blank?) if params[:event_types]
@edit[:new][:expression][:options][:time_threshold] = params[:time_threshold].to_i if params[:time_threshold]
@edit[:new][:expression][:options][:hourly_time_threshold] = params[:hourly_time_threshold].to_i if params[:hourly_time_threshold]
@edit[:new][:expression][:options][:freq_threshold] = params[:freq_threshold] if params[:freq_threshold]
if params[:perf_column]
@edit[:new][:expression][:options][:perf_column] = params[:perf_column]
@edit[:perf_column_unit] = alert_get_perf_column_unit(@edit[:perf_column_options][@edit[:new][:expression][:options][:perf_column]])
end
@edit[:new][:expression][:options][:operator] = params[:select_operator] if params[:select_operator]
@edit[:new][:expression][:options][:value_threshold] = params[:value_threshold] if params[:value_threshold]
if params[:trend_direction]
@edit[:new][:expression][:options][:trend_direction] = params[:trend_direction]
@edit[:new][:expression][:options].delete(:trend_steepness) unless params[:trend_direction].ends_with?("more_than")
@edit[:perf_column_unit] = alert_get_perf_column_unit(@edit[:perf_column_options][@edit[:new][:expression][:options][:perf_column]])
end
@edit[:new][:expression][:options][:trend_steepness] = params[:trend_steepness] if params[:trend_steepness]
@edit[:new][:expression][:options][:rt_time_threshold] = params[:rt_time_threshold].to_i if params[:rt_time_threshold]
@edit[:new][:expression][:options][:event_log_message_filter_type] = params[:select_event_log_message_filter_type] if params[:select_event_log_message_filter_type]
@edit[:new][:expression][:options][:event_log_message_filter_value] = params[:event_log_message_filter_value] if params[:event_log_message_filter_value]
@edit[:new][:expression][:options][:event_log_name] = params[:event_log_name] if params[:event_log_name]
@edit[:new][:expression][:options][:event_log_level] = params[:event_log_level] if params[:event_log_level]
@edit[:new][:expression][:options][:event_log_event_id] = params[:event_log_event_id] if params[:event_log_event_id]
@edit[:new][:expression][:options][:event_log_source] = params[:event_log_source] if params[:event_log_source]
@edit[:new][:expression][:options][:hdw_attr] = params[:select_hdw_attr] if params[:select_hdw_attr]
@edit[:new][:expression][:options][:debug_trace] = params[:debug_trace] if params[:debug_trace]

# Handle VMware Alarm parms
if params.key?(:select_ems_id)
Expand All @@ -174,18 +177,6 @@ def alert_field_changed
end
end

if params[:value_mw_greater_than]
@edit[:new][:expression][:options][:value_mw_greater_than] = params[:value_mw_greater_than]
end
if params[:value_mw_less_than]
@edit[:new][:expression][:options][:value_mw_less_than] = params[:value_mw_less_than]
end
if params[:value_mw_garbage_collector]
@edit[:new][:expression][:options][:value_mw_garbage_collector] = params[:value_mw_garbage_collector]
end
if params[:value_mw_threshold]
@edit[:new][:expression][:options][:value_mw_threshold] = params[:value_mw_threshold]
end
if params[:select_mw_operator]
@edit[:new][:expression][:options][:mw_operator] = params[:select_mw_operator]
end
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/miq_policy_controller/miq_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,14 @@ def action_field_changed
@action = @edit[:action_id] ? MiqAction.find(@edit[:action_id]) : MiqAction.new

@edit[:new][:description] = params[:description].presence if params[:description]
@edit[:new][:options][:from] = params[:from].presence if params[:from]
@edit[:new][:options][:to] = params[:to].presence if params[:to]
copy_params_if_present(@edit[:new][:options], params, %i[from to parent_type attribute value hosts])
@edit[:new][:options][:name] = params[:snapshot_name].presence if params[:snapshot_name]
@edit[:new][:options][:age] = params[:snapshot_age].to_i if params.key?(:snapshot_age)
@edit[:new][:options][:parent_type] = params[:parent_type].presence if params[:parent_type]
if params[:cpu_value]
@edit[:new][:options][:value] = params[:cpu_value]
elsif params[:memory_value]
@edit[:new][:options][:value] = params[:memory_value]
end
@edit[:new][:options][:attribute] = params[:attribute] if params[:attribute]
@edit[:new][:options][:value] = params[:value] if params[:value]
@edit[:new][:options][:ae_message] = params[:object_message] if params.key?(:object_message)
@edit[:new][:options][:ae_request] = params[:object_request] if params[:object_request]
params.each do |var, val|
Expand Down Expand Up @@ -127,7 +123,6 @@ def action_field_changed
update_playbook_variables(params)
end
@edit[:new][:options][:service_template_id] = params[:service_template_id].to_i if params[:service_template_id]
@edit[:new][:options][:hosts] = params[:hosts] if params[:hosts]

# Note that the params[:tag] here is intentionally singular
@edit[:new][:options][:tags] = params[:tag].present? ? [Classification.find(params[:tag]).tag.name] : nil if params[:tag]
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/miq_task_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ def button
# Gather any changed options
def tasks_change_options
@edit = session[:edit]
copy_params_if_present(@edit[:opts], params, %i[user_choice state_choice])
@edit[:opts][:zone] = params[:chosen_zone] if params[:chosen_zone]
@edit[:opts][:user_choice] = params[:user_choice] if params[:user_choice]
@edit[:opts][:time_period] = params[:time_period].to_i if params[:time_period]
@edit[:opts][:queued] = params[:queued] == "1" ? params[:queued] : nil if params[:queued]
@edit[:opts][:ok] = params[:ok] == "1" ? params[:ok] : nil if params[:ok]
@edit[:opts][:error] = params[:error] == "1" ? params[:error] : nil if params[:error]
@edit[:opts][:warn] = params[:warn] == "1" ? params[:warn] : nil if params[:warn]
@edit[:opts][:running] = params[:running] == "1" ? params[:running] : nil if params[:running]
@edit[:opts][:state_choice] = params[:state_choice] if params[:state_choice]

render :update do |page|
page << javascript_prologue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ def template_create_update
# Get variables from edit form
def template_get_form_vars
@ct = @edit[:ct_id] ? CustomizationTemplate.find(@edit[:ct_id]) : CustomizationTemplate.new
@edit[:new][:name] = params[:name] if params[:name]
@edit[:new][:description] = params[:description] if params[:description]
copy_params_if_present(@edit[:new], params, %i[name description typ])
@edit[:new][:img_type] = params[:img_typ] if params[:img_typ]
@edit[:new][:typ] = params[:typ] if params[:typ]
@edit[:new][:script] = params[:script_data] if params[:script_data]
@edit[:new][:script] = @edit[:new][:script] + "..." if !params[:name] && !params[:description] && !params[:img_typ] && !params[:script_data] && !params[:typ]
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/pxe_controller/pxe_image_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def pxe_image_type_set_record_vars(pxe)
# Get variables from edit form
def pxe_image_type_get_form_vars
@pxe_image_type = @edit[:pxe_id] ? PxeImageType.find(@edit[:pxe_id]) : PxeImageType.new
@edit[:new][:name] = params[:name] if params[:name]
@edit[:new][:provision_type] = params[:provision_type] if params[:provision_type]
copy_params_if_present(@edit[:new], params, %i[name provision_type])
end

# Set form variables for edit
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/report_controller/dashboards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ def db_get_form_vars
db_move_cols_up if params[:button] == "up"
db_move_cols_down if params[:button] == "down"
else
@edit[:new][:name] = params[:name] if params[:name]
@edit[:new][:description] = params[:description] if params[:description]
copy_params_if_present(@edit[:new], params, %i[name description])

if params[:locked]
@edit[:new][:locked] = params[:locked].to_i == 1
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/report_controller/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ def selected_menu_consecutive?
end

def menu_get_form_vars
@edit[:form_vars][:selected_reports] = params[:selected_reports] if params[:selected_reports]
@edit[:form_vars][:available_reports] = params[:available_reports] if params[:available_reports]
copy_params_if_present(@edit[:form_vars], params, %i[selected_reports available_reports])
@edit[:temp_arr] = []
id = session[:node_selected].split('__')
selected = id[1].split(':')
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/report_controller/reports/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,11 @@ def gfv_key_style(key, value)
end

def gfv_report_fields
@edit[:new][:pdf_page_size] = params[:pdf_page_size] if params[:pdf_page_size]
copy_params_if_present(@edit[:new], params, %i[pdf_page_size name title])
if params[:chosen_queue_timeout]
@edit[:new][:queue_timeout] = params[:chosen_queue_timeout].blank? ? nil : params[:chosen_queue_timeout].to_i
end
@edit[:new][:row_limit] = params[:row_limit].presence || ""
@edit[:new][:name] = params[:name] if params[:name]
@edit[:new][:title] = params[:title] if params[:title]
end

def gfv_move_cols_buttons
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/report_controller/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ def schedule_set_form_vars
# Get variables from edit form
def schedule_get_form_vars
@schedule = @edit[:sched_id] ? MiqSchedule.find(@edit[:sched_id]) : MiqSchedule.new(:userid => session[:userid])
@edit[:new][:name] = params[:name] if params[:name]
@edit[:new][:description] = params[:description] if params[:description]
copy_params_if_present(@edit[:new], params, %i[name description])
@edit[:new][:enabled] = (params[:enabled] == "1") if params[:enabled]
@edit[:new][:filter] = params[:filter_typ] if params[:filter_typ]
@edit[:new][:subfilter] = params[:subfilter_typ] if params[:subfilter_typ]
Expand Down

0 comments on commit 2da9a2b

Please sign in to comment.