Skip to content

Commit

Permalink
Merge pull request ManageIQ#12980 from ZitaNemeckova/snapshot_fix
Browse files Browse the repository at this point in the history
Fix selection of a node in Snapshot tree
  • Loading branch information
Dan Clarizio authored Dec 8, 2016
2 parents 312ef27 + 406bae0 commit a495372
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
10 changes: 8 additions & 2 deletions app/controllers/vm_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ def show(id = nil)
elsif @display == "snapshot_info"
drop_breadcrumb(:name => @record.name + _(" (Snapshots)"),
:url => "/#{rec_cls}/show/#{@record.id}?display=#{@display}")
@sb[@sb[:active_accord]] = TreeBuilder.build_node_id(@record)
@snapshot_tree = TreeBuilderSnapshots.new(:snapshot_tree, :snapshot, @sb, true, :root => @record)
@active = !['root', nil].include?(@snapshot_tree.selected_node)
@active = if @snapshot_tree.selected_node
snap_selected = Snapshot.find_by_id(from_cid(@snapshot_tree.selected_node.split('-').last))
snap_selected.current?
else
false
end
@button_group = "snapshot"
elsif @display == "devices"
drop_breadcrumb(:name => @record.name + _(" (Devices)"),
Expand Down Expand Up @@ -446,7 +452,7 @@ def snap_pressed
true,
:root => @record,
:selected_node => session[:snap_selected])
@active = @snap_selected.current.to_i == 1 if @snap_selected
@active = @snap_selected.current? if @snap_selected
@button_group = "snapshot"
@explorer = true
c_tb = build_toolbar("x_vm_center_tb")
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/tree_builder_snapshots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(name, type, sandbox, build = true, **params)
private

def tree_init_options(_tree_name)
{:full_ids => true}
{:full_ids => true, :selected_node => @selected_node}
end

def set_locals_for_render
Expand Down
4 changes: 4 additions & 0 deletions app/presenters/tree_node_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ def service_template_catalog_node

def snapshot_node
generic_node(object.name, 'snapshot.png', object.name)
if (options[:selected_node].present? && @node[:key] == options[:selected_node]) ||
(options[:selected_node].nil? && object.children.empty?)
@node[:highlighted] = true
end
@node[:title] += _(' (Active)') if object.current?
end

Expand Down
13 changes: 7 additions & 6 deletions spec/presenters/tree_node_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -901,11 +901,12 @@ def compress_id(id)
snapshot = FactoryGirl.build(:snapshot, :name => "Polaroid Picture")
node = TreeNodeBuilder.build(snapshot, nil, {})
expect(node).to eq(
:key => "-#{snapshot.name}",
:title => snapshot.name,
:icon => "100/snapshot.png",
:tooltip => snapshot.name,
:expand => false
:key => "-#{snapshot.name}",
:title => snapshot.name,
:icon => "100/snapshot.png",
:tooltip => snapshot.name,
:expand => false,
:highlighted => true
)
end

Expand All @@ -916,7 +917,7 @@ def compress_id(id)
:key => "-#{storage.name}",
:title => storage.name,
:icon => "100/storage.png",
:expand => false
:expand => false,
)
end

Expand Down

0 comments on commit a495372

Please sign in to comment.