Skip to content

Commit

Permalink
Fixes #8217, #8214 - Rearranging override section in smart class para…
Browse files Browse the repository at this point in the history
…meter page and host page
  • Loading branch information
orrabin committed Dec 28, 2014
1 parent e77dd57 commit a2ad747
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/lookup_keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ function keyTypeChange(item) {
var fields = reloadedItem.closest('.fields');
var mergeOverrides = fields.find("[id$='_merge_overrides']");
var avoidDuplicates = fields.find("[id$='_avoid_duplicates']");
var override_merge_div = fields.find("[id$='lookup_key_override_merge']");

changeCheckboxEnabledStatus(mergeOverrides, keyType == 'array' || keyType == 'hash');
changeCheckboxEnabledStatus(avoidDuplicates, keyType == 'array' && $(mergeOverrides).attr('checked') == 'checked');
override_merge_div.toggle(keyType == 'array' || keyType == 'hash');
}

function mergeOverridesChanged(item) {
Expand Down
1 change: 0 additions & 1 deletion app/views/common_parameters/_inherited_parameters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<th class='col-md-3'><%= _("Scope") %></th>
<th class='col-md-2'><%= _("Name") %></th>
<th class='col-md-5'><%= _("Value") %></th>
<th class='col-md-2'><%= _("Use Puppet default") %></th>
<th><%= _('Actions') %></th>
</tr>
</thead>
Expand Down
6 changes: 3 additions & 3 deletions app/views/common_parameters/_puppetclass_parameter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
:placeholder => _("Value") %>
<%= text_field_tag '', (f.object.lookup_key.key_type rescue 'unknown'), :class=> 'hide', :'data-property' => 'type', :disabled => true, :title => _('Parameter type') %>
</td>
<td class="col-md-2">
<td class="col-md-5">
<%= f.check_box :use_puppet_default, :'data-property' => 'use_puppet_default',
:disabled => (not authorized_via_my_scope("host_editing", "edit_params")),
:onchange=>'toggleUsePuppetDefaultValue(this, "value")' %>
<%= popover('', _('Do not send this parameter via the ENC. Puppet will use the value defined in the puppet manifest for this parameter')) %>
<%= popover('', _("Do not send this parameter via the ENC.<br> Puppet will use the value defined in the puppet manifest for this parameter")) %>
</td>
<td class="col-md-1">
<td>
<span class="help-block">
<%= link_to_remove_fields('', f) %>
</span>
Expand Down
18 changes: 17 additions & 1 deletion app/views/common_parameters/_puppetclasses_parameters.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
<div id="puppetclasses_parameters">
<table class="table table-condensed" id="puppetclasses_parameters_table">
<thead>
<tr>
<th class='col-md-3'><%= _("Puppet class") %></th>
<th class='col-md-2'><%= _("Name") %></th>
<th class='col-md-5'><%= _("Value") %></th>
<th class='col-md-3'><%= _("Use Puppet default") %></th>
<th><%= _('Actions') %></th>
</tr>
</thead>
</table>

<%= f.fields_for :lookup_values do |builder| %>
<%= render "common_parameters/puppetclass_parameter", :f => builder %>
<%= render "common_parameters/puppetclass_parameter", :f => builder %>
<% end %>
<%# Hidden button to add an override, used from javascript only %>
<%= authorized_via_my_scope('host_editing', 'create_params') ? link_to_add_fields('+ ' + _('Override a Puppetclass Parameter'), f, :lookup_values, 'common_parameters/puppetclass_parameter', :class => 'hide') : '' %>


</div>
1 change: 0 additions & 1 deletion app/views/hostgroups/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<p/>
<%= render "puppetclasses/classes_parameters", { :obj => @hostgroup } %>
<p/>
<%= render "common_parameters/inherited_parameters" %>
<h6><%= _('Host group parameters') %></h6>
<p/>
<%= render "common_parameters/puppetclasses_parameters", :f => f %>
Expand Down
22 changes: 13 additions & 9 deletions app/views/lookup_keys/_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@
) if is_param%>
<%= param_type_selector(f, :onchange => 'keyTypeChange(this)') %>
<%= checkbox_f(f, :use_puppet_default, :label => _('Use Puppet default'), :size => "col-md-8",
:help_block => _('Do not send this parameter via the ENC. Puppet will use the value defined in the Puppet manifest for this parameter.'),
:onchange=>'toggleUsePuppetDefaultValue(this, "default_value")',
:disabled => (f.object.is_param && !f.object.override)) if is_param%>
<%= textarea_f f, :default_value, :value => f.object.default_value_before_type_cast,:size => "col-md-8",
:disabled => (f.object.is_param && (!f.object.override || f.object.use_puppet_default)),
:rows => :auto, :help_block => _("Value to use when there is no match") %>
<%= checkbox_f(f, :use_puppet_default, :label => _('Use Puppet default'), :size => "col-md-8",
:help_block => _('Do not send this parameter via the ENC. Puppet will use the value defined in the Puppet manifest for this parameter.'),
:onchange=>'toggleUsePuppetDefaultValue(this, "default_value")',
:disabled => (f.object.is_param && !f.object.override)) if is_param%>
<div <%= "id=#{(f.object.key || 'new_lookup_keys').to_s.gsub(' ','_')}_lookup_key_override_value" %> style=<%= "display:none;" if (f.object.is_param && !f.object.override) %>>
<legend><%= _("Optional input validator") %></legend>
<%= checkbox_f(f, :required, :size => "col-md-8", :disabled => !f.object.override,
:help_block => _("If checked, will raise an error if there is no default value and no matcher provide a value.")
) if is_param %>
<%= validator_type_selector f %>
<%= text_f f, :validator_rule, :size => "col-md-8", :disabled => f.object.validator_type.blank? %>
<div <%= "id=#{(f.object.key || 'new_lookup_keys').to_s.gsub(' ','_')}_lookup_key_override_merge" %> style=<%= "display:none;" if (!f.object.merge_overrides) %>>
<legend><%= _("Override merging options") %></legend>
<%= checkbox_f(f, :merge_overrides, :onchange => 'mergeOverridesChanged(this)',
:disabled => !f.object.supports_merge?, :size => "col-md-8",
:help_block => _("Should the matchers continue to look for matches after first find (only array/hash type). Note: merging overrides ignores all matchers that use Puppet default")) %>
<%= checkbox_f(f, :avoid_duplicates, :disabled => (!f.object.supports_uniq? || !f.object.merge_overrides), :size => "col-md-8",
:help_block => _("Should the matched result avoid duplicate values (only array type).")) %>
</div>

<legend><%= _("Override value for specific hosts") %></legend>
<%= checkbox_f(f, :merge_overrides, :onchange => 'mergeOverridesChanged(this)',
:disabled => !f.object.supports_merge?, :size => "col-md-8",
:help_block => _("Should the matchers continue to look for matches after first find (only array/hash type). Note: merging overrides ignores all matchers that use Puppet default")) %>
<%= checkbox_f(f, :avoid_duplicates, :disabled => (!f.object.supports_uniq? || !f.object.merge_overrides), :size => "col-md-8",
:help_block => _("Should the matched result avoid duplicate values (only array type).")) %>
<%= textarea_f f, :path, :rows => :auto, :label => _("Order"), :size => "col-md-8", :value => f.object.path,
:help_block => popover(_("The order in which values are resolved"),
_("The order in which matchers keys are processed, first match wins.<br> You may use multiple attributes as a matcher key, for example, an order of <code>host group, environment</code> would expect a matcher such as <code>hostgroup = \"web servers\", environment = production</code>"), :title => _("The order in which values are resolved")).html_safe
Expand All @@ -44,6 +47,7 @@
<%= new_child_fields_template(f, :lookup_values, {:partial => "lookup_keys/value", :form_builder_attrs => {:is_param => is_param}}) %>
<%= f.fields_for :lookup_values do |lookup_values| %>
<%= render 'lookup_keys/value', :f => lookup_values, :is_param => is_param %>
<hr>
<% end %>
<%= add_child_link '+ ' + _("Add Matcher-Value"), :lookup_values, { :title => _('add a new matcher-value pair')} %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/lookup_keys/_value.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
:help_block => popover(_("Explain matchers"), _("Matcher is a combination of an attribute and its value, if they match, the value below would be provided.<br> You may use any attribute foreman knows about, such as facts etc for example: <code> domain = example.com </code> or <code> is_virtual = true</code>"),
:title => _("Matcher"))
%>
<%= checkbox_f(f, :use_puppet_default, :label => _('Use Puppet default'),
:help_inline => popover(_("Explain use Puppet default"), _('Do not send this parameter via the ENC. Puppet will use the value defined in the Puppet manifest for this parameter.')),
:onchange=>'toggleUsePuppetDefaultValue(this, "value")') if is_param %>
<%= checkbox_f(f, :use_puppet_default, :label => _('Use Puppet default'), :size => "col-md-8",
:help_block => popover(_("Explain use Puppet default"), _('Do not send this parameter via the ENC.<br>Puppet will use the value defined in the Puppet manifest for this parameter.')),
:onchange=>'toggleUsePuppetDefaultValue(this, "value")') if is_param %>
<%= textarea_f f, :value, :rows => :auto, :value => f.object.value_before_type_cast, :size => "col-md-8",
:disabled => f.object.use_puppet_default,
:help_inline => remove_child_link(icon_text("remove"), f, {:title => _('remove value')}) %>
</div>
</div>

0 comments on commit a2ad747

Please sign in to comment.