forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm_show_mixin.rb
146 lines (123 loc) · 4.89 KB
/
vm_show_mixin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
module VmShowMixin
extend ActiveSupport::Concern
def explorer
@explorer = true
@lastaction = "explorer"
@timeline = @timeline_filter = true # need to set these to load timelines on vm show screen
if params[:menu_click] # Came in from a chart context menu click
@_params[:id] = parse_nodetype_and_id(x_node_right_cell).last
@explorer = true
perf_menu_click # Handle the menu action
return
end
# if AJAX request, replace right cell, and return
if request.xml_http_request?
replace_right_cell
return
end
if params[:accordion]
self.x_active_tree = "#{params[:accordion]}_tree"
self.x_active_accord = params[:accordion]
end
if params[:button]
@miq_after_onload = "miqAjax('/#{controller_name}/x_button?pressed=#{params[:button]}');"
end
# Build the Explorer screen from scratch
allowed_features = build_accordions_and_trees_only
params.instance_variable_get(:@parameters).merge!(session[:exp_parms]) if session[:exp_parms] # Grab any explorer parm overrides
session.delete(:exp_parms)
if params[:commit] == "Upload" && session.fetch_path(:edit, :new, :sysprep_enabled, 1) == "Sysprep Answer File"
upload_sysprep_file
set_form_locals_for_sysprep
end
if params[:id]
# if you click on a link to VM on a dashboard widget that will redirect you
# to explorer with params[:id] and you get into the true branch
redirected = set_elements_and_redirect_unauthorized_user
else
set_active_elements(allowed_features.first) unless @upload_sysprep_file
end
render :layout => "application" unless redirected
end
def set_form_locals_for_sysprep
_partial, action, @right_cell_text = set_right_cell_vars
locals = {:submit_button => true,
:no_reset => true,
:action_url => action
}
@x_edit_buttons_locals = locals
end
# VM or Template show selected, redirect to proper controller, to get links on tasks screen working
def vm_show
record = VmOrTemplate.find_by_id(params[:id])
redirect_to :action => 'show', :controller => record.class.base_model.to_s.underscore, :id => record.id
end
private
def set_active_elements(feature, _x_node_to_set = nil)
if feature
self.x_active_tree ||= feature.tree_list_name
self.x_active_accord ||= feature.accord_name
end
get_node_info(x_node_right_cell)
end
def set_active_elements_authorized_user(tree_name, accord_name)
self.x_active_tree = tree_name
self.x_active_accord = accord_name
end
def show_record(id = nil)
@display = params[:display] || "main" unless pagination_or_gtl_request?
@lastaction = "show"
@showtype = "config"
@vm = @record = identify_record(id, VmOrTemplate) unless @record
if @record.nil?
add_flash(_("Error: Record no longer exists in the database"), :error)
if request.xml_http_request? && params[:id] # Is this an Ajax request clicking on a node that no longer exists?
@delete_node = params[:id] # Set node to be removed from the tree
end
return
end
case @display
when "download_pdf", "main", "summary_only"
@button_group = @record.kind_of?(MiqTemplate) ? "miq_template" : "vm"
get_tagdata(@record)
@showtype = "main"
set_summary_pdf_data if ["download_pdf", "summary_only"].include?(@display)
when "performance"
@showtype = "performance"
perf_gen_init_options # Initialize perf chart options, charts will be generated async
when "timeline"
@showtype = "timeline"
tl_build_timeline # Create the timeline report
end
get_host_for_vm(@record)
session[:tl_record_id] = @record.id
end
def get_filters
session[:vm_filters]
end
def get_session_data
@title = _("VMs And Templates")
@layout = controller_name
@lastaction = session[:vm_lastaction]
@showtype = session[:vm_showtype]
@filters = get_filters
@catinfo = session[:vm_catinfo]
@display = session[:vm_display]
@polArr = session[:polArr] || "" # current tags in effect
@policy_options = session[:policy_options] || ""
end
def set_session_data
session[:vm_lastaction] = @lastaction
session[:vm_showtype] = @showtype
session[:miq_compressed] = @compressed unless @compressed.nil?
session[:miq_exists_mode] = @exists_mode unless @exists_mode.nil?
session[:vm_filters] = @filters
session[:vm_catinfo] = @catinfo
session[:vm_display] = @display unless @display.nil?
session[:polArr] = @polArr unless @polArr.nil?
session[:policy_options] = @policy_options unless @policy_options.nil?
end
def breadcrumb_name(model)
ui_lookup(:models => model || self.class.model.name)
end
end