Skip to content
Snippets Groups Projects
Commit aa7534f0 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Add WDS Image handling

parent fe3abe07
No related branches found
No related tags found
No related merge requests found
function wds_images_load(element){
var url = $(element).attr('data-url');
tfm.tools.showSpinner();
$.ajax({
type:'get',
url: url,
complete: function(){
reloadOnAjaxComplete(element);
},
success: function(request) {
$('#images').html(request);
}
});
}
$(function() {
wds_images_load($('#images'));
})();
......@@ -3,18 +3,10 @@ class WdsImagesController < ApplicationController
before_action :find_resource, only: %i[edit update destroy]
def index
@images = @wds_server.send params[:image_type].to_sym == :boot ? :boot_images : :install_images
respond_to do |format|
format.html { render partial: 'images/list' }
format.json do
render json: @images.select do |img|
keep = true
keep &&= img[:architecture] == wdsify_arch
keep &&= img[:product_family] == wdsify_os.family
keep
end
end
if params[:image_type]
@images = @wds_server.send params[:image_type].to_sym == :boot ? :boot_images : :install_images
else
@images = @wds_server.boot_images + @wds_server.install_images
end
end
......
......@@ -2,7 +2,7 @@ class WdsServersController < ::ApplicationController
include Foreman::Controller::AutoCompleteSearch
include Foreman::Controller::Parameters::WdsServer
before_action :find_server, only: %i[show edit update destroy]
before_action :find_server, except: %i[index new]
def index
@wds_servers = resource_base_search_and_page
......@@ -54,6 +54,18 @@ class WdsServersController < ::ApplicationController
render partial: 'form', locals: { wds_server: @wds_server }
end
def refresh_cache
@wds_server.refresh_cache
render partial: 'form', locals: { wds_server: @wds_server }
end
def wds_images
@images = @wds_server.boot_images + @wds_server.install_images
render partial: 'wds_images/list'
end
private
def find_server
......
......@@ -13,6 +13,16 @@ class ForemanWds::WdsImage
.join(' '))
end
def type_name
self.class
.name
.demodulize
.underscore
.split('_')
.map.with_index { |v, i| i.zero? ? v.upcase : v.capitalize }
.join ' '
end
def marshal_dump
@json
end
......
<% title _('WDS Images') %>
<table id="wds_images" class="<%= table_css_classes %>" data-table='inline'>
<thead>
<tr>
<th><%= s_("Image|Name") %></th>
<th><%= s_("Image|Group Name") %></th>
<th><%= s_("Image|File Name") %></th>
<th><%= s_("Image|Version") %></th>
<th><%= s_("Image|Enabled") %></th>
<th><%= s_("Image|Type") %></th>
</tr>
</thead>
<tbody>
<% @images.each do |image| %>
<tr>
<td><%= image.name %></td>
<td><%= image.image_group if image.respond_to? :image_group %></td>
<td><%= image.file_name %></td>
<td><%= image.version %></td>
<td>
<%- if image.enabled -%>
<%= icon_text 'toggle-on', _('Enabled'),
{ kind: 'fa', class: 'center text-success fa-lg', title: _('Enabled') } %>
<%- else -%>
<%= icon_text 'toggle-off', _('Disabled'),
{ kind: 'fa', class: 'center fa-lg', title: _('Disabled') } %>
<%- end -%>
</td>
<td><%= image.type_name %></td>
</tr>
<% end %>
</tbody>
</table>
......@@ -13,7 +13,7 @@
<div class="tab-content">
<div class="tab-pane active" id="primary">
<%= text_f f, :name %>
<%= text_f f, :url, placeholder: 'https://host.example.com:5985/wsman' %>
<%= text_f f, :url, placeholder: 'http://host.example.com:5985/wsman' %>
<%= textarea_f f, :description, :rows => 3 %>
<%= text_f f, :user %>
<%= password_f f, :password %>
......
<% title @wds_server.name %>
<% title_actions link_to_if_authorized(_('Edit'), hash_for_edit_wds_server_path(@wds_server).merge(:auth_object => @wds_server), :class => "btn btn-default") %>
<% title_actions \
display_link_if_authorized(_('Refresh Cache'), hash_for_refresh_cache_wds_server_path(@wds_server).merge(:auth_object => @wds_server), method: :post, class: 'btn btn-default'),
link_to_if_authorized(_('Edit'), hash_for_edit_wds_server_path(@wds_server).merge(:auth_object => @wds_server), class: 'btn btn-default') %>
<% javascript 'foreman_wds/wds_servers' %>
<ul class="nav nav-tabs" data-tabs="tabs">
<li class="active"><a href="#primary" data-toggle="tab"><%= _("WDS Server") %></a></li>
......@@ -16,10 +19,12 @@
</tr>
</thead>
<tbody>
<%- unless @wds_server.description.empty? -%>
<tr>
<td><%= _('Description') %></td>
<td><%= @wds_server.description %></td>
</tr>
<%- end -%>
<tr>
<td><%= _('Url') %></td>
<td><%= @wds_server.url %></td>
......@@ -31,7 +36,7 @@
</tbody>
</table>
</div>
<div id="images" class="tab-pane" data-url="<%= wds_server_wds_images_path(@wds_server, image_type: :boot) %>">
<div id="images" class="tab-pane" data-url="<%= wds_images_wds_server_path(@wds_server) %>#wds_images">
<%= spinner(_('Loading image information ...')) %>
</div>
</div>
......@@ -6,7 +6,10 @@ Rails.application.routes.draw do
get 'auto_complete_search'
post 'test_connection'
end
resources :wds_images, except: %i[show]
member do
post 'refresh_cache'
get 'wds_images'
end
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment