Module: Katello::ContentOptionsHelper
- Included in:
- HostsAndHostgroupsHelper
- Defined in:
- app/helpers/katello/content_options_helper.rb
Instance Method Summary collapse
-
#blank_or_inherit_cvenv(f) ⇒ Object
f is Rails convention for form objects.
-
#blank_or_inherit_with_id(f, attr) ⇒ Object
rubocop:disable Naming/MethodParameterName.
- #build_cvenv_option_tags(cvenvs, current_cvenv) ⇒ Object
-
#build_cvenv_options_for_orgs(orgs, current_cvenv, content_source) ⇒ Object
rubocop:enable Rails/OutputSafety.
-
#content_options(host, selected_id, object_type, options = {}) ⇒ Object
rubocop:disable Rails/OutputSafety Generic method to provide a list of options in the UI.
- #content_source_options(host, options = {}) ⇒ Object
-
#content_view_environment_options(hostgroup, options = {}) ⇒ Object
rubocop:disable Rails/OutputSafety Generate
-
#content_views_for_host(host, options) ⇒ Object
rubocop:disable Rails/OutputSafety.
- #fetch_cvenvs_for_org(org, current_cvenv, content_source) ⇒ Object
- #filter_cvenvs_by_content_source(cvenvs, content_source, org) ⇒ Object
-
#lifecycle_environment_options(host, options = {}) ⇒ Object
rubocop:enable Rails/OutputSafety.
-
#view_to_options(view_options, selected_val, include_blank = false) ⇒ Object
rubocop:disable Rails/OutputSafety.
Instance Method Details
#blank_or_inherit_cvenv(f) ⇒ Object
f is Rails convention for form objects
161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/helpers/katello/content_options_helper.rb', line 161 def blank_or_inherit_cvenv(f) # f is Rails convention for form objects return true unless f.object.respond_to?(:parent_id) && f.object.parent_id parent_cvenv = f.object.parent&.content_view_environment inherited_value = parent_cvenv.try(:id) || '' if parent_cvenv %(<option data-id="#{inherited_value}" value="">#{h(_('Inherit parent (%s)') % parent_cvenv.label)}</option>) else %(<option value="">#{_('Inherit parent')}</option>) end end |
#blank_or_inherit_with_id(f, attr) ⇒ Object
rubocop:disable Naming/MethodParameterName
155 156 157 158 159 |
# File 'app/helpers/katello/content_options_helper.rb', line 155 def blank_or_inherit_with_id(f, attr) # f is Rails convention for form objects return true unless f.object.respond_to?(:parent_id) && f.object.parent_id inherited_value = f.object.send(attr).try(:id) || '' %(<option data-id="#{inherited_value}" value="">#{blank_or_inherit_f(f, attr)}</option>) end |
#build_cvenv_option_tags(cvenvs, current_cvenv) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'app/helpers/katello/content_options_helper.rb', line 104 def (cvenvs, current_cvenv) = cvenvs.map do |cvenv| selected = current_cvenv&.id == cvenv.id ? 'selected' : '' label = cvenv.label %(<option value="#{cvenv.id}" #{selected}>#{h(label)}</option>) end .join end |
#build_cvenv_options_for_orgs(orgs, current_cvenv, content_source) ⇒ Object
rubocop:enable Rails/OutputSafety
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/katello/content_options_helper.rb', line 71 def (orgs, current_cvenv, content_source) orgs.map do |org| cvenvs = fetch_cvenvs_for_org(org, current_cvenv, content_source) = (cvenvs, current_cvenv) if orgs.count > 1 %(<optgroup label="#{h(org.name)}">#{}</optgroup>) else end end end |
#content_options(host, selected_id, object_type, options = {}) ⇒ Object
rubocop:disable Rails/OutputSafety Generic method to provide a list of options in the UI
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/katello/content_options_helper.rb', line 5 def (host, selected_id, object_type, = {}) include_blank = .fetch(:include_blank, nil) include_blank = '<option></option>' if include_blank == true #check for true specifically orgs = relevant_organizations(host) = [] orgs.each do |org| = "" accessible_content_objects = case object_type when :lifecycle_environment accessible_lifecycle_environments(org, host) when :content_source accessible_content_proxies(host) end accessible_content_objects.each do |content_object| selected = selected_id == content_object.id ? 'selected' : '' << %(<option value="#{content_object.id}" class="kt-env" #{selected}>#{h(content_object.name)}</option>) end if orgs.count > 1 << %(<optgroup label="#{h(org.name)}">#{}</optgroup>) else << end end = .join .insert(0, include_blank) if include_blank .html_safe # User content is safely escaped with h() end |
#content_source_options(host, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/helpers/katello/content_options_helper.rb', line 45 def (host, = {}) ( host, fetch_content_source(host, ).try(:id), :content_source, ) end |
#content_view_environment_options(hostgroup, options = {}) ⇒ Object
rubocop:disable Rails/OutputSafety Generate
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/katello/content_options_helper.rb', line 56 def (hostgroup, = {}) include_blank = .fetch(:include_blank, nil) include_blank = '<option></option>' if include_blank == true orgs = relevant_organizations(hostgroup) current_cvenv = fetch_content_view_environment(hostgroup, ) content_source = fetch_content_source(hostgroup, ) = (orgs, current_cvenv, content_source) = .join .insert(0, include_blank) if include_blank .html_safe # User content is safely escaped with h() end |
#content_views_for_host(host, options) ⇒ Object
rubocop:disable Rails/OutputSafety
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/helpers/katello/content_options_helper.rb', line 114 def content_views_for_host(host, ) include_blank = .fetch(:include_blank, nil) if include_blank == true #check for true specifically include_blank = '<option></option>' end lifecycle_environment = fetch_lifecycle_environment(host, ) content_view = fetch_content_view(host, ) views = [] if lifecycle_environment views = Katello::ContentView.in_environment(lifecycle_environment).ignore_generated.readable.order(:name) views |= [content_view] if content_view.present? && content_view.in_environment?(lifecycle_environment) elsif content_view views = [content_view] end = views.map do |view| selected = content_view.try(:id) == view.id ? 'selected' : '' %(<option #{selected} value="#{view.id}">#{h(view.name)}</option>) end = .join .insert(0, include_blank) if include_blank .html_safe # User content is safely escaped with h() end |
#fetch_cvenvs_for_org(org, current_cvenv, content_source) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/katello/content_options_helper.rb', line 84 def fetch_cvenvs_for_org(org, current_cvenv, content_source) cvenvs = Katello::ContentViewEnvironment.joins(:content_view, :environment) .where("#{Katello::ContentView.table_name}.organization_id" => org.id) .order("#{Katello::KTEnvironment.table_name}.name", "#{Katello::ContentView.table_name}.name") .to_a cvenvs = filter_cvenvs_by_content_source(cvenvs, content_source, org) if content_source.present? cvenvs |= [current_cvenv] if current_cvenv.present? && current_cvenv.content_view.organization_id == org.id cvenvs end |
#filter_cvenvs_by_content_source(cvenvs, content_source, org) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'app/helpers/katello/content_options_helper.rb', line 95 def filter_cvenvs_by_content_source(cvenvs, content_source, org) return cvenvs if content_source.pulp_primary? available_env_ids = content_source.lifecycle_environments.where(organization_id: org.id).pluck(:id) return cvenvs unless available_env_ids.any? cvenvs.select { |cvenv| available_env_ids.include?(cvenv.environment_id) } end |
#lifecycle_environment_options(host, options = {}) ⇒ Object
rubocop:enable Rails/OutputSafety
36 37 38 39 40 41 42 43 |
# File 'app/helpers/katello/content_options_helper.rb', line 36 def (host, = {}) ( host, fetch_lifecycle_environment(host, ).try(:id), :lifecycle_environment, ) end |
#view_to_options(view_options, selected_val, include_blank = false) ⇒ Object
rubocop:disable Rails/OutputSafety
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/helpers/katello/content_options_helper.rb', line 140 def (, selected_val, include_blank = false) if include_blank == true #check for true specifically include_blank = '<option></option>' end views = .map do |view| selected = selected_val == view.id ? 'selected' : '' %(<option #{selected} value="#{view.id}">#{h(view.name)}</option>) end views = views.join views.insert(0, include_blank) if include_blank views.html_safe # User content is safely escaped with h() end |