Project

General

Profile

« Previous | Next » 

Revision e282ff7b

Added by Ori Rabin over 8 years ago

Fixes #11464 - use host inherited views for hostgroup parent parameters

View differences:

app/controllers/hostgroups_controller.rb
before_filter :find_resource, :only => [:nest, :clone, :edit, :update, :destroy]
before_filter :ajax_request, :only => [:process_hostgroup, :current_parameters, :puppetclass_parameters]
before_filter :taxonomy_scope, :only => [:new, :edit, :process_hostgroup]
before_filter :update_parent_params!, :only => [:update, :create]
before_filter :taxonomy_scope, :only => [:new, :edit, :process_hostgroup, :current_parameters]
def index
@hostgroups = resource_base.search_for(params[:search], :order => params[:order]).paginate :page => params[:page]
......
def current_parameters
Taxonomy.as_taxonomy @organization, @location do
inherited_parameters = Hostgroup.find(params['hostgroup_parent_id']).inherited_params(true) if params['hostgroup_parent_id']
hostgroup_parent_parameters = Hostgroup.authorized(:view_hostgroups).find(params['hostgroup_parent_id']).parameters(true) if params['hostgroup_parent_id'].present?
hostgroup_parameters = params['hostgroup_id'] != "null" ? Hostgroup.authorized(:view_hostgroups).find(params['hostgroup_id']).group_parameters : []
render :partial => "common_parameters/inherited_parameters",
:locals => { :inherited_parameters => inherited_parameters }
:locals => { :inherited_parameters => hostgroup_parent_parameters, :parameters => hostgroup_parameters }
end
end
......
end
end
def parse_parent_params(parameters)
parameter_keys = parameters.select { |p| p.match(/key/) }.values
parameter_values = parameters.select { |p| p.match(/value/) }.values
parameters = {}
parameters_hash = parameter_keys.zip(parameter_values).reject{|k, v| v.blank?}
parameters_hash.each_with_index do |val, i|
key, value = val[0], val[1]
id = GroupParameter.last.id + 1 + i
parameters[id] = { 'name' => key, 'value' => value } if value.present?
end
parameters
end
def update_parent_params!
parent_params = parse_parent_params(params.select { |k| k.match(/parent.*/) } )
if params[:hostgroup] && (params[:hostgroup][:group_parameters_attributes].present? || parent_params.present?)
params[:hostgroup][:group_parameters_attributes] ||= {}
params[:hostgroup][:group_parameters_attributes].merge!(parent_params)
end
end
def define_parent
if params[:hostgroup][:parent_id].present?
@parent = Hostgroup.authorized(:view_hostgroups).find(params[:hostgroup][:parent_id])

Also available in: Unified diff