Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #21643 - fix and move nfs_visibilty.js to webpack #5002

Merged
merged 1 commit into from Nov 30, 2017

Conversation

amirfefer
Copy link
Member

@amirfefer amirfefer commented Nov 13, 2017

nfs section does not become visible when choosing a required nfs os family in installation media form.
This occurs due to broken script file - nfs_visibilty.js, which apparently doesn't work since moving to a select box from checkbox to choose an os family.
I re-wrote the logic and moved it to wepback

@theforeman-bot
Copy link
Member

Issues: #21643


def required_nfs_list
Hash[Operatingsystem.families.map {|key|
[key, key.constantize.require_nfs_access_to_medium]}].to_json

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expression at 6, 58 should be on its own line.

@@ -1,3 +1,8 @@
module MediumsHelper
include PtablesHelper

def required_nfs_list
Hash[Operatingsystem.families.map {|key|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using {...} for multi-line blocks.


def required_nfs_list
Hash[Operatingsystem.families.map {|key|
[key, key.constantize.require_nfs_access_to_medium]}].to_json

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expression at 6, 58 should be on its own line.

@@ -1,3 +1,8 @@
module MediumsHelper
include PtablesHelper

def required_nfs_list
Hash[Operatingsystem.families.map {|key|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using {...} for multi-line blocks.

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments inline.
Also, IIRC there was some dead css code you can get rid of while you're here.

$('#nfs-section').show();
} else {
$('#nfs-section').hide();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this a one liner:

$('#nfs-section').toggle(nfsRequired[osFamily.value]);

@@ -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?(!@medium.operatingsystems.map{ |obj| obj.class.require_nfs_access_to_medium }.any?) %>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if the medium has solaris os_family but no operating systems assigned.
Why not also leverage the required_nfs_list helper here?
p.s. you can use any? with a block instead of .map{..}.any?

Hash[Operatingsystem.families.map do |key|
[key, key.constantize.require_nfs_access_to_medium]
end].to_json
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just return a list of all families requiring it and check if the selected family is in it or not?

@amirfefer
Copy link
Member Author

@tbrisker , Thanks for your review, could you have a second look?

@theforeman-bot
Copy link
Member

@amirfefer, this pull request is currently not mergeable. Please rebase against the develop branch and push again.

If you have a remote called 'upstream' that points to this repository, you can do this by running:

    $ git pull --rebase upstream develop

This message was auto-generated by Foreman's prprocessor

@@ -0,0 +1,31 @@
jest.unmock('./foreman_medium');
import $ from 'jquery';
import {nfsVisibility} from './foreman_medium';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import in body of module; reorder to top import/first
Expected empty line after import statement not followed by another import import/newline-after-import
A space is required after '{' object-curly-spacing
A space is required before '}' object-curly-spacing

@@ -0,0 +1,31 @@
jest.unmock('./foreman_medium');
import $ from 'jquery';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import in body of module; reorder to top import/first

import $ from 'jquery';

export function nfsVisibility(osFamily, nfsRequired) {
nfsRequired.includes(osFamily.value) ? $('#nfs-section').show() : $('#nfs-section').hide();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected an assignment or function call and instead saw an expression no-unused-expressions

@@ -34,4 +34,8 @@ window.tfm = Object.assign(window.tfm || {}, {
reactMounter: require('./react_app/common/MountingService'),
editor: require('./foreman_editor'),
nav: require('./foreman_navigation'),
<<<<<<< HEAD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: Unexpected token

@@ -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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing trailing comma comma-dangle

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment, other than that works well.


def required_nfs?
required_nfs_list.include?(@medium.os_family) ||
@medium.operatingsystems.any?{ |obj| obj.class.require_nfs_access_to_medium }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part of this check is redundant, you can only add operating systems that match the family

@amirfefer
Copy link
Member Author

@tbrisker , Thanks for your review,
could you have a second look?

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, will merge once tests pass.

@tbrisker tbrisker merged commit 8f7f710 into theforeman:develop Nov 30, 2017
@tbrisker
Copy link
Member

Thanks @amirfefer !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants