Skip to content

Commit

Permalink
fixes #22467 - dashboard: list hosts in build mode
Browse files Browse the repository at this point in the history
  • Loading branch information
timogoebel authored and lzap committed Jun 21, 2018
1 parent d5f2f1d commit bde92a1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Lint/Void:

# Offense count: 604
Metrics/AbcSize:
Max: 128
Max: 132

# Offense count: 345
# Configuration parameters: CountComments, ExcludedMethods.
Expand Down Expand Up @@ -191,7 +191,7 @@ Metrics/MethodLength:
# Offense count: 25
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 441
Max: 446

# Offense count: 10
# Configuration parameters: CountKeywordArgs.
Expand Down
20 changes: 20 additions & 0 deletions app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ def out_of_sync_enabled?(origin)
setting.nil? ? true : !setting
end

def host_build_status_icon(host)
if host.token_expired?
icon = 'hourglass-o'
icon_kind = 'fa'
icon_class = 'text-danger'
label = _('Token expired')
elsif host.build_errors.present?
icon = 'error-circle-o'
icon_kind = 'pficon'
icon_class = ''
label = _('Build errors')
else
icon = 'in-progress'
icon_kind = 'pficon'
icon_class = ''
label = _('Build in progress')
end
icon_text(icon, '', kind: icon_kind, title: label, class: icon_class)
end

private

def origin_setting(origin, name)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/hosts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def name_field(host)
end

def build_duration(host)
return _("N/A") if host.initiated_at.nil? && host.installed_at.nil?
return _('N/A') if host.initiated_at.nil? || host.installed_at.nil?
if host.installed_at.nil?
time_ago_in_words(host.initiated_at, include_seconds: true) + " (in progress)"
else
Expand Down
3 changes: 3 additions & 0 deletions app/models/host/managed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class Jail < ::Safemode::Jail

scope :with_compute_resource, -> { where.not(:compute_resource_id => nil, :uuid => nil) }

scope :in_build_mode, -> { where(build: true) }
scope :with_build_errors, -> { where.not(build_errors: nil) }

# some shortcuts
alias_attribute :arch, :architecture

Expand Down
3 changes: 2 additions & 1 deletion app/services/dashboard/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def builtin_widgets
}
end,
{template: 'reports_widget', sizex: 6, sizey: 1, name: N_('Latest Events')},
{template: 'new_hosts_widget', sizex: 8, sizey: 1, name: N_('New Hosts')}
{template: 'new_hosts_widget', sizex: 8, sizey: 1, name: N_('New Hosts')},
{template: 'hosts_in_build_mode_widget', sizex: 8, sizey: 1, name: N_('Hosts in build mode')}
].flatten.sort_by {|widget| widget['name'] }
end

Expand Down
11 changes: 11 additions & 0 deletions app/views/dashboard/_hosts_in_build_mode_widget.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% hosts = @data.hosts.in_build_mode.or(@data.hosts.with_build_errors).includes(:token).preload(:owner).order(created_at: :desc).limit(9) %>

<h4 class="header">
<%= _('Hosts in Build mode or with Build errors') %>
</h4>

<% if hosts.empty? %>
<p class="ca"><%= icon_text('ok', '', kind: 'pficon') %></span><%= _('No Hosts are in build mode or have build errors.') %></p>
<% else %>
<%= render :partial => 'hosts_in_build_mode_widget_host_list', :locals => { :hosts => hosts } %>
<% end %>
18 changes: 18 additions & 0 deletions app/views/dashboard/_hosts_in_build_mode_widget_host_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<table class="<%= table_css_classes('table-fixed') %>">
<thead>
<th width="40%"><%= _('Host') %></th>
<th><%= _('Owner') %></th>
<th><%= _('Build Duration') %></th>
<th><%= _('Token Expiry') %></th>
</thead>
<tbody>
<% hosts.each do |host| %>
<tr>
<td class="ellipsis"><%= host_build_status_icon(host) %> <%= link_to host.name, host_path(host) %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= host.owner %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= build_duration(host) %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= host.token ? date_time_relative_value(host.token.expires) : _('N/A') %></td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 1 addition & 1 deletion test/unit/dashboard_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DashboardManagerTest < ActiveSupport::TestCase
test '.default_widgets returns built-in widgets' do
Dashboard::Manager.stubs(:registered_report_orgins).returns(['Puppet'])
Foreman::Plugin.expects(:all).returns([])
assert_equal 7, Dashboard::Manager.default_widgets.count
assert_equal 8, Dashboard::Manager.default_widgets.count
end

test '.default_widgets adds plugin widgets' do
Expand Down

0 comments on commit bde92a1

Please sign in to comment.