Skip to content

Commit d560e28

Browse files
committed
Convert automate simulation form and combine with summary component
1 parent 3fada58 commit d560e28

File tree

24 files changed

+1367
-291
lines changed

24 files changed

+1367
-291
lines changed

app/controllers/application_controller/automate.rb

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module ApplicationController::Automate
22
extend ActiveSupport::Concern
3+
include MiqAeToolsHelper
34

45
def resolve_button_throw
56
if valid_resolve_object?
@@ -21,48 +22,10 @@ def resolve_button_throw
2122
add_flash(_("Automation Error: %{error_message}") % {:error_message => bang.message}, :error)
2223
end
2324
end
24-
render :update do |page|
25-
page << javascript_prologue
26-
page.replace("left_cell_bottom", :partial => "resolve_form_buttons")
27-
page.replace("flash_msg_div", :partial => "layouts/flash_msg")
28-
page << "miqScrollTop();" if @flash_array.present?
29-
page.replace_html("main_div", :partial => "results_tabs")
30-
page << javascript_reload_toolbars
31-
page << "miqSparkle(false);"
32-
end
25+
automation_simulation_data(@ae_simulation_tree, @results, @resolve)
3326
end
3427
private :resolve_button_throw
3528

36-
# Copy current URI as an automate button
37-
def resolve_button_copy
38-
session[:resolve_object] = copy_hash(@resolve)
39-
head :ok
40-
end
41-
private :resolve_button_copy
42-
43-
# Copy current URI as an automate button
44-
def resolve_button_paste
45-
@resolve = copy_hash(session[:resolve_object])
46-
@edit = session[:edit]
47-
@custom_button = @edit[:custom_button]
48-
@edit[:instance_names] = @resolve[:instance_names]
49-
@edit[:new][:instance_name] = @resolve[:new][:instance_name]
50-
@edit[:new][:object_message] = @resolve[:new][:object_message]
51-
@edit[:new][:object_request] = @resolve[:new][:object_request]
52-
@edit[:new][:attrs] = @resolve[:new][:attrs]
53-
@edit[:new][:target_class] = @resolve[:target_class] = @resolve[:new][:target_class]
54-
@edit[:uri] = @resolve[:uri]
55-
(ApplicationController::AE_MAX_RESOLUTION_FIELDS - @resolve[:new][:attrs].length).times { @edit[:new][:attrs].push([]) }
56-
@changed = (@edit[:new] != @edit[:current])
57-
render :update do |page|
58-
page << javascript_prologue
59-
page.replace_html("main_div", :partial => "shared/buttons/ab_list")
60-
page << javascript_for_miq_button_visibility_changed(@changed)
61-
page << "miqSparkle(false);"
62-
end
63-
end
64-
private :resolve_button_paste
65-
6629
# Copy current URI as an automate button
6730
def resolve_button_simulate
6831
@edit = copy_hash(session[:resolve])
@@ -115,15 +78,15 @@ def resolve_button_reset_or_none
11578
end
11679
private :resolve_button_reset_or_none
11780

118-
def resolve
81+
def resolve_automate_simulation
11982
custom_button_redirect = params[:button] == 'simulate' || params[:simulate] == 'simulate'
12083
assert_privileges(custom_button_redirect ? 'ab_button_simulate' : 'miq_ae_class_simulation')
12184
@explorer = true
12285
@breadcrumbs = []
12386
drop_breadcrumb(:name => _("Resolve"), :url => "/miq_ae_tools/resolve")
12487
@lastaction = "resolve"
12588
@right_cell_text = _("Simulation")
126-
89+
get_simulation_form_vars
12790
case params[:button]
12891
when "throw", "retry" then resolve_button_throw
12992
when "copy" then resolve_button_copy
@@ -133,6 +96,22 @@ def resolve
13396
end
13497
end
13598

99+
def resolve
100+
custom_button_redirect = params[:button] == 'simulate' || params[:simulate] == 'simulate'
101+
assert_privileges(custom_button_redirect ? 'ab_button_simulate' : 'miq_ae_class_simulation')
102+
@explorer = true
103+
@breadcrumbs = []
104+
drop_breadcrumb(:name => _("Resolve"), :url => "/miq_ae_tools/resolve")
105+
@lastaction = "resolve"
106+
@right_cell_text = _("Simulation")
107+
108+
case params[:button]
109+
when "throw", "retry" then resolve_button_throw
110+
when "simulate" then resolve_button_simulate
111+
else resolve_button_reset_or_none
112+
end
113+
end
114+
136115
def build_results
137116
options = {
138117
:vmdb_object => @sb[:obj],

app/controllers/miq_ae_tools_controller.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,51 @@ def reset_datastore
329329
javascript_flash(:spinner_off => true)
330330
end
331331

332+
def get_simulation_form_vars
333+
assert_privileges('miq_ae_class_simulation')
334+
if params[:object_request]
335+
@resolve[:new][:object_request] = params[:object_request]
336+
end
337+
if params.key?(:starting_object)
338+
@resolve[:new][:starting_object] = params[:starting_object]
339+
@resolve[:new][:instance_name] = nil
340+
end
341+
if params[:readonly]
342+
@resolve[:new][:readonly] = (params[:readonly] != "1")
343+
end
344+
345+
copy_params_if_present(@resolve[:new], params, %i[instance_name other_name object_message object_request target_class target_id])
346+
347+
ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
348+
ApplicationController::AE_MAX_RESOLUTION_FIELDS.times do |i|
349+
f = ("attribute_" + (i + 1).to_s)
350+
v = ("value_" + (i + 1).to_s)
351+
@resolve[:new][:attrs][i][0] = params[f.to_sym] || nil
352+
@resolve[:new][:attrs][i][1] = params[v.to_sym] || nil
353+
end
354+
end
355+
@resolve[:new][:target_id] = nil if params[:target_class] == ""
356+
copy_params_if_present(@resolve, params, %i[button_text button_number])
357+
@resolve[:throw_ready] = ready_to_throw
358+
end
359+
360+
def get_form_targets
361+
assert_privileges('miq_ae_class_simulation')
362+
if params.key?(:target_class) && params[:target_class] != '-1'
363+
targets = Rbac.filtered(params[:target_class]).select(:id, *columns_for_klass(params[:target_class])) if params[:target_class].present?
364+
unless targets.nil?
365+
@resolve[:targets] = targets.sort_by { |t| t.name.downcase }.collect { |t| [t.name, t.id.to_s] }
366+
if !@resolve[:target_id]
367+
@resolve[:target_id] = nil
368+
end
369+
end
370+
end
371+
372+
render_json = {}
373+
render_json[:targets] = @resolve[:targets] if @resolve[:targets].present?
374+
render :json => render_json
375+
end
376+
332377
private ###########################
333378

334379
def automate_import_json_serializer

app/helpers/application_helper/button/ae_copy_simulate.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
11
class ApplicationHelper::Toolbar::MiqAeToolsSimulateCenter < ApplicationHelper::Toolbar::Basic
2-
button_group('miq_ae_tools_vmdb', [
3-
button(
4-
:ae_copy_simulate,
5-
'fa fa-files-o fa-lg',
6-
N_('Copy object details for use in a Button'),
7-
N_('Copy'),
8-
:url => "resolve",
9-
:url_parms => "?button=copy",
10-
:klass => ApplicationHelper::Button::AeCopySimulate),
11-
])
122
end

app/helpers/miq_ae_tools_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def git_import_submit_help
1818

1919
def automation_simulation_data(tree, results, resolve)
2020
if results
21-
{
21+
render :json => {
2222
:tree => {:text => _('Tree View'), :rows => ae_result_tree(tree)},
2323
:xml => {:text => _('Xml View'), :rows => ae_result_xml(results)},
2424
:object => {:text => _('Object info'), :rows => ae_result_uri(resolve)}

app/javascript/components/AutomationSimulation/index.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import MiqStructuredList from '../miq-structured-list';
77
/** Component to render the summary contents displayed in the Automation / Embedded Automate / Simulation */
88
const AutomationSimulation = ({ data }) => {
99
const [tabConfig, setTabConfig] = useState([]);
10-
1110
useEffect(() => {
12-
const config = Object.keys(data).map((name) => ({ name, text: data[name].text }));
13-
setTabConfig(config);
14-
}, []);
11+
if (Object.keys(data).length > 1) {
12+
const config = Object.keys(data).map((name) => ({ name, text: data[name].text }));
13+
setTabConfig(config);
14+
}
15+
}, [data]);
1516

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

40-
return data.notice
41+
return Object.keys(data).length <= 1
4142
? <NotificationMessage type="info" message={data.notice} />
4243
: renderTabs();
4344
};

0 commit comments

Comments
 (0)