Skip to content

Commit

Permalink
Fixes #10395 - fine grain for CPU selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ares authored and tbrisker committed Sep 15, 2016
1 parent 8fde288 commit 8096335
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/host_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function computeResourceSelected(item){
activate_select2('#compute_resource');
if ($('#compute_resource').find('.alert-danger').length > 0) $('#compute_resource_tab a').addClass('tab-error');
update_capabilities($('#capabilities').val());
tfm.initByteSpinner();
tfm.numFields.initAll();
}
})
}
Expand Down
20 changes: 16 additions & 4 deletions app/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,27 @@ def autocomplete_f(f, attr, options = {})
def byte_size_f(f, attr, options = {})
options[:class] = options[:class].to_s + ' byte_spinner'
options[:help_inline] ||= popover('', _("When specifying custom value, add 'MB' or 'GB' at the end. Field is not case sensitive and MB is default if unspecified."))
options[:help_block] ||= content_tag(:span, :class => 'maximum-limit hidden') do
content_tag(:i, '', :class => 'pficon-warning-triangle-o') +
content_tag(:span, ' ' + _('Specified value is higher than recommended maximum'), :class => 'error-message')
end
options[:help_block] ||= soft_limit_warning_block
options[:help_block] += f.hidden_field(attr, :class => "real-hidden-value", :id => nil)

text_f(f, attr, options)
end

def counter_f(f, attr, options = {})
options[:class] = options[:class].to_s + ' counter_spinner'
options[:help_block] ||= soft_limit_warning_block

text_f(f, attr, options)
end

def soft_limit_warning_block
content_tag(:span, :class => 'maximum-limit hidden') do
icon_text('warning-triangle-o',
content_tag(:span, ' ' + _('Specified value is higher than recommended maximum'), :class => 'error-message'),
:kind => 'pficon')
end
end

def form_to_submit_id(f)
object = f.object.respond_to?(:to_model) ? f.object.to_model : f.object
key = if object.present?
Expand Down
4 changes: 2 additions & 2 deletions app/views/compute_resources_vms/form/libvirt/_base.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<%= javascript_tag("$(document).on('ContentLoad', tfm.initByteSpinner)"); %>
<%= javascript_tag("$(document).on('ContentLoad', tfm.numFields.initAll)"); %>

<%= text_f f, :name, :label => _('Name'), :label_size => "col-md-2", :disabled => !new_host if show_vm_name? %>

<%= selectable_f f, :cpus, 1..compute_resource.max_cpu_count, { }, :disabled => !new_host, :label => _('CPUs'), :label_size => "col-md-2" %>
<%= counter_f f, :cpus, :disabled => !new_host, :label => _('CPUs'), :label_size => 'col-md-2', :'data-soft-max' => compute_resource.max_cpu_count %>

<%= byte_size_f f, :memory, :disabled => !new_host, :label => _('Memory'), :label_size => "col-md-2", :'data-soft-max' => compute_resource.max_memory %>

Expand Down
5 changes: 3 additions & 2 deletions app/views/compute_resources_vms/form/ovirt/_base.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= javascript_tag("$(document).on('ContentLoad', tfm.initByteSpinner)"); %>
<%= javascript_tag("$(document).on('ContentLoad', tfm.numFields.initAll)"); %>

<% javascript 'compute_resource' %>
<%= text_f f, :name, :label => _('Name'), :label_size => "col-md-3" if show_vm_name? %>
<% clusters = compute_resource.clusters %>
Expand All @@ -18,7 +19,7 @@

<% selected_cluster ||= params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:cluster] %>

<%= selectable_f f, :cores, 1..compute_resource.max_cpu_count, { }, :class => "col-md-2", :label => _('Cores'), :label_size => "col-md-2" %>
<%= counter_f f, :cores, :disabled => !new_host, :label => _('Cores'), :label_size => 'col-md-2', :'data-soft-max' => compute_resource.max_cpu_count %>
<%= byte_size_f f, :memory, :disabled => !new_host, :label => _('Memory'), :label_size => "col-md-2", :'data-soft-max' => compute_resource.max_memory %>

<% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %>
Expand Down
12 changes: 6 additions & 6 deletions test/functional/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ def test_submit_multiple_rebuild_config_pessimistic

assert_response :success
assert_template :partial => '_form'
assert_select '#host_compute_attributes_cpus option[selected]', "5"
assert_select '#host_compute_attributes_cpus'
end

test '#process_hostgroup does not change compute attributes if compute profile selected manually' do
Expand All @@ -1228,29 +1228,29 @@ def test_submit_multiple_rebuild_config_pessimistic

assert_response :success
assert_template :partial => '_form'
assert_select '#host_compute_attributes_cpus option[selected]', "3"
assert_select '#host_compute_attributes_cpus'
end

test '#compute_resource_selected renders compute tab without compute profile' do
xhr :get, :compute_resource_selected, { :host => {:compute_resource_id => compute_resources(:one).id}}, set_session_user
assert_response :success
assert_template :partial => '_compute'
assert_select '#host_compute_attributes_cpus option[selected]', '1'
assert_select '#host_compute_attributes_cpus'
end

test '#compute_resource_selected renders compute tab with explicit compute profile' do
xhr :get, :compute_resource_selected, { :host => {:compute_resource_id => compute_resources(:one).id, :compute_profile_id => compute_profiles(:two).id}}, set_session_user
assert_response :success
assert_template :partial => '_compute'
assert_select '#host_compute_attributes_cpus option[selected]', '4'
assert_select '#host_compute_attributes_cpus'
end

test '#compute_resource_selected renders compute tab with hostgroup\'s compute profile' do
group = FactoryGirl.create(:hostgroup, :compute_profile => compute_profiles(:two))
xhr :get, :compute_resource_selected, { :host => {:compute_resource_id => compute_resources(:one).id, :hostgroup_id => group.id}}, set_session_user
assert_response :success
assert_template :partial => '_compute'
assert_select '#host_compute_attributes_cpus option[selected]', '4'
assert_select '#host_compute_attributes_cpus'
end

test '#compute_resource_selected renders compute tab with hostgroup parent\'s compute profile' do
Expand All @@ -1259,7 +1259,7 @@ def test_submit_multiple_rebuild_config_pessimistic
xhr :get, :compute_resource_selected, { :host => {:compute_resource_id => compute_resources(:one).id, :hostgroup_id => group.id}}, set_session_user
assert_response :success
assert_template :partial => '_compute'
assert_select '#host_compute_attributes_cpus option[selected]', '4'
assert_select '#host_compute_attributes_cpus'
end
end

Expand Down
2 changes: 1 addition & 1 deletion webpack/assets/javascripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ require('./bundle_select2');
require('./bundle_datatables');
window.tfm = {
tools: require('./foreman_tools'),
initByteSpinner: require('./jquery.ui.custom_spinners').initByteSpinner
numFields: require('./jquery.ui.custom_spinners')
};
24 changes: 23 additions & 1 deletion webpack/assets/javascripts/jquery.ui.custom_spinners.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,29 @@ $(function () {
});
});

export function initByteSpinner() {
export function initAll() {
initByte();
initCounter();
}

export function initCounter() {
$('input.counter_spinner').each(function () {
let field = $(this);
let errorMessage = field.closest('.form-group').find('.maximum-limit');

field.limitedSpinner({
softMaximum: field.data('softMax'),
errorTarget: errorMessage,
min: 1
});

field.change(function () {
field.limitedSpinner('validate');
});
});
}

export function initByte() {
$('input.byte_spinner').each(function () {
let field = $(this);
let errorMessage = field.closest('.form-group').find('.maximum-limit');
Expand Down

0 comments on commit 8096335

Please sign in to comment.