Module: ForemanAnsible::AnsibleRolesHelper
- Defined in:
- app/helpers/foreman_ansible/ansible_roles_helper.rb
Overview
Small convenience to list all roles in the UI
Instance Method Summary collapse
- #ansible_proxy_import(hash) ⇒ Object
- #ansible_proxy_links(hash, classes = nil) ⇒ Object
- #ansible_role_select(f, persisted) ⇒ Object
- #import_time(role) ⇒ Object
- #role_attributes_for_roles_switcher(form_object) ⇒ Object
- #roles_attrs(roles) ⇒ Object
Instance Method Details
#ansible_proxy_import(hash) ⇒ Object
28 29 30 31 32 |
# File 'app/helpers/foreman_ansible/ansible_roles_helper.rb', line 28 def ansible_proxy_import(hash) (_('Import'), { :primary => true, :class => 'roles-import' }, ansible_proxy_links(hash)) end |
#ansible_proxy_links(hash, classes = nil) ⇒ Object
6 7 8 9 10 11 12 |
# File 'app/helpers/foreman_ansible/ansible_roles_helper.rb', line 6 def ansible_proxy_links(hash, classes = nil) SmartProxy.with_features('Ansible').map do |proxy| (_('Import from %s') % proxy.name, hash.merge(:proxy => proxy), :class => classes) end.flatten end |
#ansible_role_select(f, persisted) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/foreman_ansible/ansible_roles_helper.rb', line 14 def ansible_role_select(f, persisted) blank_opt = persisted ? {} : { :include_blank => true } select_items = persisted ? [f.object.ansible_role] : AnsibleRole.order(:name) select_f f, :ansible_role_id, select_items, :id, :to_label, blank_opt, :label => _("Ansible Role"), :disabled => persisted, :required => true end |
#import_time(role) ⇒ Object
34 35 36 |
# File 'app/helpers/foreman_ansible/ansible_roles_helper.rb', line 34 def import_time(role) _('%s ago') % time_ago_in_words(role.updated_at) end |
#role_attributes_for_roles_switcher(form_object) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/foreman_ansible/ansible_roles_helper.rb', line 38 def role_attributes_for_roles_switcher(form_object) inherited_role_ids = form_object.inherited_ansible_roles.map(&:id) if form_object.is_a?(Hostgroup) assoc_roles = form_object.hostgroup_ansible_roles assoc_key = :hostgroup_ansible_role_id else assoc_roles = form_object.host_ansible_roles assoc_key = :host_ansible_role_id end own_roles_attrs = model_roles_attrs(assoc_roles.reject { |ar| inherited_role_ids.include?(ar.ansible_role_id) }, assoc_key) roles_attrs(form_object.inherited_ansible_roles) + own_roles_attrs end |
#roles_attrs(roles) ⇒ Object
51 52 53 |
# File 'app/helpers/foreman_ansible/ansible_roles_helper.rb', line 51 def roles_attrs(roles) roles.map { |item| { id: item.id, name: item.name } } end |