From 2b09d531441d121c72f9408405a7bc729746eb56 Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Tue, 5 Sep 2017 22:27:22 -0400 Subject: [PATCH] Added changes to show playbook data on method summary screen. Moved couple of common methods to application controller. Removed some unrequired/leftover code https://www.pivotaltracker.com/story/show/149747321 --- .../miq_ae_class/ae_method_form_controller.js | 2 +- app/controllers/application_controller.rb | 18 ++++++++++ app/controllers/catalog_controller.rb | 18 ---------- app/controllers/miq_ae_class_controller.rb | 33 +++++++++---------- .../_ansible_form_options_angular.html.haml | 2 +- .../miq_ae_class/_method_inputs.html.haml | 32 ++++++++++++++++++ 6 files changed, 67 insertions(+), 38 deletions(-) diff --git a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js index 82e0d7fb22d0..a8485836588a 100644 --- a/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js +++ b/app/assets/javascripts/controllers/miq_ae_class/ae_method_form_controller.js @@ -106,7 +106,7 @@ ManageIQ.angular.app.controller('aeMethodFormController', ['$http', '$scope', 'a vm.aeMethodModel.provisioning_key = ''; vm.aeMethodModel.provisioning_value = ''; - if (configData['verbosity'] === undefined) { + if (configData['verbosity'] === undefined || configData['verbosity'] == '') { vm.aeMethodModel.provisioning_verbosity = '0'; } else { vm.aeMethodModel.provisioning_verbosity = configData['verbosity']; diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 460cd94c0f84..9f7a4b86d819 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2337,4 +2337,22 @@ def build_accordions_and_trees @accords = allowed_features.map(&:accord_hash) set_active_elements(allowed_features.first) end + + def fetch_name_from_object(klass, id) + klass.find_by(:id => from_cid(id)).try(:name) + end + + def verbosity_display(verbosity) + verbosity ||= "0" + verbosity_hsh = { + "0" => "0 (Normal)", + "1" => "1 (Verbose)", + "2" => "2 (More Verbose)", + "3" => "3 (Debug)", + "4" => "4 (Connection Debug)", + "5" => "5 (WinRM Debug)" + } + verbosity_hsh[verbosity.to_s] + end + helper_method :verbosity_display end diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 248acaab5cf3..0fd33e229bf3 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -832,20 +832,6 @@ def remove_resources_display(remove_resources) end helper_method :remove_resources_display - def verbosity_display(verbosity) - verbosity ||= "0" - verbosity_hsh = { - "0" => "0 (Normal)", - "1" => "1 (Verbose)", - "2" => "2 (More Verbose)", - "3" => "3 (Debug)", - "4" => "4 (Connection Debug)", - "5" => "5 (WinRM Debug)" - } - verbosity_hsh[verbosity.to_s] - end - helper_method :verbosity_display - def features [{:role => "svc_catalog_accord", :role_any => true, @@ -1866,10 +1852,6 @@ def fetch_playbook_details playbook_details end - def fetch_name_from_object(klass, id) - klass.find_by(:id => id).try(:name) - end - def fetch_dialog(playbook_details, dialog_id, key) return nil if dialog_id.nil? dialog = Dialog.find_by(:id => dialog_id) diff --git a/app/controllers/miq_ae_class_controller.rb b/app/controllers/miq_ae_class_controller.rb index 01ddf1af3b76..306e584419d5 100644 --- a/app/controllers/miq_ae_class_controller.rb +++ b/app/controllers/miq_ae_class_controller.rb @@ -991,18 +991,6 @@ def method_form_fields :cloud_credential_id => data['cloud_credential_id'] || '', :hosts => data['hosts'], :verbosity => data['verbosity'], - # :extra_vars => { - # :sleep => '40', - # :pkg => 'httpd', - # :user => 'root', - # :host => 'localhost' - # }, - # :extra_vars => [ - # ['sleep', '40', 'string'], - # ['pkg', 'httpd', 'string'], - # ['user', 'root', 'string'], - # ['host', 'localhost', "string"] - # ] :extra_vars => method.inputs } } @@ -1213,12 +1201,6 @@ def set_playbook_data :credential_id => params['credential_id'], :hosts => params['hosts'], :verbosity => params['verbosity'], - :extra_vars => { - :sleep => '40', - :pkg => 'httpd', - :user => 'root', - :host => 'localhost' - } } data[:network_credential_id] = params['network_credential_id'] if params['network_credential_id'] data[:cloud_credential_id] = params['cloud_credential_id'] if params['cloud_credential_id'] @@ -2678,11 +2660,26 @@ def get_method_node_info(id) if @record.location == 'expression' hash = YAML.load(@record.data) @expression = hash[:expression] ? MiqExpression.new(hash[:expression]).to_human : "" + elsif @record.location == "playbook" + fetch_playbook_details end domain_overrides set_right_cell_text(x_node, @record) end + def fetch_playbook_details + @playbook_details = {} + data = JSON.parse(@record.data) + @playbook_details[:repository] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource, data['repository_id']) + @playbook_details[:playbook] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook, data['playbook_id']) + @playbook_details[:machine_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential, data['credential_id']) + @playbook_details[:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential, data['network_credential_id']) if data['network_credential_id'] + @playbook_details[:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedAnsible::AutomationManager::CloudCredential, data['cloud_credential_id']) if data['cloud_credential_id'] + @playbook_details[:verbosity] = data['verbosity'] + @playbook_details[:hosts] = data['hosts'] + @playbook_details + end + def get_class_node_info(id) @sb[:active_tab] = "instances" if !@in_a_form && !params[:button] && !params[:pressed] begin diff --git a/app/views/layouts/angular/_ansible_form_options_angular.html.haml b/app/views/layouts/angular/_ansible_form_options_angular.html.haml index 429920fd9a31..dfe61a0949e4 100644 --- a/app/views/layouts/angular/_ansible_form_options_angular.html.haml +++ b/app/views/layouts/angular/_ansible_form_options_angular.html.haml @@ -137,7 +137,7 @@ %label.col-md-3.control-label = _('Verbosity') .col-md-9 - %select{"ng-model" => "vm.#{ng_model}.#{prefix}_verbosity", + %select{"ng-model" => "#{ng_model}.#{prefix}_verbosity", "name" => "#{prefix}_verbosity", 'ng-options' => 'v as k for (v, k) in vm.verbosity_types', "checkchange" => "", diff --git a/app/views/miq_ae_class/_method_inputs.html.haml b/app/views/miq_ae_class/_method_inputs.html.haml index d40a4da8c2a8..9b89d277754e 100644 --- a/app/views/miq_ae_class/_method_inputs.html.haml +++ b/app/views/miq_ae_class/_method_inputs.html.haml @@ -50,6 +50,38 @@ :read_only => true} - elsif @ae_method.location == 'expression' = @expression + - elsif @ae_method.location == 'playbook' + .form-horizontal.static + .form-group + %label.col-md-2.control-label + = _('Repository') + .col-md-8 + = h(@playbook_details[:repository]) + .form-group + %label.col-md-2.control-label + = _('Playbook') + .col-md-8 + = h(@playbook_details[:playbook]) + .form-group + %label.col-md-2.control-label + = _('Machine Credential') + .col-md-8 + = h(@playbook_details[:machine_credential]) + .form-group + %label.col-md-2.control-label + = _('Cloud Credential') + .col-md-8 + = h(@playbook_details[:cloud_credential]) + .form-group + %label.col-md-2.control-label + = _('Hosts') + .col-md-8 + = h(@playbook_details[:hosts]) + .form-group + %label.col-md-2.control-label + = _('Verbosity') + .col-md-8 + = h(verbosity_display(@playbook_details[:verbosity])) - else = @ae_method.data -# show inputs parameters grid if there are any inputs