Skip to content

Commit

Permalink
Convert automate simulation form and combine with summary component
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-samuel committed Nov 19, 2024
1 parent 3fada58 commit d560e28
Show file tree
Hide file tree
Showing 24 changed files with 1,367 additions and 291 deletions.
61 changes: 20 additions & 41 deletions app/controllers/application_controller/automate.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ApplicationController::Automate
extend ActiveSupport::Concern
include MiqAeToolsHelper

def resolve_button_throw
if valid_resolve_object?
Expand All @@ -21,48 +22,10 @@ def resolve_button_throw
add_flash(_("Automation Error: %{error_message}") % {:error_message => bang.message}, :error)
end
end
render :update do |page|
page << javascript_prologue
page.replace("left_cell_bottom", :partial => "resolve_form_buttons")
page.replace("flash_msg_div", :partial => "layouts/flash_msg")
page << "miqScrollTop();" if @flash_array.present?
page.replace_html("main_div", :partial => "results_tabs")
page << javascript_reload_toolbars
page << "miqSparkle(false);"
end
automation_simulation_data(@ae_simulation_tree, @results, @resolve)
end
private :resolve_button_throw

# Copy current URI as an automate button
def resolve_button_copy
session[:resolve_object] = copy_hash(@resolve)
head :ok
end
private :resolve_button_copy

# Copy current URI as an automate button
def resolve_button_paste
@resolve = copy_hash(session[:resolve_object])
@edit = session[:edit]
@custom_button = @edit[:custom_button]
@edit[:instance_names] = @resolve[:instance_names]
@edit[:new][:instance_name] = @resolve[:new][:instance_name]
@edit[:new][:object_message] = @resolve[:new][:object_message]
@edit[:new][:object_request] = @resolve[:new][:object_request]
@edit[:new][:attrs] = @resolve[:new][:attrs]
@edit[:new][:target_class] = @resolve[:target_class] = @resolve[:new][:target_class]
@edit[:uri] = @resolve[:uri]
(ApplicationController::AE_MAX_RESOLUTION_FIELDS - @resolve[:new][:attrs].length).times { @edit[:new][:attrs].push([]) }
@changed = (@edit[:new] != @edit[:current])
render :update do |page|
page << javascript_prologue
page.replace_html("main_div", :partial => "shared/buttons/ab_list")
page << javascript_for_miq_button_visibility_changed(@changed)
page << "miqSparkle(false);"
end
end
private :resolve_button_paste

# Copy current URI as an automate button
def resolve_button_simulate
@edit = copy_hash(session[:resolve])
Expand Down Expand Up @@ -115,15 +78,15 @@ def resolve_button_reset_or_none
end
private :resolve_button_reset_or_none

def resolve
def resolve_automate_simulation
custom_button_redirect = params[:button] == 'simulate' || params[:simulate] == 'simulate'
assert_privileges(custom_button_redirect ? 'ab_button_simulate' : 'miq_ae_class_simulation')
@explorer = true
@breadcrumbs = []
drop_breadcrumb(:name => _("Resolve"), :url => "/miq_ae_tools/resolve")
@lastaction = "resolve"
@right_cell_text = _("Simulation")

get_simulation_form_vars
case params[:button]
when "throw", "retry" then resolve_button_throw
when "copy" then resolve_button_copy
Expand All @@ -133,6 +96,22 @@ def resolve
end
end

def resolve
custom_button_redirect = params[:button] == 'simulate' || params[:simulate] == 'simulate'
assert_privileges(custom_button_redirect ? 'ab_button_simulate' : 'miq_ae_class_simulation')
@explorer = true
@breadcrumbs = []
drop_breadcrumb(:name => _("Resolve"), :url => "/miq_ae_tools/resolve")
@lastaction = "resolve"
@right_cell_text = _("Simulation")

case params[:button]
when "throw", "retry" then resolve_button_throw
when "simulate" then resolve_button_simulate
else resolve_button_reset_or_none
end
end

def build_results
options = {
:vmdb_object => @sb[:obj],
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/miq_ae_tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,51 @@ def reset_datastore
javascript_flash(:spinner_off => true)
end

def get_simulation_form_vars
assert_privileges('miq_ae_class_simulation')
if params[:object_request]
@resolve[:new][:object_request] = params[:object_request]
end
if params.key?(:starting_object)
@resolve[:new][:starting_object] = params[:starting_object]
@resolve[:new][:instance_name] = nil
end
if params[:readonly]
@resolve[:new][:readonly] = (params[:readonly] != "1")
end

copy_params_if_present(@resolve[:new], params, %i[instance_name other_name object_message object_request target_class target_id])

ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
f = ("attribute_" + (i + 1).to_s)
v = ("value_" + (i + 1).to_s)
@resolve[:new][:attrs][i][0] = params[f.to_sym] || nil
@resolve[:new][:attrs][i][1] = params[v.to_sym] || nil
end
end
@resolve[:new][:target_id] = nil if params[:target_class] == ""
copy_params_if_present(@resolve, params, %i[button_text button_number])
@resolve[:throw_ready] = ready_to_throw
end

def get_form_targets
assert_privileges('miq_ae_class_simulation')
if params.key?(:target_class) && params[:target_class] != '-1'
targets = Rbac.filtered(params[:target_class]).select(:id, *columns_for_klass(params[:target_class])) if params[:target_class].present?
unless targets.nil?
@resolve[:targets] = targets.sort_by { |t| t.name.downcase }.collect { |t| [t.name, t.id.to_s] }
if !@resolve[:target_id]
@resolve[:target_id] = nil
end
end
end

render_json = {}
render_json[:targets] = @resolve[:targets] if @resolve[:targets].present?
render :json => render_json
end

private ###########################

def automate_import_json_serializer
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/application_helper/button/ae_copy_simulate.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
class ApplicationHelper::Toolbar::MiqAeToolsSimulateCenter < ApplicationHelper::Toolbar::Basic
button_group('miq_ae_tools_vmdb', [
button(
:ae_copy_simulate,
'fa fa-files-o fa-lg',
N_('Copy object details for use in a Button'),
N_('Copy'),
:url => "resolve",
:url_parms => "?button=copy",
:klass => ApplicationHelper::Button::AeCopySimulate),
])
end
2 changes: 1 addition & 1 deletion app/helpers/miq_ae_tools_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def git_import_submit_help

def automation_simulation_data(tree, results, resolve)
if results
{
render :json => {
:tree => {:text => _('Tree View'), :rows => ae_result_tree(tree)},
:xml => {:text => _('Xml View'), :rows => ae_result_xml(results)},
:object => {:text => _('Object info'), :rows => ae_result_uri(resolve)}
Expand Down
11 changes: 6 additions & 5 deletions app/javascript/components/AutomationSimulation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import MiqStructuredList from '../miq-structured-list';
/** Component to render the summary contents displayed in the Automation / Embedded Automate / Simulation */
const AutomationSimulation = ({ data }) => {
const [tabConfig, setTabConfig] = useState([]);

useEffect(() => {
const config = Object.keys(data).map((name) => ({ name, text: data[name].text }));
setTabConfig(config);
}, []);
if (Object.keys(data).length > 1) {
const config = Object.keys(data).map((name) => ({ name, text: data[name].text }));
setTabConfig(config);
}
}, [data]);

/** Function to render the tabs contents. */
const renderTabContent = (name) => {
Expand All @@ -37,7 +38,7 @@ const AutomationSimulation = ({ data }) => {
</Tabs>
);

return data.notice
return Object.keys(data).length <= 1
? <NotificationMessage type="info" message={data.notice} />
: renderTabs();
};
Expand Down
Loading

0 comments on commit d560e28

Please sign in to comment.