Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display checkable folders in the Alert Profile Assignment tree for ems_folder #1747

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions app/controllers/miq_policy_controller/alert_profiles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,35 +180,34 @@ def alert_profile_build_obj_tree
tree = nil
return nil if alert_profile_get_assign_to_objects_empty?
if @assign[:new][:assign_to] == "ems_folder"
tree = TreeBuilderBelongsToHac.new(:vat_tree,
:vat,
@sb,
true,
:edit => @edit,
:filters => @filters,
:group => @group,
:selected => @assign[:new][:objects].collect { |f| "EmsFolder_#{f}" })
tree = instantiate_tree("TreeBuilderBelongsToVat",
:vat_tree,
:vat,
@assign[:new][:objects].collect { |f| "EmsFolder_#{f}" })
elsif @assign[:new][:assign_to] == "resource_pool"
tree = TreeBuilderBelongsToHac.new(:hac_tree,
:hac,
@sb,
true,
:edit => @edit,
:filters => @filters,
:group => @group,
:selected => @assign[:new][:objects].collect { |f| "ResourcePool_#{f}" })
tree = instantiate_tree("TreeBuilderBelongsToHac",
:hac_tree,
:hac,
@assign[:new][:objects].collect { |f| "ResourcePool_#{f}" })
else
tree = TreeBuilderAlertProfileObj.new(:object_tree,
:object,
@sb,
true,
:assign_to => @assign[:new][:assign_to],
:cat => @assign[:new][:cat],
:selected => @assign[:new][:objects])
tree = instantiate_tree("TreeBuilderAlertProfileObj",
:object_tree,
:object,
@assign[:new][:objects])
end
tree
end

def instantiate_tree(tree_class, tree_name, type, selected)
tree_class.constantize.new(tree_name,
type,
@sb,
true,
:assign_to => @assign[:new][:assign_to],
:cat => @assign[:new][:cat],
:selected => selected)
end

def alert_profile_build_edit_screen
@edit = {}
@edit[:new] = {}
Expand Down
24 changes: 19 additions & 5 deletions app/presenters/tree_builder_belongs_to_hac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class TreeBuilderBelongsToHac < TreeBuilder

def override(node, object, _pid, options)
if [ExtManagementSystem, EmsCluster, Datacenter, EmsFolder, ResourcePool].any? { |klass| object.kind_of?(klass) }
node[:select] = options.key?(:selected) && options[:selected].include?("#{object.class.name}_#{object[:id]}")
node[:select] = if @assign_to
options.key?(:selected) && options[:selected].include?("ResourcePool_#{object[:id]}")
else
options.key?(:selected) && options[:selected].include?("#{object.class.name}_#{object[:id]}")
end
end
node[:hideCheckbox] = true if object.kind_of?(Host) && object.ems_cluster_id.present?
node[:cfmeNoClick] = true
Expand All @@ -18,6 +22,7 @@ def initialize(name, type, sandbox, build, params)
@edit = params[:edit]
@group = params[:group]
@selected = params[:selected]
@assign_to = params[:assign_to]
# need to remove tree info
TreeState.new(sandbox).remove_tree(name)
super(name, type, sandbox, build)
Expand All @@ -29,16 +34,25 @@ def tree_init_options(_tree_name)
{:full_ids => true,
:add_root => false,
:lazy => false,
:checkable_checkboxes => @edit.present?,
:checkable_checkboxes => @edit.present? || @assign_to.present?,
:selected => @selected}
end

def set_locals_for_render
locals = super
locals.merge!(:check_url => "/ops/rbac_group_field_changed/#{group_id}___",
:oncheck => @edit ? "miqOnCheckUserFilters" : nil,

oncheck, check_url = if @assign_to
["miqOnCheckHandler", "/miq_policy/alert_profile_assign_changed/"]
elsif @edit
["miqOnCheckUserFilters", "/ops/rbac_group_field_changed/#{group_id}___"]
else
[nil, "/ops/rbac_group_field_changed/#{group_id}___"]
end

locals.merge!(:oncheck => oncheck,
:check_url => check_url,
:highlight_changes => @assign_to ? false : true,
:checkboxes => true,
:highlight_changes => true,
:onclick => false)
end

Expand Down