Sha256: 9ff0c8f523f3c6b99fb4852f8cded7c53e00c7f8a6cc83cfc461160b19eb31e0

Contents?: true

Size: 1.85 KB

Versions: 45

Compression:

Stored size: 1.85 KB

Contents

module ForemanPuppet
  module PuppetclassesAndEnvironmentsHelper
    def class_update_text(pcs, env)
      if pcs.empty?
        _('Empty environment')
      elsif pcs == ['_destroy_']
        _('Deleted environment')
      elsif pcs.delete '_destroy_'
        format(_('Deleted environment %{env} and %{pcs}'), env: env, pcs: pcs.to_sentence)
      elsif pcs == ['_ignored_']
        _('Ignored environment')
      else
        module_puppetclasses(pcs.is_a?(Hash) ? pcs.keys : pcs)
      end
    end

    def import_proxy_select(hash)
      select_action_button(_('Import'), {}, import_proxy_links(hash, true))
    end

    def import_proxy_links(hash, import_env_text = false, classes = nil)
      import_from_text = import_env_text ? _('Import environments from %s') : _('Import classes from %s')
      SmartProxy.with_features('Puppet').map do |proxy|
        display_link_if_authorized(import_from_text % proxy.name, hash.merge(proxy: proxy), { class: classes })
      end.flatten
    end

    private

    def module_puppetclasses(classes)
      mod_classes = {}
      classes.each do |klass|
        if (mod = klass.gsub(/::.*/, ''))
          mod_classes[mod] ||= []
          mod_classes[mod] << klass
        end
      end
      mod_classes.keys.sort.map do |mod_name|
        num = mod_classes[mod_name].size
        num_tag = tag.span(num.to_s, class: 'label label-info')
        tag.a(
          mod_name,
          rel: 'popover',
          data: { content: mod_classes[mod_name].sort.join('<br>').html_safe,
                  'original-title': format(n_('%{name} has %{num_tag} class', '%{name} has %{num_tag} classes', num), name: mod_name, num_tag: num_tag),
                  trigger: 'focus',
                  container: 'body',
                  html: true },
          role: 'button',
          tabindex: '-1'
        )
      end.to_sentence.html_safe
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
foreman_puppet-8.1.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-8.0.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-6.4.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-7.0.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-6.3.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-6.2.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-6.1.1 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-5.1.3 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-6.1.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-6.0.1 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-6.0.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-5.1.2 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-4.1.1 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-5.1.1 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-5.1.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-4.1.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-4.0.4 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-5.0.0 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-4.0.3 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb
foreman_puppet-4.0.2 app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb