Module: ForemanPuppet::PuppetclassLookupKeysHelper
- Defined in:
- app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb
Instance Method Summary collapse
-
#diagnostic_popover(lookup_key, matcher, inherited_value, warnings) ⇒ Object
rubocop:enable Rails/HelperInstanceVariable.
- #hidden_puppet_lookup_value_fields(lookup_key, lookup_value, disabled) ⇒ Object
- #lookup_key_description(lookup_key, matcher, inherited_value) ⇒ Object
- #lookup_key_warnings(required, has_value) ⇒ Object
- #lookup_value_matcher(obj, lookup_key) ⇒ Object
-
#lookup_value_name_prefix(lookup_key_id) ⇒ Object
Input tags used to override lookup keys need a ‘name’ HTML attribute to tell Rails which lookup_value they belong to.
- #omit_puppet_lookup_check_box(lookup_key, lookup_value, disabled) ⇒ Object
-
#overridable_puppet_lookup_keys(klass, obj) ⇒ Object
—— Host(group) Form Helpers —–.
- #parameters_receiver ⇒ Object
- #puppet_lookup_key_with_diagnostic(obj, lookup_key, lookup_value) ⇒ Object
-
#puppet_lookup_value_hash_host_cache(host) ⇒ Object
rubocop:disable Rails/HelperInstanceVariable.
- #puppet_override_toggle(overridden) ⇒ Object
- #puppetclass_lookup_keys_breadcrumbs ⇒ Object
Instance Method Details
#diagnostic_popover(lookup_key, matcher, inherited_value, warnings) ⇒ Object
rubocop:enable Rails/HelperInstanceVariable
89 90 91 92 93 94 95 96 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 89 def diagnostic_popover(lookup_key, matcher, inherited_value, warnings) description = lookup_key_description(lookup_key, matcher, inherited_value) popover('', description.prepend(warnings[:text]), data: { placement: 'top' }, title: _('Original value info'), icon: 'info-circle', kind: 'fa') end |
#hidden_puppet_lookup_value_fields(lookup_key, lookup_value, disabled) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 15 def hidden_puppet_lookup_value_fields(lookup_key, lookup_value, disabled) return unless can_edit_params? value_prefix = lookup_value_name_prefix(lookup_key.id) hidden_field(value_prefix, :lookup_key_id, value: lookup_key.id, disabled: disabled, class: 'send_to_remove') + hidden_field(value_prefix, :id, value: lookup_value.id, disabled: disabled, class: 'send_to_remove') + hidden_field(value_prefix, :_destroy, value: false, disabled: disabled, class: 'send_to_remove destroy') end |
#lookup_key_description(lookup_key, matcher, inherited_value) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 98 def lookup_key_description(lookup_key, matcher, inherited_value) format(_("<b>Description:</b> %{desc}<br/> <b>Type:</b> %{type}<br/> <b>Matcher:</b> %{matcher}<br/> <b>Inherited value:</b> %{inherited_value}"), desc: html_escape(lookup_key.description), type: lookup_key.key_type, matcher: html_escape(matcher), inherited_value: html_escape(inherited_value)) end |
#lookup_key_warnings(required, has_value) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 109 def lookup_key_warnings(required, has_value) return { text: '', icon: 'info' } if has_value if required { text: _('Required parameter without value.<br/><b>Please override!</b><br/>'), icon: 'error-circle-o' } else { text: _('Optional parameter without value.<br/><i>Still managed by Foreman, the value will be empty.</i><br/>'), icon: 'warning-triangle-o' } end end |
#lookup_value_matcher(obj, lookup_key) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 68 def lookup_value_matcher(obj, lookup_key) if parameters_receiver == 'host' value = puppet_lookup_value_hash_host_cache(obj)[lookup_key.id] value_for_key = value.try(:[], lookup_key.key) if value_for_key.present? [value_for_key[:value], "#{value_for_key[:element]} (#{value_for_key[:element_name]})"] else [lookup_key.default_value, _('Default value')] end else # hostgroup obj.inherited_lookup_value(lookup_key) end end |
#lookup_value_name_prefix(lookup_key_id) ⇒ Object
Input tags used to override lookup keys need a ‘name’ HTML attribute to tell Rails which lookup_value they belong to. This method returns the name attribute for any combination of lookup_key and host/hostgroup. Other objects that may receive parameters too will need to override this method in their respective helpers.
126 127 128 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 126 def lookup_value_name_prefix(lookup_key_id) "#{parameters_receiver}[lookup_values_attributes][#{lookup_key_id}]" end |
#omit_puppet_lookup_check_box(lookup_key, lookup_value, disabled) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 26 def omit_puppet_lookup_check_box(lookup_key, lookup_value, disabled) check_box(lookup_value_name_prefix(lookup_key.id), :omit, value: lookup_value.id, disabled: disabled || !can_edit_params?, onchange: "toggleOmitValue(this, 'value')", hidden: disabled, title: _('Omit from classification output'), checked: lookup_value.omit) end |
#overridable_puppet_lookup_keys(klass, obj) ⇒ Object
—— Host(group) Form Helpers —–
11 12 13 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 11 def overridable_puppet_lookup_keys(klass, obj) klass.class_params.override.where(environment_classes: { environment_id: obj.environment }) end |
#parameters_receiver ⇒ Object
130 131 132 133 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 130 def parameters_receiver return 'host' if params.key?(:host) || params[:controller] == 'hosts' 'hostgroup' end |
#puppet_lookup_key_with_diagnostic(obj, lookup_key, lookup_value) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 48 def puppet_lookup_key_with_diagnostic(obj, lookup_key, lookup_value) value, matcher = lookup_value_matcher(obj, lookup_key) inherited_value = LookupKey.format_value_before_type_cast(value, lookup_key.key_type) effective_value = lookup_value.lookup_key_id.nil? ? inherited_value.to_s : lookup_value.value_before_type_cast.to_s warnings = lookup_key_warnings(lookup_key.required, effective_value.present?) popover_value = lookup_key.hidden_value? ? lookup_key.hidden_value : inherited_value parameter_value_content( "#{parameters_receiver}_lookup_values_attributes_#{lookup_key.id}_value", effective_value, popover: diagnostic_popover(lookup_key, matcher, popover_value, warnings), name: "#{lookup_value_name_prefix(lookup_key.id)}[value]", disabled: !lookup_key.overridden?(obj) || lookup_value.omit || !can_edit_params?, inherited_value: inherited_value, lookup_key: lookup_key, hidden_value?: lookup_key.hidden_value?, lookup_key_type: lookup_key.key_type ) end |
#puppet_lookup_value_hash_host_cache(host) ⇒ Object
rubocop:disable Rails/HelperInstanceVariable
83 84 85 86 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 83 def puppet_lookup_value_hash_host_cache(host) @puppet_lookup_value_hash_host_cache ||= {} @puppet_lookup_value_hash_host_cache[host.id] ||= ForemanPuppet::HostInfoProviders::PuppetInfo.new(host).inherited_puppetclass_parameters end |
#puppet_override_toggle(overridden) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 36 def puppet_override_toggle(overridden) return unless can_edit_params? link_to_function(icon_text('pencil-square-o', '', kind: 'fa'), 'tfm.puppetEnc.hostForm.overridePuppetclassParam(this)', title: _('Override this value'), 'data-tag': 'override', class: "btn btn-default btn-md btn-override #{'hide' if overridden}") + link_to_function(icon_text('times', '', kind: 'fa'), 'tfm.puppetEnc.hostForm.overridePuppetclassParam(this)', title: _('Remove this override'), 'data-tag': 'remove', class: "btn btn-default btn-md btn-override #{'hide' unless overridden}") end |
#puppetclass_lookup_keys_breadcrumbs ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb', line 3 def (resource_url: api_smart_class_parameters_path, name_field: 'parameter', switcher_item_url: '/puppetclass_lookup_keys/:id-:name/edit') end |