Skip to content

Commit

Permalink
Added Configured System tree builder file back
Browse files Browse the repository at this point in the history
- Added Configured System tree builder file back this is needed for Configured Systems accordion in Automation Manager Explorer
- While testing found that toolbar buttons in Automation Manager explorer were not working due to changes made in Configuration Manager controller changes. Moved around some of the methods, deleted duplicated methods and fixed code to get Add/Edit/Refresh/Delete buttons working in both Automation Manager explorer and Configuration Manager screens.
- deleted unused method
  • Loading branch information
h-kataria committed Mar 25, 2020
1 parent 5ce1063 commit 3c482ce
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 163 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def process_elements(elements, klass, task, display_name = nil, order_field = ni
end

def explorer_controller?
%w[vm_cloud vm_infra vm_or_template infra_networking].include?(controller_name)
%w[vm_cloud vm_infra vm_or_template infra_networking automation_manager].include?(controller_name)
end

def process_element_destroy(element, klass, name)
Expand Down
77 changes: 5 additions & 72 deletions app/controllers/configuration_manager_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,58 +67,16 @@ def button
end
end

def edit
@server_zones = Zone.visible.in_my_region.order('lower(description)').pluck(:description, :name)
case params[:button]
when "cancel"
cancel_provider
when "save"
add_provider
save_provider
else
assert_privileges("configuration_manager_edit_provider")
manager_id = params[:miq_grid_checks] || params[:id] || find_checked_items[0]
@provider_manager = find_record(concrete_model, manager_id)
@providerdisplay_type = _("Configuration Manager")
@sb[:action] = params[:action]
@in_a_form = true
@redirect_controller = "configuration_manager"
@redirect_id = @provider_manager.id
@refresh_partial = "edit"
end
end

def form_fields
assert_privileges("configuration_manager_edit_provider")
# set value of read only zone text box, when there is only single zone
if params[:id] == "new"
return render(:json => {:zone => Zone.visible.in_my_region.size >= 1 ? Zone.visible.in_my_region.first.name : nil})
end

manager = find_record(concrete_model, params[:id])
provider = manager.provider
private

render :json => {:name => provider.name,
:zone => provider.zone.name,
:zone_hidden => !manager.enabled?,
:url => provider.url,
:verify_ssl => provider.verify_ssl,
:default_userid => provider.authentications.first.userid,
:default_auth_status => provider.authentication_status_ok?}
def self.model_to_name(provmodel)
Dictionary.gettext('configuration_manager', :type => :ui_title, :translate => false)
end

def new
assert_privileges("configuration_manager_add_provider")
@provider_manager = concrete_model.new
@server_zones = Zone.visible.in_my_region.order('lower(description)').pluck(:description, :name)
@sb[:action] = params[:action]
@in_a_form = true
@redirect_controller = "configuration_manager"
@refresh_partial = "new"
def privilege_prefix
"configuration_manager"
end

private

def refresh
assert_privileges("configuration_manager_refresh_provider")
manager_button_operation('refresh_ems', _('Refresh'))
Expand All @@ -132,31 +90,6 @@ def provider_class
ManageIQ::Providers::Foreman::Provider
end

def delete
assert_privileges("configuration_manager_delete_provider")
checked_items = find_checked_items
checked_items.push(params[:id]) if checked_items.empty? && params[:id]
providers = Rbac.filtered(concrete_model.where(:id => checked_items).includes(:provider).collect(&:provider))
if providers.empty?
add_flash(_("No Providers were selected for deletion"), :error)
else
providers.each do |provider|
AuditEvent.success(
:event => "provider_record_delete_initiated",
:message => "[#{provider.name}] Record delete initiated",
:target_id => provider.id,
:target_class => provider.type,
:userid => session[:userid]
)
provider.destroy_queue
end

add_flash(n_("Delete initiated for %{count} Provider",
"Delete initiated for %{count} Providers",
providers.length) % {:count => providers.length})
end
end

def breadcrumbs_options
{
:breadcrumbs => [
Expand Down
59 changes: 0 additions & 59 deletions app/controllers/mixins/automation_manager_controller_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,65 +130,6 @@ def accordion_select
replace_right_cell(:replace_trees => [x_active_accord])
end

def new
assert_privileges("#{privilege_prefix}_add_provider")
@provider_manager = concrete_model.new
@server_zones = Zone.visible.in_my_region.order('lower(description)').pluck(:description, :name)
@sb[:action] = params[:action]
render_form
end

def edit
@server_zones = Zone.visible.in_my_region.order('lower(description)').pluck(:description, :name)
case params[:button]
when "cancel"
cancel_provider
when "save"
add_provider
save_provider
else
assert_privileges("#{privilege_prefix}_edit_provider")
manager_id = params[:miq_grid_checks] || params[:id] || find_checked_items[0]
@provider_manager = find_record(concrete_model, manager_id)
@providerdisplay_type = self.class.model_to_name(@provider_manager.type)
@sb[:action] = params[:action]
render_form
end
end

def delete
assert_privileges("#{privilege_prefix}_delete_provider")
checked_items = find_checked_items
checked_items.push(params[:id]) if checked_items.empty? && params[:id]
providers = Rbac.filtered(concrete_model.where(:id => checked_items).includes(:provider).collect(&:provider))
if providers.empty?
add_flash(_("No Providers were selected for deletion"), :error)
else
providers.each do |provider|
AuditEvent.success(
:event => "provider_record_delete_initiated",
:message => "[#{provider.name}] Record delete initiated",
:target_id => provider.id,
:target_class => provider.type,
:userid => session[:userid]
)
provider.destroy_queue
end

add_flash(n_("Delete initiated for %{count} Provider",
"Delete initiated for %{count} Providers",
providers.length) % {:count => providers.length})
end
replace_right_cell
end

def refresh
assert_privileges("#{privilege_prefix}_refresh_provider")
@explorer = true
manager_button_operation('refresh_ems', _('Refresh'))
replace_right_cell
end

private

def tag_action
Expand Down
24 changes: 20 additions & 4 deletions app/controllers/mixins/manager_controller_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,22 @@ def authentication_validate

def new
assert_privileges("#{privilege_prefix}_add_provider")
@explorer = true if explorer_controller?
@provider_manager = concrete_model.new
@server_zones = Zone.visible.in_my_region.order('lower(description)').pluck(:description, :name)
@sb[:action] = params[:action]
render_form if @explorer
if @explorer
render_form
else
@in_a_form = true
@redirect_controller = "configuration_manager"
@refresh_partial = "new"
end
end

def edit
assert_privileges("#{privilege_prefix}_edit_provider")
@explorer = true if explorer_controller?
@server_zones = Zone.visible.in_my_region.order('lower(description)').pluck(:description, :name)
case params[:button]
when "cancel"
Expand All @@ -101,17 +110,24 @@ def edit
add_provider
save_provider
else
assert_privileges("#{privilege_prefix}_edit_provider")
manager_id = params[:miq_grid_checks] || params[:id] || find_checked_items[0]
@provider_manager = find_record(concrete_model, manager_id)
@providerdisplay_type = self.class.model_to_name(@provider_manager.type)
@sb[:action] = params[:action]
render_form if @explorer
if @explorer
render_form
else
@in_a_form = true
@redirect_controller = "configuration_manager"
@redirect_id = @provider_manager.id
@refresh_partial = "edit"
end
end
end

def delete
assert_privileges("#{privilege_prefix}_delete_provider")
@explorer = true if explorer_controller?
checked_items = find_checked_items
checked_items.push(params[:id]) if checked_items.empty? && params[:id]
providers = Rbac.filtered(concrete_model.where(:id => checked_items).includes(:provider).collect(&:provider))
Expand All @@ -137,8 +153,8 @@ def delete
end

def refresh
@explorer = true if explorer_controller?
assert_privileges("#{privilege_prefix}_refresh_provider")
@explorer = true
manager_button_operation('refresh_ems', _('Refresh'))
replace_right_cell if @explorer
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/mixins/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def x_active_tree
protect_tree
pxe_image_types_tree
pxe_servers_tree
configuration_manager_providers_tree
rbac_tree
reports_tree
roles_by_server_tree
Expand Down
15 changes: 0 additions & 15 deletions app/helpers/application_helper/toolbar_chooser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,21 +537,6 @@ def center_toolbar_filename_automation_manager
end
end

def configuration_manager_providers_tree_center_tb(nodes)
case nodes.first
when "root" then "configuration_manager_providers_center_tb"
when "fr", "at" then "configuration_manager_provider_center_tb"
when "cp" then configuration_profile_center_tb
when "f" then inventory_group_center_tb
when "xx" then
case nodes.last
when "f" then "configured_systems_center_tb"
when "cp" then "unassigned_profiles_group_center_tb"
else "configuration_manager_providers_center_tb"
end
end
end

def cs_filter_tree_center_tb(nodes)
case nodes.first
when "root", "ms", "xx", "csa", "csf" then "configured_systems_center_tb"
Expand Down
20 changes: 20 additions & 0 deletions app/presenters/tree_builder_configured_systems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class TreeBuilderConfiguredSystems < TreeBuilder
include TreeBuilderFiltersMixin

private

def tree_init_options
{:allow_reselect => true}
end

def x_get_tree_custom_kids(object, count_only)
count_only_or_filter_kids(@root_class, object, count_only)
end

# Get root nodes count/array for explorer tree
def x_get_tree_roots
objects = []
objects.push(configured_systems)
count_only_or_objects(false, objects + FILTERS.values)
end
end
8 changes: 1 addition & 7 deletions app/views/automation_manager/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
= render :partial => 'configuration_manager/shared_form'

:javascript
ManageIQ.angular.app.value('configurationManagerFormId', '#{@provider_manager.id || "new"}');
ManageIQ.angular.app.value('url', '/automation_manager');
ManageIQ.angular.app.value('modelName', 'automationManagerModel');
miq_bootstrap('#form_div');
= render :partial => 'configuration_manager/shared_form', :locals => {:url => "/automation_manager", :model => "automationManagerModel"}
4 changes: 2 additions & 2 deletions app/views/configuration_manager/_shared_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@
:javascript
ManageIQ.angular.app.value('configurationManagerFormId', '#{@provider_manager.id || "new"}');
ManageIQ.angular.app.value('url', '/configuration_manager');
ManageIQ.angular.app.value('modelName', 'configurationManagerModel');
ManageIQ.angular.app.value('url', '#{url}');
ManageIQ.angular.app.value('modelName', '#{model}');
miq_bootstrap('#form_div');
2 changes: 1 addition & 1 deletion app/views/configuration_manager/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= render :partial => 'configuration_manager/shared_form'
= render :partial => 'configuration_manager/shared_form', :locals => {:url => "/configuration_manager", :model => "configurationManagerModel"}
2 changes: 1 addition & 1 deletion app/views/configuration_manager/new.html.haml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= render :partial => 'configuration_manager/shared_form'
= render :partial => 'configuration_manager/shared_form', :locals => {:url => "/configuration_manager", :model => "configurationManagerModel"}

0 comments on commit 3c482ce

Please sign in to comment.