Skip to content

Commit

Permalink
Display an unassigned configuration profile group in foreman tree & list
Browse files Browse the repository at this point in the history
  • Loading branch information
AparnaKarve committed Jun 5, 2015
1 parent 3872a63 commit aa6e82c
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 28 deletions.
12 changes: 10 additions & 2 deletions vmdb/app/controllers/application_controller.rb
Expand Up @@ -1116,7 +1116,7 @@ def view_to_xml(view, from_idx = 0, to_idx = -1, options = {})
table.data[from_idx..to_idx].each do |row|
@id = row['id']

new_row = root.add_element('row', "id" => to_cid(row['id']))
new_row = root.add_element('row', "id" => list_row_id(row))
new_row.add_element('cell').text = '0' # Checkbox column unchecked

# Generate html for the list icon
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def listicon_image(view)
"../../../pictures/#{item.picture.basename}"
end
end
image ? image : "#{pn}#{(@listicon || view.db).underscore}.png"
list_row_image(pn, image, (@listicon || view.db).underscore, item.name)
end

def get_host_for_vm(vm)
Expand Down Expand Up @@ -2709,6 +2709,14 @@ def controller_for_common_methods
end
end

def list_row_id(row)
to_cid(row['id'])
end

def list_row_image(image_path, image, model_image, _itemname)
image ? image : "#{image_path}#{model_image}.png"
end

def render_flash_not_applicable_to_model(type)
add_flash(_("%{task} does not apply to selected %{model}") % {:model => ui_lookup(:table => "miq_template"), :task => type.capitalize}, :error)
render_flash { |page| page << '$(\'#main_div\').scrollTop();' }
Expand Down
142 changes: 128 additions & 14 deletions vmdb/app/controllers/provider_foreman_controller.rb
Expand Up @@ -213,7 +213,7 @@ def tree_select
load_or_clear_adv_search

unless action_name == "reload"
if %w(x_show x_search_by_name).include?(action_name) && configuration_profile_record?
if active_tab_configured_systems?
@sb[:active_tab] = 'configured_systems'
else
@sb[:active_tab] = 'summary'
Expand Down Expand Up @@ -257,15 +257,12 @@ def load_or_clear_adv_search

def x_show
@explorer = true
if x_active_tree == :foreman_providers_tree
@record = foreman_providers_tree_rec
elsif x_active_tree == :cs_filter_tree
@record = cs_filter_tree_rec
end
tree_record unless unassigned_configuration_profile?(params[:id])

respond_to do |format|
format.js do
unless @record
redirect_to :action => "explorer"
check_for_unassigned_configuration_profile
return
end
params[:id] = x_build_node_id(@record) # Get the tree node id
Expand All @@ -280,6 +277,33 @@ def x_show
end
end

def tree_record
if x_active_tree == :foreman_providers_tree
@record = foreman_providers_tree_rec
elsif x_active_tree == :cs_filter_tree
@record = cs_filter_tree_rec
end
end

def check_for_unassigned_configuration_profile
if action_name == "x_show"
unassigned_configuration_profile?(params[:id]) ? tree_select : tree_select_unprovisioned_configured_system
elsif action_name == "tree_select"
tree_select_unprovisioned_configured_system
else
redirect_to :action => "explorer"
end
end

def tree_select_unprovisioned_configured_system
if unassigned_configuration_profile?(x_node)
params[:id] = "cs-#{params[:id]}"
tree_select
else
redirect_to :action => "explorer"
end
end

def foreman_providers_tree_rec
nodes = x_node.split('-')
case nodes.first
Expand Down Expand Up @@ -439,7 +463,11 @@ def get_node_info(treenodeid)
when "MiqSearch"
miq_search_node
else
default_node
if unassigned_configuration_profile?(treenodeid)
configuration_profile_node(id, model)
else
default_node
end
end
@right_cell_text += @edit[:adv_search_applied][:text] if x_tree[:type] == :filter && @edit && @edit[:adv_search_applied]

Expand All @@ -463,6 +491,7 @@ def provider_node(id, model)
options[:where_clause] = ["configuration_manager_id IN (?)", provider.id]
@no_checkboxes = true
process_show_list(options)
add_unassigned_configuration_profile_record(provider.id)
record_model = ui_lookup(:model => model ? model : TreeBuilder.get_model_for_prefix(@nodetype))
@right_cell_text =
_("%{model} \"%{name}\"") %
Expand All @@ -472,21 +501,25 @@ def provider_node(id, model)
end

def configuration_profile_node(id, model)
@record = @configuration_profile_record = identify_record(id, ConfigurationProfile)
if model
@record = @configuration_profile_record = identify_record(id, ConfigurationProfile)
else
@record = @configuration_profile_record = ConfigurationProfile.new
end
if @configuration_profile_record.nil?
self.x_node = "root"
get_node_info("root")
return
else
options = {:model => "ConfiguredSystem"}
options[:where_clause] = ["configuration_profile_id IN (?)", @configuration_profile_record.id]
options[:where_clause] =
["configuration_manager_id IN (?) AND \
configuration_profile_id IS NULL", id] if empty_configuration_profile_record?(@configuration_profile_record)
process_show_list(options)
record_model = ui_lookup(:model => model ? model : TreeBuilder.get_model_for_prefix(@nodetype))
if @sb[:active_tab] == 'configured_systems'
@right_cell_text =
_("%{model} \"%{name}\"") %
{:name => @configuration_profile_record.name,
:model => "#{ui_lookup(:tables => "configured_system")} under #{record_model}"}
configuration_profile_right_cell_text(model)
else
@showtype = 'main'
@pages = nil
Expand Down Expand Up @@ -643,7 +676,7 @@ def update_partials(record_showing, presenter, r)
end
partial = 'form'
presenter[:update_partials][:main_div] = r[:partial => partial, :locals => partial_locals]
elsif @configuration_profile_record
elsif valid_configuration_profile_record?(@configuration_profile_record)
presenter[:set_visible_elements][:form_buttons_div] = false
presenter[:update_partials][:main_div] = r[:partial => "configuration_profile",
:locals => {:controller => 'provider_foreman'}]
Expand Down Expand Up @@ -785,6 +818,87 @@ def tagging_explorer_controller?
@explorer
end

def active_tab_configured_systems?
(%w(x_show x_search_by_name).include?(action_name) && configuration_profile_record?) ||
unassigned_configuration_profile?(x_node)
end

def unassigned_configuration_profile?(node)
_type, _pid, nodeinfo = node.split("_").last.split("-")
nodeinfo == "unassigned"
end

def empty_configuration_profile_record?(configuration_profile_record)
configuration_profile_record.try(:id).nil?
end

def valid_configuration_profile_record?(configuration_profile_record)
configuration_profile_record.try(:id)
end

def list_row_id(row)
if row['name'] == _("Unassigned Profiles Group") && row['id'].nil?
"-#{row['configuration_manager_id']}-unassigned"
else
to_cid(row['id'])
end
end

def list_row_image(image_path, image, model_image, itemname)
if itemname == _("Unassigned Profiles Group")
image_path ? "#{image_path}folder.png" : "folder"
else
super
end
end

def configuration_profile_right_cell_text(model)
record_model = ui_lookup(:model => model ? model : TreeBuilder.get_model_for_prefix(@nodetype))
return if @sb[:active_tab] != 'configured_systems'
if valid_configuration_profile_record?(@configuration_profile_record)
@right_cell_text =
_("%{model} \"%{name}\"") %
{:name => @configuration_profile_record.name,
:model => "#{ui_lookup(:tables => "configured_system")} under #{record_model}"}
else
name = _("Unassigned Profiles Group")
@right_cell_text =
_("%{model}") %
{:model => "#{ui_lookup(:tables => "configured_system")} under \"#{name}\""}
end
end

def add_unassigned_configuration_profile_record(provider_id)
unprovisioned_configured_systems =
ConfiguredSystem.where(:configuration_manager_id => provider_id, :configuration_profile_id => nil).count

return if unprovisioned_configured_systems == 0

unassigned_configuration_profile_desc = unassigned_configuration_profile_name = _("Unassigned Profiles Group")
unassigned_configuration_profile = ConfigurationProfile.new
unassigned_configuration_profile.configuration_manager_id = provider_id
unassigned_configuration_profile.name = unassigned_configuration_profile_name
unassigned_configuration_profile.description = unassigned_configuration_profile_desc

unassigned_profile_row =
{'description' => unassigned_configuration_profile_desc,
'total_configured_systems' => unprovisioned_configured_systems,
'configuration_environment_name' => unassigned_configuration_profile.configuration_environment_name,
'my_zone' => unassigned_configuration_profile.my_zone,
'region_description' => unassigned_configuration_profile.region_description,
'name' => unassigned_configuration_profile_name,
'configuration_manager_id' => provider_id
}

add_unassigned_configuration_profile_record_to_view(unassigned_profile_row, unassigned_configuration_profile)
end

def add_unassigned_configuration_profile_record_to_view(unassigned_profile_row, unassigned_configuration_profile)
@view.table.data.push(unassigned_profile_row)
@targets_hash[unassigned_profile_row['id']] = unassigned_configuration_profile
@grid_xml = view_to_xml(@view, 0, -1, :association => nil)
end

def set_root_node
self.x_node = "root"
get_node_info(x_node)
Expand Down
5 changes: 5 additions & 0 deletions vmdb/app/helpers/application_helper.rb
Expand Up @@ -2348,6 +2348,7 @@ def foreman_providers_tree_center_tb(nodes)
when "root" then "provider_foreman_center_tb"
when "e" then "configuration_profile_foreman_center_tb"
when "cp" then configuration_profile_center_tb
else unassigned_configuration_profile_node(nodes)
end
end

Expand All @@ -2365,6 +2366,10 @@ def configuration_profile_center_tb
end
end

def unassigned_configuration_profile_node(nodes)
configuration_profile_center_tb if nodes[2] == "unassigned"
end

# check if back to summary button needs to be show
def display_back_button?
# don't need to back button if @record is not there or @record doesnt have name or
Expand Down
3 changes: 3 additions & 0 deletions vmdb/app/presenters/tree_builder.rb
Expand Up @@ -84,6 +84,9 @@ def x_get_child_nodes(id)
elsif model.nil? && [:sandt_tree, :svccat_tree, :stcat_tree].include?(x_active_tree)
# Creating empty record to show items under unassigned catalog node
ServiceTemplateCatalog.new
elsif model.nil? && [:foreman_providers_tree].include?(x_active_tree)
# Creating empty record to show items under unassigned catalog node
ConfigurationProfile.new
else
model.constantize.find(from_cid(rec_id))
end
Expand Down
30 changes: 27 additions & 3 deletions vmdb/app/presenters/tree_builder_foreman.rb
Expand Up @@ -18,9 +18,33 @@ def x_get_tree_roots(options)
end

def x_get_tree_cmf_kids(object, options)
count_only_or_objects(options[:count_only],
ConfigurationProfile.where(:configuration_manager_id => object[:id]),
"name")
assigned_configuration_profile_objs =
count_only_or_objects(options[:count_only],
ConfigurationProfile.where(:configuration_manager_id => object[:id]),
"name")
unassigned_configuration_profile_objs =
fetch_unassigned_configuration_profile_objects(options[:count_only], object[:id])

assigned_configuration_profile_objs + unassigned_configuration_profile_objs
end

def fetch_unassigned_configuration_profile_objects(count_only, configuration_manager_id)
unprovisioned_configured_systems = ConfiguredSystem.where(:configuration_profile_id => nil,
:configuration_manager_id => configuration_manager_id)
if unprovisioned_configured_systems.count > 0
unassigned_id = "#{configuration_manager_id}-unassigned"
unassigned_configuration_profile =
[ConfigurationProfile.new(:name => "Unassigned Profiles Group|#{unassigned_id}",
:configuration_manager_id => configuration_manager_id)]
unassigned_configuration_profile_objs = count_only_or_objects(count_only,
unassigned_configuration_profile,
nil)
end

if unassigned_configuration_profile_objs.nil?
count_only ? unassigned_configuration_profile_objs = 0 : unassigned_configuration_profile_objs = []
end
unassigned_configuration_profile_objs
end

def x_get_tree_cpf_kids(object, options)
Expand Down
14 changes: 13 additions & 1 deletion vmdb/app/presenters/tree_node_builder.rb
Expand Up @@ -60,7 +60,7 @@ def build
generic_node(object.name, "vendor-#{object.image_name}.png", "#{ui_lookup(:model => prefix_model)}: #{object.name}")
when ChargebackRate then generic_node(object.description, "chargeback_rates.png")
when Condition then generic_node(object.description, "miq_condition.png")
when ConfigurationProfile then generic_node(object.name, "configuration_profile.png", "Configuration Profile: #{object.name}")
when ConfigurationProfile then configuration_profile_node(object.name, "configuration_profile.png", "Configuration Profile: #{object.name}")
when ConfiguredSystem then generic_node(object.hostname, "configured_system.png", "Configured System: #{object.hostname}")
when Container then generic_node(object.name, "container.png")
when CustomButton then generic_node(object.name, object.options && object.options[:button_image] ? "custom-#{object.options[:button_image]}.png" : "leaf.gif",
Expand Down Expand Up @@ -198,6 +198,18 @@ def miq_ae_node(enabled, text, image, tip)
tooltip(tip)
end

def configuration_profile_node(text, image, tip = nil)
text = ERB::Util.html_escape(text) unless text.html_safe?
title = text.split('|').first
@node = {
:key => build_object_id,
:title => title,
:icon => title == _("Unassigned Profiles Group") ? "folder.png" : image
}
@node[:expand] = true if options[:open_all] # Start with all nodes open
tooltip(tip)
end

def image_for_node(object, image)
case object
when MiqAeNamespace
Expand Down
4 changes: 3 additions & 1 deletion vmdb/app/views/layouts/quadicon/_quadicon_text.html.haml
Expand Up @@ -40,6 +40,8 @@
- name = row['resource_name']
- elsif db == "ConfiguredSystem"
- name = row['hostname']
- elsif db == "ConfigurationProfile"
- name = row['description']
- else
- name = row['name']
- if request.parameters[:controller] == "service" && @view.db == "Vm"
Expand All @@ -55,7 +57,7 @@
= truncate_for_quad(name)
- else
= link_to(truncate_for_quad(name),
{:action => 'x_show', :id => to_cid(row['id'])},
{:action => 'x_show', :id => controller.send(:list_row_id, row)},
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
:title => name,
Expand Down
4 changes: 3 additions & 1 deletion vmdb/app/views/layouts/quadicon/_single_quad.html.haml
Expand Up @@ -6,6 +6,8 @@
- img = item.class.to_s.underscore
- elsif item.kind_of?(ConfigurationManagerForeman)
- img = "vendor-#{item.image_name}"
- elsif item.kind_of?(ConfigurationProfile)
- img = controller.send(:list_row_image, nil, item.class.base_class.to_s.underscore, "configuration_profile", item.name)
- else
- img = item.class.base_class.to_s.underscore
.flobj
Expand All @@ -20,7 +22,7 @@
- if !@embedded || @showlinks
- if @explorer
= link_to(image_tag("/images/icons/#{size}/reflection.png", :width => size, :height => size, :title => h(name)),
{:action => 'x_show', :id => to_cid(item.id)},
{:action => 'x_show', :id => controller.send(:list_row_id, item)},
"data-miq_sparkle_on" => true,
"data-miq_sparkle_off" => true,
:remote => true)
Expand Down

0 comments on commit aa6e82c

Please sign in to comment.