Module: Katello::ApplicationHelper
- Includes:
- LayoutHelper
- Defined in:
- app/helpers/katello/application_helper.rb
Instance Method Summary collapse
- #a_link(name, href, html_options) ⇒ Object
- #activation_key_link_helper(key) ⇒ Object
-
#auto_tab_index ⇒ Object
auto_tab_index: this method may be used to simplify adding a tabindex to UI forms.
- #content_view_select_labels(_organization, environment) ⇒ Object
- #current_url(extra_params = {}) ⇒ Object
- #current_user ⇒ Object
-
#editable_class(editable = false) ⇒ Object
used for jeditable fields.
- #env_select_class(curr_env, selected_env, curr_path, selected_path, accessible_envs, library_clickable) ⇒ Object
- #env_select_url(proc, env, next_env, org) ⇒ Object
- #environment_selector(options = {}) ⇒ Object
-
#format_time(date, options = {}) ⇒ Object
formats the date time if the dat is not nil.
- #generate_url(path, options, entity) ⇒ Object
-
#get_product_and_repos(record, content_types) ⇒ Object
Using the record provided, return a hash where the keys are the products associated with the record and the values are arrays listing the repositories associated with the given product.
- #kt_form_for(object, options = {}, &block) ⇒ Object
- #link_to_authorized(*args, &block) ⇒ Object
- #no_content_view ⇒ Object
- #notification_polling_time ⇒ Object
- #one_panel(panel_id, collection, options) ⇒ Object
- #repo_selector(repositories, url, field = :repository_id, record = nil) ⇒ Object
- #select_content_view ⇒ Object
- #selected_content_view(content_view) ⇒ Object
-
#sort(field, options = {}, html_options = {}) ⇒ Object
These 2 methods copied from scoped_search https://github.com/wvanbergen/scoped_search which Katello used to use but no longer uses.
-
#stats_line(stats, _options = {}) ⇒ Object
Headpin inclusion.
- #subscription_limits_helper(sub) ⇒ Object
- #to_calendar_date(date) ⇒ Object
-
#to_value_list(stats) ⇒ Object
Headpin inclusion.
- #two_panel(collection, options) ⇒ Object
Methods included from LayoutHelper
#javascript, #stylesheet, #trunc_with_tooltip
Instance Method Details
#a_link(name, href, html_options) ⇒ Object
215 216 217 218 219 |
# File 'app/helpers/katello/application_helper.rb', line 215 def a_link(name, href, ) = () link = "<a href=\"#{href}\"#{tag_options}>#{name}</a>" return link.respond_to?(:html_safe) ? link.html_safe : link end |
#activation_key_link_helper(key) ⇒ Object
221 222 223 224 225 226 227 228 229 |
# File 'app/helpers/katello/application_helper.rb', line 221 def activation_key_link_helper(key) if ActivationKey.readable? key.organization link_to(key.name, activation_keys_path(key.id, :anchor => "/&list_search=id:#{key.id}&panel=activation_key_#{key.id}")) else key.name end rescue _('Activation key with uuid %s not found') % key.try(:id) end |
#auto_tab_index ⇒ Object
auto_tab_index: this method may be used to simplify adding a tabindex to UI forms.
149 150 151 152 |
# File 'app/helpers/katello/application_helper.rb', line 149 def auto_tab_index @current_index ||= 0 @current_index += 1 end |
#content_view_select_labels(_organization, environment) ⇒ Object
244 245 246 247 248 249 250 251 252 |
# File 'app/helpers/katello/application_helper.rb', line 244 def content_view_select_labels(_organization, environment) if environment labels = ContentView.readable. in_environment(environment).collect { |cv| [cv.name, cv.id] } else labels = [] end labels end |
#current_url(extra_params = {}) ⇒ Object
9 10 11 |
# File 'app/helpers/katello/application_helper.rb', line 9 def current_url(extra_params = {}) url_for params.merge(extra_params) end |
#current_user ⇒ Object
5 6 7 |
# File 'app/helpers/katello/application_helper.rb', line 5 def current_user User.current end |
#editable_class(editable = false) ⇒ Object
used for jeditable fields
166 167 168 169 |
# File 'app/helpers/katello/application_helper.rb', line 166 def editable_class(editable = false) return "editable edit_panel_element multiline" if editable "multiline" end |
#env_select_class(curr_env, selected_env, curr_path, selected_path, accessible_envs, library_clickable) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/helpers/katello/application_helper.rb', line 123 def env_select_class(curr_env, selected_env, curr_path, selected_path, accessible_envs, library_clickable) classes = [] if (library_clickable || !curr_env.library?) && accessible_envs.member?(curr_env) classes << "path_link" else # if library isn't clickable, disable the hover effect classes << "crumb-nohover" end if curr_env.id == selected_env.id if !selected_env.library? classes << "active" else #we only want to highlight the Library along the path that is actually selected classes << "active" if curr_path[1] == selected_path[1] end end classes.join(' ') end |
#env_select_url(proc, env, next_env, org) ⇒ Object
143 144 145 146 |
# File 'app/helpers/katello/application_helper.rb', line 143 def env_select_url(proc, env, next_env, org) return nil if proc.nil? proc.call(:environment => env, :next_environment => next_env, :organization => org) end |
#environment_selector(options = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/katello/application_helper.rb', line 111 def environment_selector( = {}) [:library_clickable] = true if [:library_clickable].nil? # ||= doesn't work if false [:url_proc] = nil if [:url_proc].nil? #explicitly set url_method to nil if not provided # the path widget and entries classes allow the user to override the classes that will be applied to these # elements. by default, they are set assuming the env selector will be displayed on a page (vs w/in a panel) [:path_widget_class] = "" if [:path_widget_class].nil? [:path_entries_class] = "grid_10" if [:path_entries_class].nil? render :partial => "/katello/common/env_select", :locals => end |
#format_time(date, options = {}) ⇒ Object
formats the date time if the dat is not nil
155 156 157 158 |
# File 'app/helpers/katello/application_helper.rb', line 155 def format_time(date, = {}) return I18n.l(date, ) if date "" end |
#generate_url(path, options, entity) ⇒ Object
160 161 162 163 |
# File 'app/helpers/katello/application_helper.rb', line 160 def generate_url(path, , entity) panel_page = .key?(:panel_page) ? ("&panelpage=" + [:panel_page]) : "" path + "?list_search=id%3D#{options[:id]}#panel=#{entity}_#{options[:id]}" + panel_page end |
#get_product_and_repos(record, content_types) ⇒ Object
Using the record provided, return a hash where the keys are the products associated with the record and the values are arrays listing the repositories associated with the given product. For example: => [repo1, repo2]
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'app/helpers/katello/application_helper.rb', line 300 def get_product_and_repos(record, content_types) products_hash = record.resulting_products.inject({}) do |hash, product| if record.repositories.empty? hash[product] = [] else repos = product.repos(current_organization.library).where(:content_type => content_types) repos.each do |repo| hash[product] ||= [] hash[product] << repo end end hash end products_hash end |
#kt_form_for(object, options = {}, &block) ⇒ Object
231 232 233 234 |
# File 'app/helpers/katello/application_helper.rb', line 231 def kt_form_for(object, = {}, &block) [:builder] = KatelloFormBuilder form_for(object, , &block) end |
#link_to_authorized(*args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/katello/application_helper.rb', line 13 def (*args, &block) if block_given? = args.first || {} = args.second (capture(&block), , ) else name = args[0] = args[1] || {} = args[2] if .key? :controller ctrl = [:controller] action = [:action] || 'index' if current_user && current_user.allowed_to?(:controller => ctrl, :action => action) link_to(name, , ) end end end end |
#no_content_view ⇒ Object
240 241 242 |
# File 'app/helpers/katello/application_helper.rb', line 240 def no_content_view _('No Content View') end |
#notification_polling_time ⇒ Object
105 106 107 108 109 |
# File 'app/helpers/katello/application_helper.rb', line 105 def notification_polling_time time = 120 return time.to_i * 1_000 if time return 120_000 end |
#one_panel(panel_id, collection, options) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/katello/application_helper.rb', line 87 def one_panel(panel_id, collection, ) [:accessor] ||= "id" panel_id ||= "panel" render :partial => "katello/common/one_panel", :locals => { :single_select => [:single_select] || false, :hover_text_cb => [:hover_text_cb], :panel_id => panel_id, :title => [:title], :name => [:name], :columns => [:col], :column_titles => [:col_titles], :custom_rows => [:custom_rows], :collection => collection, :accessor => [:accessor] } end |
#repo_selector(repositories, url, field = :repository_id, record = nil) ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'app/helpers/katello/application_helper.rb', line 270 def repo_selector(repositories, url, field = :repository_id, record = nil) products = repositories.map(&:product).uniq.sort_by { |product| product[:name] } repo_ids = repositories.map(&:id) content_tag "select", :id => "repo_select", :name => field, "data-url" => url do html = "" html << content_tag("option", :value => "") { "None" } groups = products.map do |prod| content_tag("optgroup", :label => "#{h(prod.name)}") do = prod.repositories.select { |repo| repo_ids.include?(repo.id) }.map do |repo| selected = record && record.send(field) == repo.id content_tag("option", :value => repo.id, :selected => selected) do h(repo.name) end end .join.html_safe end end (html + groups.join).html_safe end end |
#select_content_view ⇒ Object
236 237 238 |
# File 'app/helpers/katello/application_helper.rb', line 236 def select_content_view _('Select Content View') end |
#selected_content_view(content_view) ⇒ Object
254 255 256 |
# File 'app/helpers/katello/application_helper.rb', line 254 def selected_content_view(content_view) content_view.nil? ? no_content_view : content_view.id end |
#sort(field, options = {}, html_options = {}) ⇒ Object
These 2 methods copied from scoped_search https://github.com/wvanbergen/scoped_search which Katello used to use but no longer uses.
Creates a link that alternates between ascending and descending.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'app/helpers/katello/application_helper.rb', line 183 def sort(field, = {}, = {}) unless [:as] id = field.to_s.downcase == "id" [:as] = id ? field.to_s.upcase : field.to_s.humanize end ascend = "#{field}|ASC" descend = "#{field}|DESC" ascending = params[:order] == ascend new_sort = ascending ? descend : ascend selected = [ascend, descend].include?(params[:order]) if selected css_classes = [:class] ? [:class].split(" ") : [] if ascending [:as] = "▲ #{options[:as]}" css_classes << "ascending" else [:as] = "▼ #{options[:as]}" css_classes << "descending" end [:class] = css_classes.join(" ") end = params.merge(:order => new_sort) [:as] = raw([:as]) if defined?(RailsXss) a_link([:as], html_escape(url_for()), ) end |
#stats_line(stats, _options = {}) ⇒ Object
Headpin inclusion
35 36 37 38 |
# File 'app/helpers/katello/application_helper.rb', line 35 def stats_line(stats, = {}) render :partial => "katello/commonstats_line", :locals => {:stats => stats} end |
#subscription_limits_helper(sub) ⇒ Object
262 263 264 265 266 267 268 |
# File 'app/helpers/katello/application_helper.rb', line 262 def subscription_limits_helper(sub) lim = [] lim << _("Sockets: %s") % sub.sockets if sub.sockets > 0 lim << _("Cores: %s") % sub.cores if sub.cores > 0 lim << _("RAM: %s GB") % sub.ram if sub.ram > 0 lim.join(", ") end |
#to_calendar_date(date) ⇒ Object
258 259 260 |
# File 'app/helpers/katello/application_helper.rb', line 258 def to_calendar_date(date) date.strftime('%m/%d/%Y') end |
#to_value_list(stats) ⇒ Object
Headpin inclusion
41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/katello/application_helper.rb', line 41 def to_value_list(stats) list = "" prepend = "" stats.each do |stat| list += prepend prepend = "," list += stat.value.to_s end list end |
#two_panel(collection, options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/helpers/katello/application_helper.rb', line 52 def two_panel(collection, ) [:accessor] ||= "id" [:left_panel_width] ||= nil [:ajax_load] ||= false enable_create = [:enable_create] enable_create = true if enable_create.nil? enable_sort = [:enable_sort] ? [:enable_sort] : false fail ":titles option not provided" unless [:titles] render :partial => "katello/common/panel", :locals => { :title => [:title], :name => [:name], :create => [:create], :enable_create => enable_create, :create_label => [:create_label] || nil, :enable_sort => enable_sort, :columns => [:col], :titles => [:titles], :custom_rows => [:custom_rows], :collection => collection, :accessor => [:accessor], :url => [:url], :left_panel_width => [:left_panel_width], :ajax_load => [:ajax_load], :ajax_scroll => [:ajax_scroll], :search_env => [:search_env], :initial_action => [:initial_action] || :edit, :initial_state => [:initial_state] || false, :actions => [:actions], :search_class => [:search_class], :disable_create => [:disable_create] || false} end |