Skip to content

Commit

Permalink
Refs #35274 - Use SelectableColumns on hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Jul 25, 2022
1 parent f23cd03 commit 92f68ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
17 changes: 2 additions & 15 deletions app/views/hosts/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@
<% if power_status_visible? %>
<th class="ca" width="80px"><%= _('Power') %></th>
<% end %>
<th width="25%"><%= sort :name, :as => _('Name') %></th>
<th class="hidden-xs" width="17%"><%= sort :os_title, :as => _("Operating system") %></th>
<th class="hidden-tablet hidden-xs" width="10%"><%= sort :model, :as => _('Model') %></th>
<th class="hidden-tablet hidden-xs" width="8%"><%= sort :owner, :as => _('Owner') %></th>
<th class="hidden-tablet hidden-xs" width="15%"><%= sort :hostgroup, :as => _("Host group") %></th>
<th class="hidden-tablet hidden-xs" width="10%"><%= sort :last_report, :as => _('Last report'), :default => 'DESC' %></th>
<%= render_selected_column_ths %>
<%= render_pagelets_for(:hosts_table_column_header) %>
<th class="hidden-tablet hidden-xs" width="7%"><%= sort :comment, :as => _('Comment') %></th>
<th width="100px"><%= _('Actions') %></th>
</tr>
</thead>
Expand All @@ -29,15 +23,8 @@
<%= react_component('PowerStatus', id: host.id, url: power_api_host_path(host)) %>
</td>
<% end %>
<td class="ellipsis"><%= name_column(host) %>
</td>
<td class="hidden-xs ellipsis"><%= (icon(host.operatingsystem, :size => "16x16") + " #{host.operatingsystem.to_label}").html_safe if host.operatingsystem %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= host.compute_resource_or_model %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= host_owner_column(host) %></td>
<td class="hidden-tablet hidden-xs"><%= label_with_link host.hostgroup, 23, @hostgroup_authorizer %></td>
<td class="hidden-tablet hidden-xs ellipsis"><%= last_report_column(host) %></td>
<%= render_selected_column_tds(host) %>
<%= render_pagelets_for(:hosts_table_column_content, :subject => host) %>
<td class="hidden-tablet hidden-xs ca" title="<%= host.comment&.truncate(255) %>"><%= icon_text('comment', '') unless host.comment.empty? %></td>
<td>
<%= action_buttons(
display_link_if_authorized(_("Edit"), hash_for_edit_host_path(:id => host).merge(:auth_object => host, :authorizer => authorizer)),
Expand Down
23 changes: 23 additions & 0 deletions config/initializers/foreman_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,26 @@
partial: 'hosts/init_config_tab',
priority: 100
end

Foreman::SelectableColumns::Storage.define(:hosts) do
common_th_class = 'hidden-tablet hidden-xs'
common_td_class = common_th_class + ' ellipsis'
category :general, default: true do
column :name, th: { label: _('Name'), sortable: true, width: '25%' },
td: { class: 'ellipsis', callback: ->(host) { name_column(host) } }
column :os_title, th: { label: _('Operating system'), sortable: true, width: '17%', class: 'hidden-xs' },
td: { class: 'hidden-xs ellipsis', callback: ->(host) { (icon(host.operatingsystem, size: "16x16") + " #{host.operatingsystem.to_label}").html_safe if host.operatingsystem } }
column :model, th: { label: _('Model'), sortable: true, width: '10%', class: common_th_class },
td: { class: common_td_class, callback: ->(host) { host.compute_resource_or_model } }
column :owner, th: { label: _('Owner'), sortable: true, width: '8%', class: common_th_class },
td: { class: common_td_class, callback: ->(host) { host_owner_column(host) } }
column :hostgroup, th: { label: _('Host group'), sortable: true, width: '15%', class: common_th_class },
td: { class: common_th_class, callback: ->(host) { label_with_link host.hostgroup, 23, @hostgroup_authorizer } }
column :last_report, th: { label: _('Last report'), sortable: true, default_sort: 'DESC', width: '10%', class: common_th_class },
td: { class: common_td_class, callback: ->(host) { last_report_column(host) } }
column :comment, th: { label: _('Comment'), sortable: true, width: '7%', class: common_th_class },
td: { class: common_th_class + ' ca',
attr_callbacks: { title: ->(host) { host.comment&.truncate(255) } },
callback: ->(host) { icon_text('comment', '') unless host.comment.empty? } }
end
end

0 comments on commit 92f68ca

Please sign in to comment.