Skip to content

Commit

Permalink
Merge pull request #4616 from skateman/treeview-powerstate
Browse files Browse the repository at this point in the history
Use the new powerstate icons in treeview for VMs
  • Loading branch information
Dan Clarizio authored Sep 26, 2018
2 parents 751657d + dc73d1d commit b9d30e3
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 53 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/patternfly_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@ table.table-compressed tr td .piechart {
margin-left: 5px;
}

.treeview .icon.node-icon-background {
color: #fff;
}

/// ===================================================================
/// end misc styling
/// ===================================================================
9 changes: 2 additions & 7 deletions app/presenters/tree_builder_genealogy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ def set_locals_for_render
end

def vm_icon_image(vm)
if vm.template?
{:icon => "pficon pficon-template"}
elsif vm.retired
{:image => 'svg/currentstate-retired.svg'}
else
{:image => "svg/currentstate-#{vm.current_state.downcase}.svg"}
end
state = QuadiconHelper.machine_state(vm.normalized_state)
{:icon => state[:fonticon], :iconBackground => state[:background]}
end

def root_options
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/tree_builder_network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class TreeBuilderNetwork < TreeBuilder
has_kids_for Switch, [:x_get_tree_switch_kids]

def override(node, _object, _pid, _options)
node[:selectable] = false if node[:image].nil? || !node[:image].include?('svg/currentstate-')
node[:selectable] = false # if node[:image].nil? || !node[:image].include?('svg/currentstate-')
end

def initialize(name, type, sandbox, build = true, root = nil)
Expand Down
12 changes: 7 additions & 5 deletions app/presenters/tree_node/assigned_server_role.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module TreeNode
class AssignedServerRole < Node
set_attributes(:text, :image, :klass) do
set_attributes(:text, :icon, :icon_background, :klass) do
text = ViewHelper.content_tag(:strong) do
if @options[:tree] == :servers_by_role_tree
"#{_('Server')}: #{@object.name} [#{@object.id}]"
Expand All @@ -20,14 +20,14 @@ class AssignedServerRole < Node
end
end
if @object.active? && @object.miq_server.started?
image = 'svg/currentstate-on.svg'
state = QuadiconHelper.machine_state('on')
text += _(" (%{priority}active, PID=%{number})") % {:priority => priority, :number => @object.miq_server.pid}
else
if @object.miq_server.started?
image = 'svg/currentstate-suspended.svg'
state = QuadiconHelper.machine_state('suspended')
text += _(" (%{priority}available, PID=%{number})") % {:priority => priority, :number => @object.miq_server.pid}
else
image = 'svg/currentstate-off.svg'
state = QuadiconHelper.machine_state('off')
text += _(" (%{priority}unavailable)") % {:priority => priority}
end
klass = "red" if @object.priority == 1
Expand All @@ -36,7 +36,9 @@ class AssignedServerRole < Node
klass = "opacity"
end

[text, image, klass]
icon, bg = state.values_at(:fonticon, :background)

[text, icon, bg, klass]
end
end
end
2 changes: 2 additions & 0 deletions app/presenters/tree_node/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Hash < Node

set_attribute(:icon) { @object[:icon] }

set_attribute(:icon_background) { @object[:icon_background] }

set_attribute(:selectable) { @object.key?(:selectable) ? @object[:selectable] : true }

set_attribute(:hide_checkbox) { @object.key?(:hideCheckbox) && @object[:hideCheckbox] ? true : nil }
Expand Down
27 changes: 16 additions & 11 deletions app/presenters/tree_node/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def icon
@object.try(:decorate).try(:fonticon)
end

def icon_background
nil
end

def klass
nil
end
Expand Down Expand Up @@ -73,17 +77,18 @@ def escape(string)

def to_h
node = {
:key => key,
:text => escape(text),
:tooltip => escape(tooltip),
:icon => icon,
:iconColor => color,
:expand => expand,
:hideCheckbox => hide_checkbox ? hide_checkbox : nil,
:addClass => klass,
:selectable => selectable,
:select => selected,
:checkable => checkable ? nil : false,
:key => key,
:text => escape(text),
:tooltip => escape(tooltip),
:icon => icon,
:iconBackground => icon_background,
:iconColor => color,
:expand => expand,
:hideCheckbox => hide_checkbox ? hide_checkbox : nil,
:addClass => klass,
:selectable => selectable,
:select => selected,
:checkable => checkable ? nil : false,
}

node[:image] = if !image
Expand Down
4 changes: 3 additions & 1 deletion app/presenters/tree_node/vm_or_template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module TreeNode
class VmOrTemplate < Node
set_attribute(:icon) { QuadiconHelper.machine_state(@object.normalized_state)[:fonticon] }
set_attributes(:icon, :icon_background) do
QuadiconHelper.machine_state(@object.normalized_state).values_at(:fonticon, :background)
end

set_attribute(:tooltip) do
unless @object.template?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"moment-timezone": "~0.5.21",
"numeral": "~2.0.6",
"patternfly": "~3.54.1",
"patternfly-bootstrap-treeview": "~2.1.5",
"patternfly-bootstrap-treeview": "~2.1.7",
"patternfly-react": "2.10.1",
"prop-types": "^15.6.0",
"proxy-polyfill": "^0.1.7",
Expand Down
7 changes: 4 additions & 3 deletions spec/presenters/tree_builder_genealogy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@

describe '#root_options' do
it 'sets root to empty one' do
expect(subject.send(:root_options)).to eq(:text => record.name,
:tooltip => "VM: %{name} (Click to view)" % {:name => record.name},
:image => "svg/currentstate-#{record.current_state.downcase}.svg")
expect(subject.send(:root_options)).to eq(:text => record.name,
:tooltip => "VM: %{name} (Click to view)" % {:name => record.name},
:icon => QuadiconHelper.machine_state(record.normalized_state)[:fonticon],
:iconBackground => QuadiconHelper.machine_state(record.normalized_state)[:background])
end
end

Expand Down
26 changes: 14 additions & 12 deletions spec/presenters/tree_builder_roles_by_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@
'icon' => "pficon pficon-server",
'text' => "<strong>Server: #{@miq_server.name} [#{@miq_server.id}] (current) (started)</strong>",
'selectable' => true,
'nodes' => [{'key' => "asr-#{@assigned_server_role1.id}",
'image' => ActionController::Base.helpers.image_path('svg/currentstate-on.svg'),
'text' => "<strong>Role: SmartProxy</strong> (primary, active, PID=)",
'state' => {'expanded' => true},
'selectable' => true,
'class' => ''},
{'key' => "asr-#{@assigned_server_role2.id}",
'image' => ActionController::Base.helpers.image_path('svg/currentstate-on.svg'),
'text' => "<strong>Role: SmartProxy</strong> (secondary, active, PID=)",
'state' => {'expanded' => true},
'selectable' => true,
'class' => ''},],
'nodes' => [{'key' => "asr-#{@assigned_server_role1.id}",
'icon' => 'pficon pficon-on',
'iconBackground' => '#3F9C35',
'text' => "<strong>Role: SmartProxy</strong> (primary, active, PID=)",
'state' => {'expanded' => true},
'selectable' => true,
'class' => ''},
{'key' => "asr-#{@assigned_server_role2.id}",
'icon' => 'pficon pficon-on',
'iconBackground' => '#3F9C35',
'text' => "<strong>Role: SmartProxy</strong> (secondary, active, PID=)",
'state' => {'expanded' => true},
'selectable' => true,
'class' => ''},],
'state' => {'expanded' => true, 'selected' => true},
'class' => ''}]
expect(JSON.parse(@server_tree.locals_for_render[:bs_tree])).to eq(nodes)
Expand Down
26 changes: 14 additions & 12 deletions spec/presenters/tree_builder_servers_by_role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@
"icon" => "ff ff-user-role",
'text' => "Role: SmartProxy (stopped)",
'selectable' => true,
'nodes' => [{'key' => "asr-#{@assigned_server_role1.id}",
'image' => ActionController::Base.helpers.image_path('svg/currentstate-suspended.svg'),
'text' => "<strong>Server: smartproxy [#{@assigned_server_role1.id}]</strong> (primary, available, PID=)",
'state' => { 'expanded' => true },
'selectable' => true,
'class' => 'red', },
{'key' => "asr-#{@assigned_server_role2.id}",
'image' => ActionController::Base.helpers.image_path('svg/currentstate-on.svg'),
'text' => "<strong>Server: smartproxy [#{@assigned_server_role2.id}]</strong> (secondary, active, PID=)",
'state' => { 'expanded' => true },
'selectable' => true,
'class' => ''}],
'nodes' => [{'key' => "asr-#{@assigned_server_role1.id}",
'icon' => 'pficon pficon-asleep',
'iconBackground' => '#FF9900',
'text' => "<strong>Server: smartproxy [#{@assigned_server_role1.id}]</strong> (primary, available, PID=)",
'state' => { 'expanded' => true },
'selectable' => true,
'class' => 'red', },
{'key' => "asr-#{@assigned_server_role2.id}",
'icon' => 'pficon pficon-on',
'iconBackground' => '#3F9C35',
'text' => "<strong>Server: smartproxy [#{@assigned_server_role2.id}]</strong> (secondary, active, PID=)",
'state' => { 'expanded' => true },
'selectable' => true,
'class' => ''}],
'state' => { 'expanded' => true },
'class' => '' }]
expect(JSON.parse(@server_tree.locals_for_render[:bs_tree])).to eq(nodes)
Expand Down

0 comments on commit b9d30e3

Please sign in to comment.