Revision ad3852f2
Added by Ohad Levy over 8 years ago
app/controllers/containers_controller.rb | ||
---|---|---|
8 | 8 |
:search_repository] |
9 | 9 |
|
10 | 10 |
def index |
11 |
@container_resources = allowed_resources.select { |cr| cr.provider == 'Docker' }
|
|
11 |
@container_resources = allowed_resources |
|
12 | 12 |
if @container_resources.empty? |
13 | 13 |
warning('You need a Compute Resource of type Docker to start managing containers') |
14 | 14 |
redirect_to new_compute_resource_path |
... | ... | |
139 | 139 |
end |
140 | 140 |
|
141 | 141 |
def allowed_resources |
142 |
ComputeResource.authorized(:view_compute_resources)
|
|
142 |
ForemanDocker::Docker.authorized(:view_compute_resources)
|
|
143 | 143 |
end |
144 | 144 |
|
145 | 145 |
# To be replaced by find_resource after 1.6 support is deprecated |
app/helpers/containers_helper.rb | ||
---|---|---|
1 | 1 |
module ContainersHelper |
2 | 2 |
def managed_icon(container, resource) |
3 |
if managed?(container, resource) |
|
4 |
'<span class="glyphicon glyphicon-check"></span>'.html_safe |
|
5 |
else |
|
6 |
'<span class="glyphicon glyphicon-unchecked"></span>'.html_safe |
|
7 |
end |
|
3 |
icon_text(managed?(container, resource) ? 'check' : 'unchecked') |
|
8 | 4 |
end |
9 | 5 |
|
10 | 6 |
def managed?(container, resource) |
app/views/containers/_list.html.erb | ||
---|---|---|
1 | 1 |
<table class="table table-bordered table-striped table-condensed" data-table="inline"> |
2 |
</thead>
|
|
3 |
<tr>
|
|
4 |
<th class="text-center"><%= sort :name, :as => _("Name") %></th>
|
|
5 |
<th class="hidden-tablet hidden-xs text-center"><%= sort :status, :as => _("Status") %></th>
|
|
6 |
<th class="hidden-tablet hidden-xs text-center"><%= sort :image, :as => _("Image") %></th>
|
|
7 |
<th class="hidden-tablet hidden-xs text-center"><%= sort :command, :as => _("Command") %></th>
|
|
8 |
<th class="hidden-tablet hidden-xs text-center"><%= sort :uptime, :as => _("Uptime") %></th>
|
|
9 |
<th class="hidden-tablet hidden-xs text-center"><%= sort :running_on, :as => _("Running on") %></th>
|
|
10 |
<th class="hidden-tablet hidden-xs text-center"><%= sort :managed , :as => _("Managed") %></th>
|
|
11 |
<th></th>
|
|
12 |
</tr>
|
|
2 |
<thead> |
|
3 |
<tr> |
|
4 |
<th class="text-center"><%= _("Name") %></th>
|
|
5 |
<th class="hidden-tablet hidden-xs text-center"><%= _("Status") %></th>
|
|
6 |
<th class="hidden-tablet hidden-xs text-center"><%= _("Image") %></th>
|
|
7 |
<th class="hidden-tablet hidden-xs text-center"><%= _("Command") %></th>
|
|
8 |
<th class="hidden-tablet hidden-xs text-center"><%= _("Uptime") %></th>
|
|
9 |
<th class="hidden-tablet hidden-xs text-center"><%= _("Running on") %></th>
|
|
10 |
<th class="hidden-tablet hidden-xs text-center"><%= _("Managed") %></th>
|
|
11 |
<th></th> |
|
12 |
</tr> |
|
13 | 13 |
</thead> |
14 | 14 |
|
15 |
<tbody> |
|
15 | 16 |
<% containers.each do |container| %> |
16 | 17 |
<tr> |
17 | 18 |
<td class="ellipsis text-center"><%= link_to_container(container, resource) %></td> |
18 |
<td class="hidden-tablet hidden-xs text-center"><span <%= vm_power_class(container.ready?) %>><%= vm_state(container) %></span></td> |
|
19 |
<td class="hidden-tablet hidden-xs text-center"> |
|
20 |
<span <%= vm_power_class(container.ready?) %>><%= vm_state(container) %></span></td> |
|
19 | 21 |
<td class="hidden-tablet hidden-xs text-center"><%= trunc(container.image_friendly_name) %></td> |
20 | 22 |
<td class="hidden-tablet hidden-xs text-center"><%= trunc(container.command) %></td> |
21 |
<td class="hidden-tablet hidden-xs text-center"><span class="glyphicon glyphicon-time"></span> <%= container.ready? ? time_ago_in_words(container.started_at) : "N/A" %></td> |
|
22 |
<td class="hidden-tablet hidden-xs text-center"><%= link_to resource, compute_resource_path(resource)%> </td> |
|
23 |
<td class="hidden-tablet hidden-xs text-center"> |
|
24 |
<span class="glyphicon glyphicon-time"></span> <%= container.ready? ? time_ago_in_words(container.started_at) : "N/A" %> |
|
25 |
</td> |
|
26 |
<td class="hidden-tablet hidden-xs text-center"><%= link_to resource, compute_resource_path(resource) %> </td> |
|
23 | 27 |
<td class="hidden-tablet hidden-xs text-center"><%= managed_icon(container, resource) %></td> |
24 | 28 |
<% @compute_resource = resource %> |
25 | 29 |
<td><%= action_buttons(vm_power_action(container), |
... | ... | |
30 | 34 |
:confirm => _("Delete %s?") % container.name)) %></td> |
31 | 35 |
</tr> |
32 | 36 |
<% end %> |
37 |
</tbody> |
|
33 | 38 |
</table> |
34 |
|
|
35 |
<!-- To be replaced by will_paginate_with_info after 1.6 support is deprecated --> |
|
36 |
<%= page_entries_info containers %> |
|
37 |
<%= will_paginate containers %> |
app/views/containers/index.html.erb | ||
---|---|---|
2 | 2 |
|
3 | 3 |
<% if authorized? %> |
4 | 4 |
<% title_actions button_group(link_to_if_authorized _("New container"), hash_for_new_container_path, |
5 |
:class => 'btn-success' ) %>
|
|
5 |
:class => 'btn-success') %>
|
|
6 | 6 |
<% end %> |
7 | 7 |
|
8 | 8 |
<ul class="nav nav-tabs" data-tabs="tabs"> |
... | ... | |
23 | 23 |
<div class="tab-pane" id="<%= resource.name %>"> |
24 | 24 |
<% end %> |
25 | 25 |
<% if resource.test_connection %> |
26 |
<%= render 'list', :containers => resource.vms.to_a |
|
27 |
.sort_by(&:name).paginate(:page => params[:page], |
|
28 |
:per_page => 10), |
|
29 |
:resource => resource %> |
|
26 |
<%= render 'list', :containers => resource.vms, |
|
27 |
:resource => resource %> |
|
30 | 28 |
<% else %> |
31 | 29 |
<div class="alert alert-warning"> |
32 | 30 |
<%= (_("Error connecting with the compute resource: <strong> %s </strong>") % resource.errors.messages[:base]).html_safe %> |
33 | 31 |
</div> |
34 |
<% end%> |
|
32 |
<% end %>
|
|
35 | 33 |
</div> |
36 | 34 |
<% end %> |
37 |
</div> |
|
35 |
</div> |
|
36 |
</div> |
Also available in: Unified diff
fixes #8718 - refactor container index
- simplify controller to use the correct compute resource type in sql
- used icon helper methods
- fixed html syntax + removed duplicate pagination