Skip to content

Commit

Permalink
Fixes #21643 - fix and move nfs_visibilty.js to webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfefer authored and tbrisker committed Nov 30, 2017
1 parent 763018b commit 8f7f710
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 54 deletions.
33 changes: 0 additions & 33 deletions app/assets/javascripts/nfs_visibility.js

This file was deleted.

11 changes: 0 additions & 11 deletions app/assets/stylesheets/base.scss
Expand Up @@ -138,17 +138,6 @@ select {
padding: initial;
}

.inputs-list {
display: inline;
list-style: none;
margin-bottom: 18px;
margin-left: 0;
}

.collapse .inputs-list li {
margin-left: 20px;
}

.delete {
color: #b94a48 !important;
cursor: pointer;
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/mediums_helper.rb
@@ -1,3 +1,11 @@
module MediumsHelper
include PtablesHelper

def required_nfs_list
Operatingsystem.families.select {|family| family.constantize.require_nfs_access_to_medium }
end

def required_nfs?
required_nfs_list.include?(@medium.os_family)
end
end
2 changes: 1 addition & 1 deletion app/models/operatingsystem.rb
Expand Up @@ -233,7 +233,7 @@ def image_extension
end

# If this OS family requires access to its media via NFS
def require_nfs_access_to_medium
def self.require_nfs_access_to_medium
false
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/operatingsystems/solaris.rb
Expand Up @@ -48,7 +48,7 @@ def pxeconfig_default
end

# If this OS family requires access to its media via NFS
def require_nfs_access_to_medium
def self.require_nfs_access_to_medium
true
end

Expand Down
8 changes: 2 additions & 6 deletions app/views/media/_form.html.erb
@@ -1,4 +1,3 @@
<%= javascript "nfs_visibility" %>
<%= form_for @medium do |f| %>
<%= base_errors_for @medium %>

Expand All @@ -17,18 +16,15 @@
<%= text_f f, :name %>
<%= text_f f, :path, :size => "col-md-8", :help_block => _("The path to the medium, can be a URL or a valid NFS server (exclusive of the architecture).
for example <em>http://mirror.centos.org/centos/$version/os/$arch</em> where <strong>$arch</strong> will be substituted for the host's actual OS architecture and <strong>$version</strong>, <strong>$major</strong> and <strong>$minor</strong> will be substituted for the version of the operating system. Solaris and Debian media may also use <strong>$release</strong>.").html_safe %>
<span id="nfs-section" <%= display?(!@medium.operatingsystems.map(&:require_nfs_access_to_medium).any?) %>>
<span id="nfs-section" <%= display?(!required_nfs?) %>>
<%= text_f f, :media_path, :size => "col-md-8", :help_inline => _("The NFS path to the media.") %>
<%= text_f f, :config_path, :size => "col-md-8", :help_inline => _("The NFS path to the jumpstart control files.") %>
<%= text_f f, :image_path, :size => "col-md-8", :help_inline => _("The NFS path to the image directory.") %>
</span>
<%= select_f f, :os_family, Operatingsystem.families_as_collection, :value, :name, { :include_blank => _("Choose a family") }, { :label => _("Operating System Family") } %>
<%= select_f f, :os_family, Operatingsystem.families_as_collection, :value, :name, { :include_blank => _("Choose a family") }, { :label => _("Operating System Family"), :onchange => "tfm.medium.nfsVisibility(this, #{required_nfs_list.to_json});" } %>
</div>
<%= render 'taxonomies/loc_org_tabs', :f => f, :obj => @medium %>
<%= submit_or_cancel f %>
</div>
<% end %>

<script type="text/javascript" charset="utf-8">
nfs_section_visibility([<%= Operatingsystem.all.map(&:require_nfs_access_to_medium).join(", ") %>])
</script>
1 change: 0 additions & 1 deletion app/views/media/index.html.erb
@@ -1,4 +1,3 @@
<%= javascript "nfs_visibility" %>
<% title _("Installation Media") %>
<% title_actions new_link(_("Create Medium")),
documentation_button('4.4.2InstallationMedia'),
Expand Down
1 change: 0 additions & 1 deletion config/initializers/assets.rb
Expand Up @@ -17,7 +17,6 @@
host_edit_interfaces
hosts
host_checkbox
nfs_visibility
noVNC/base64
noVNC/des
noVNC/display
Expand Down
1 change: 1 addition & 0 deletions webpack/assets/javascripts/bundle.js
Expand Up @@ -34,4 +34,5 @@ window.tfm = Object.assign(window.tfm || {}, {
reactMounter: require('./react_app/common/MountingService'),
editor: require('./foreman_editor'),
nav: require('./foreman_navigation'),
medium: require('./foreman_medium'),
});
5 changes: 5 additions & 0 deletions webpack/assets/javascripts/foreman_medium.js
@@ -0,0 +1,5 @@
import $ from 'jquery';

export function nfsVisibility(osFamily, nfsRequired) {
$('#nfs-section').toggle(nfsRequired.includes(osFamily.value));
}
32 changes: 32 additions & 0 deletions webpack/assets/javascripts/foreman_medium.test.js
@@ -0,0 +1,32 @@
import $ from 'jquery';
import { nfsVisibility } from './foreman_medium';

jest.unmock('./foreman_medium');
const nfsRequired = ['Solaris'];

document.body.innerHTML =
`<span id="nfs-section" style=display:none;>
<span class="help-block help-inline">The NFS path to the media.</span>
<span class="help-block help-inline">The NFS path to the jumpstart control files.</span>
<span class="help-block help-inline">The NFS path to the image directory.</span>
</span>
<select id='os_family' id="medium_os_family">
<option value="">Choose a family</option>
<option value="Redhat">Red Hat</option>
<option value="Solaris">Solaris</option>
</select>`;

it('When an os family with required nfs is chosen, nfs section should be visable', () => {
$.fn.show = jest.fn();
expect($('#os_family').is(':visible')).toBe(false);
$('#os_family').val('Solaris');
nfsVisibility($('#os_family')[0], nfsRequired);
expect($.fn.show).toBeCalled();
});

it('When an os family without required nfs is chosen, nfs section should be hidden', () => {
$.fn.hide = jest.fn();
$('#os_family').val('Redhat');
nfsVisibility($('#os_family')[0], nfsRequired);
expect($.fn.hide).toBeCalled();
});

0 comments on commit 8f7f710

Please sign in to comment.