Skip to content

Commit

Permalink
Getting toolbar buttons working.
Browse files Browse the repository at this point in the history
  • Loading branch information
h-kataria committed Mar 23, 2020
1 parent 28e02c4 commit 9501afc
Show file tree
Hide file tree
Showing 14 changed files with 640 additions and 375 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 @@ -306,7 +306,7 @@ def manager_button_operation(method, display_name)
def process_managers(managers, task)
controller_class = request.parameters[:controller]
provider_class = case controller_class
when 'provider_foreman' then ManageIQ::Providers::ConfigurationManager
when 'configuration_manager', 'provider_foreman' then ManageIQ::Providers::ConfigurationManager
when 'automation_manager' then ManageIQ::Providers::AutomationManager
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def tagging_edit_tags_cancel
replace_right_cell
else
session[:flash_msgs] = @flash_array.dup # Put msg in session for next transaction to display
p "XCCCCCCCCCCCCCCCCCCCCCC #{previous_breadcrumb_url.inspect}"
javascript_redirect(previous_breadcrumb_url)
end
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/automation_manager_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AutomationManagerController < ApplicationController

include Mixins::GenericSessionMixin
include Mixins::ManagerControllerMixin
include Mixins::AutomationManagerControllerMixin
include Mixins::ExplorerPresenterMixin
include Mixins::EmsCommon::Core
include Mixins::EmsCommon::PauseResume
Expand Down
134 changes: 134 additions & 0 deletions app/controllers/configuration_manager_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class ConfigurationManagerController < ApplicationController
include Mixins::GenericShowMixin
include Mixins::GenericSessionMixin
include Mixins::BreadcrumbsMixin
include Mixins::GenericFormMixin
include Mixins::ManagerControllerMixin
include Mixins::FindRecord

before_action :check_privileges
before_action :get_session_data
Expand All @@ -21,8 +24,139 @@ def self.display_methods
%w[configuration_profiles configured_systems]
end

def button
@edit = session[:edit] # Restore @edit for adv search box
params[:display] = @display if %w[configuration_profiles configured_systems].include?(@display) # Were we displaying nested list

# Handle Toolbar Policy Tag Button
@refresh_div = "main_div" # Default div for button.rjs to refresh
model = self.class.model
tag(model) if params[:pressed] == "#{params[:controller]}_tag"

if [ConfiguredSystem].include?(model)
assign_policies(model) if params[:pressed] == "#{model.name.underscore}_protect"
check_compliance(model) if params[:pressed] == "#{model.name.underscore}_check_compliance"
end

case params[:pressed]
when 'configuration_manager_edit_provider'
edit
when 'configuration_manager_add_provider'
new
when "configuration_manager_refresh_provider"
refresh
when "configuration_manager_delete_provider"
delete
end

return if ["#{params[:controller]}_tag"].include?(params[:pressed]) && @flash_array.nil? # Tag screen showing

if single_delete_test
single_delete_redirect
elsif (params[:pressed].ends_with?("_edit_provider") || params[:pressed] == "configuration_manager_add_provider") && @flash_array.nil?
if @flash_array
show_list
replace_gtl_main_div
else
javascript_redirect(:action => @refresh_partial, :id => @redirect_id)
end
elsif @refresh_div == "main_div" && @lastaction == "show_list"
replace_gtl_main_div
else
render_flash unless performed?
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

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?}
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"
end

private

def refresh
assert_privileges("configuration_manager_refresh_provider")
manager_button_operation('refresh_ems', _('Refresh'))
end

def concrete_model
ManageIQ::Providers::ConfigurationManager
end

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
31 changes: 31 additions & 0 deletions app/controllers/configured_system_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,37 @@ def self.table_name
@table_name ||= "configured_system"
end

def button
@edit = session[:edit] # Restore @edit for adv search box
params[:display] = @display if %w[configuration_profiles configured_systems].include?(@display) # Were we displaying nested list

# Handle Toolbar Policy Tag Button
@refresh_div = "main_div" # Default div for button.rjs to refresh
model = self.class.model
tag(model) if params[:pressed] == "#{params[:controller]}_tag"
if [ConfiguredSystem].include?(model)
assign_policies(model) if params[:pressed] == "#{model.name.underscore}_protect"
check_compliance(model) if params[:pressed] == "#{model.name.underscore}_check_compliance"
end
if params[:pressed] == 'service_dialog_from_ct'
create_service_dialog
return
end

return if ["#{params[:controller]}_tag"].include?(params[:pressed]) && @flash_array.nil? # Tag screen showing

# Handle scan
if params[:pressed] == "container_image_scan"
scan_images

if @lastaction == "show"
javascript_flash
else
replace_main_div(:partial => "layouts/gtl")
end
end
end

private

def textual_group_list
Expand Down
Loading

0 comments on commit 9501afc

Please sign in to comment.