Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tooltip to health state of the cards in the physical infra dashboard #4453

Merged
merged 1 commit into from Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 37 additions & 30 deletions app/services/ems_physical_infra_dashboard_service.rb
Expand Up @@ -66,7 +66,7 @@ def attributes_data
:title => attr_hsh[attr],
:count => ems_attr.length,
:href => get_url(@ems_id, attr_url[attr]),
:notification => notification_data(ems_attr)
:notification => notification_data(ems_attr, attr_hsh[attr])
)
end
attr_data
Expand Down Expand Up @@ -101,39 +101,46 @@ def recent_servers
}
end

def notification_data(attrs)
valid = 0
warning = 0
critical = 0
attrs.each do |attr|
next unless attr.respond_to?(:health_state)
case attr.health_state&.downcase
when 'critical'
critical += 1
when 'warning'
warning += 1
when 'valid'
valid += 1
end
end
if critical.positive?
icon_class = 'pficon pficon-error-circle-o'
count = critical
elsif warning.positive?
icon_class = 'pficon pficon-warning-triangle-o'
count = warning
elsif valid.positive?
icon_class = 'pficon pficon-ok'
count = valid
else
icon_class = 'pficon pficon-error-circle-o'
def notification_data(components, component_type)
if components&.first.respond_to?(:health_state)
count = 0
health_states = components.group('lower(health_state)').count
health_states.default = 0
critical_count = health_states["critical"]
warning_count = health_states["warning"]

if critical_count.positive?
icon_class = 'pficon pficon-error-circle-o'
count = critical_count
health_state = 'critical'
elsif warning_count.positive?
icon_class = 'pficon pficon-warning-triangle-o'
count = warning_count
health_state = 'warning'
else
health_state = 'valid'
icon_class = 'pficon pficon-ok'
end
tooltip_count = count.positive? ? count : components.count
{
:count => count,
:iconClass => icon_class,
:tooltip => format_tooltip(health_state, component_type.downcase, tooltip_count),
}
end
end

{
:iconClass => icon_class,
:count => count,
def format_tooltip(health_state, component_type, count)
tooltip_data = {
:count => count,
:component_type => count > 1 ? component_type : component_type.singularize,
:health_state => health_state,
}
n_(
"%{count} %{component_type} is in %{health_state} state.",
"%{count} %{component_type} are in %{health_state} state.",
count
) % tooltip_data
end

def servers_group
Expand Down
Expand Up @@ -46,7 +46,7 @@

%div{:class => "card-pf-body"}
%p{"ng-if" => "$ctrl.status.notification.iconImage || $ctrl.status.notification.iconClass || $ctrl.status.notification.count", :class => "card-pf-aggregate-status-notifications"}
%span{:class => "card-pf-aggregate-status-notification"}
%span{:class => "card-pf-aggregate-status-notification", :title => "{{$ctrl.status.notification.tooltip}}" }
%a{"ng-if" => "$ctrl.status.notification.href", :href => "{{$ctrl$ctrl.status.notification.href}}"}
%image{"ng-if" => "$ctrl.status.notification.iconImage", "ng-src" => "{{$ctrl.status.notification.iconImage}}", :alt => "", :class => "card-pf-icon-image"}
%span{"ng-if" => "$ctrl.status.notification.iconClass", :class => "{{$ctrl.status.notification.iconClass}}"}
Expand All @@ -58,3 +58,7 @@
%span{"ng-if" => "$ctrl.status.notification.iconClass", :class => "{{$ctrl.status.notification.iconClass}}"}
%span{"ng-if" => "$ctrl.status.notification.count"}
{{$ctrl.status.notification.count}}

%span{"ng-if" => "!$ctrl.status.notification.href && !$ctrl.status.notification.count"}
%image{"ng-if" =>"$ctrl.status.notification.iconImage", "ng-src" => "{{$ctrl.status.notification.iconImage}}", :alt => "", :class => "card-pf-icon-image"}
%span{"ng-if" => "$ctrl.status.notification.iconClass", :class => "{{$ctrl.status.notification.iconClass}}"}