Skip to content

Commit eb0a8ad

Browse files
committed
Convert clusters and datastores collection from ruby to react
1 parent f2c46c5 commit eb0a8ad

File tree

50 files changed

+1254
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1254
-147
lines changed

app/controllers/ops_controller.rb

+7
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ def replace_right_cell(options = {})
596596

597597
presenter = ExplorerPresenter.new(:active_tree => x_active_tree)
598598

599+
if params["tab_id"] == "settings_cu_collection"
600+
@hide_bottom_bar = true
601+
end
602+
599603
replace_explorer_trees(replace_trees, presenter)
600604
rebuild_toolbars(presenter)
601605
handle_bottom_cell(nodetype, presenter, locals)
@@ -806,6 +810,9 @@ def handle_bottom_cell(nodetype, presenter, locals)
806810
if ["settings_workers", "diagnostics_cu_repair"].include?(@sb[:active_tab])
807811
presenter.hide(:form_buttons_div)
808812
end
813+
if @hide_bottom_bar
814+
presenter.hide(:form_buttons_div)
815+
end
809816
end
810817

811818
def replace_explorer_trees(replace_trees, presenter)

app/controllers/ops_controller/settings/cap_and_u.rb

+94-35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ def cu_collection_update
66

77
return unless load_edit("cu_edit__collection", "replace_cell__explorer")
88

9+
cu_collection_get_form_vars
10+
911
if params[:button] == "save"
1012
# C & U collection settings
1113
if @edit[:new][:all_clusters] != @edit[:current][:all_clusters]
@@ -39,11 +41,6 @@ def cu_collection_update
3941
add_flash(_("Capacity and Utilization Collection settings saved"))
4042
get_node_info(x_node)
4143
replace_right_cell(:nodetype => @nodetype)
42-
elsif params[:button] == "reset"
43-
@changed = false
44-
add_flash(_("All changes have been reset"), :warning)
45-
get_node_info(x_node)
46-
replace_right_cell(:nodetype => @nodetype)
4744
end
4845
end
4946

@@ -58,22 +55,82 @@ def set_perf_collection_for_clusters
5855
end
5956
end
6057

61-
def cu_collection_field_changed
62-
assert_privileges("region_edit")
58+
def cu_collection_fetch
59+
@edit = {}
60+
@edit[:new] = {}
61+
@edit[:current] = {}
62+
@edit[:key] = "cu_edit__collection"
63+
@edit[:current][:all_clusters] = Metric::Targets.perf_capture_always[:host_and_cluster]
64+
@edit[:current][:all_storages] = Metric::Targets.perf_capture_always[:storage]
65+
@edit[:current][:clusters] = []
66+
@cl_hash = EmsCluster.get_perf_collection_object_list
67+
@cl_hash.each_with_index do |h, j|
68+
_cid, cl_hash = h
69+
c = cl_hash[:cl_rec]
70+
enabled = cl_hash[:ho_enabled]
71+
enabled_host_ids = enabled.collect(&:id)
72+
hosts = (cl_hash[:ho_enabled] + cl_hash[:ho_disabled]).sort_by { |ho| ho.name.downcase }
73+
cl_enabled = enabled_host_ids.length == hosts.length
74+
en_flg = cl_enabled && !enabled.empty?
75+
@edit[:current][:clusters].push(:id => c.id, :capture => en_flg)
76+
@edit[:current][c.id] = []
77+
hosts.each do |host|
78+
host_capture = enabled_host_ids.include?(host.id.to_i)
79+
@edit[:current][c.id].push(:id => host.id, :capture => host_capture)
80+
end
81+
flg = true
82+
count = 0
83+
@edit[:current][c.id].each do |host|
84+
unless host[:capture]
85+
count += 1 # checking if all hosts are unchecked then cluster capture will be false else undefined
86+
flg = count == @edit[:current][c.id].length ? false : "undefined"
87+
end
88+
@edit[:current][:clusters][j][:capture] = flg
89+
end
90+
end
91+
@edit[:current][:clusters].sort_by! { |c| c[:name] }
6392

64-
return unless load_edit("cu_edit__collection", "replace_cell__explorer")
93+
# ##################### Adding Non-Clustered hosts node
94+
@edit[:current][:non_cl_hosts] ||= []
95+
ExtManagementSystem.in_my_region.each do |e|
96+
all = e.non_clustered_hosts
97+
all.each do |h|
98+
@edit[:current][:non_cl_hosts] << {:id => h.id, :capture => h.perf_capture_enabled?}
99+
end
100+
end
101+
if @edit[:current][:clusters].present?
102+
@cluster_tree = TreeBuilderClusters.new(:cluster_tree, @sb, true, :root => @cl_hash)
103+
end
104+
@edit[:current][:storages] = {}
105+
Storage.in_my_region.includes(:taggings, :tags, :hosts).select(:id, :name, :location).sort_by { |s| s.name.downcase }.each do |s|
106+
@edit[:current][:storages][s.id] = {:id => s.id, :capture => s.perf_capture_enabled?}
107+
end
108+
if @edit[:current][:storages].present?
109+
@datastore_tree = TreeBuilderDatastores.new(:datastore_tree, @sb, true, :root => @edit[:current][:storages])
110+
end
111+
@edit[:new] = copy_hash(@edit[:current])
65112

66-
cu_collection_get_form_vars
67-
@changed = (@edit[:new] != @edit[:current]) # UI edit form, C&U collection form
68-
# C&U tab
69-
# need to create an array of items, if their or their children's capture has been changed then make the changed one blue.
70-
render :update do |page|
71-
page << javascript_prologue
72-
page.replace_html(@refresh_div, :partial => @refresh_partial) if @refresh_div
73-
page << "$('#clusters_div').#{params[:all_clusters] == 'true' ? "hide" : "show"}()" if params[:all_clusters]
74-
page << "$('#storages_div').#{params[:all_storages] == 'true' ? "hide" : "show"}()" if params[:all_storages]
75-
page << javascript_for_miq_button_visibility(@changed)
113+
clusters = []
114+
@edit[:current].each do |key, value|
115+
if key.is_a?(Numeric)
116+
clusters << value
117+
end
76118
end
119+
hosts = []
120+
clusters.each do |cluster|
121+
if !cluster.empty?
122+
cluster.each do |host|
123+
hosts << host
124+
end
125+
else
126+
hosts << cluster
127+
end
128+
end
129+
130+
render :json => {
131+
:hosts => hosts,
132+
:datastores => @edit[:current][:storages].values
133+
}
77134
end
78135

79136
private
@@ -136,38 +193,40 @@ def cu_build_edit_screen
136193
end
137194

138195
def cu_collection_get_form_vars
139-
@edit[:new][:all_clusters] = params[:all_clusters] == 'true' if params[:all_clusters]
140-
@edit[:new][:all_storages] = params[:all_storages] == 'true' if params[:all_storages]
196+
@edit[:new][:all_clusters] = params[:all_clusters]
197+
@edit[:new][:all_storages] = params[:all_datastores]
141198

142-
if params[:id]
143-
model, id, _ = TreeBuilder.extract_node_model_and_id(params[:id])
144-
145-
if model == 'Storage'
146-
@edit[:new][:storages][id.to_i][:capture] = params[:check] == "1"
147-
else
148-
cluster_tree_settings(model, id)
149-
end
199+
params[:clusters_checked].each do |cluster|
200+
model, id, _ = TreeBuilder.extract_node_model_and_id(cluster[:id])
201+
cluster_tree_settings(model, id, cluster)
202+
end
203+
params[:datastores_checked].each do |storage|
204+
model, id, _ = TreeBuilder.extract_node_model_and_id(storage[:id])
205+
@edit[:new][:storages][id.to_i][:capture] = storage[:capture]
206+
end
207+
params[:hosts_checked].each do |host|
208+
model, id, _ = TreeBuilder.extract_node_model_and_id(host[:id])
209+
cluster_tree_settings(model, id, host)
150210
end
151211
end
152212

153-
def cluster_tree_settings(model, id)
213+
def cluster_tree_settings(model, id, cluster_or_host)
154214
if id == "NonCluster" # Clicked on all non-clustered hosts
155-
@edit[:new][:non_cl_hosts].each { |c| c[:capture] = params[:check] == "1" }
215+
@edit[:new][:non_cl_hosts].each { |c| c[:capture] = cluster_or_host[:capture] }
156216
elsif model == "EmsCluster" # Clicked on a cluster
157-
@edit[:new][id.to_i].each { |h| h[:capture] = params[:check] == "1" }
217+
@edit[:new][id.to_i].each { |h| h[:capture] = cluster_or_host[:capture] }
158218
elsif model == "Host" # Clicked on a host
159219
nc_host = @edit[:new][:non_cl_hosts].find { |x| x[:id] == id.to_i }
160220
# The host is among the non-clustered ones
161-
return nc_host[:capture] = params[:check] == "1" if nc_host
162-
221+
return nc_host[:capture] = cluster_or_host[:capture] if nc_host
163222
# The host is under a cluster, find it and change it
164223
@edit[:new][:clusters].find do |cl|
165224
@edit[:new][cl[:id]].find do |h|
166225
found = h[:id] == id.to_i
167-
h[:capture] = params[:check] == "1" if found
226+
h[:capture] = cluster_or_host[:capture] if found
168227
found
169228
end
170229
end
171230
end
172231
end
173-
end
232+
end

0 commit comments

Comments
 (0)