Module: Katello::ApplicationHelper

Includes:
LayoutHelper
Defined in:
app/helpers/katello/application_helper.rb

Instance Method Summary collapse

Methods included from LayoutHelper

#javascript, #stylesheet, #trunc_with_tooltip

Instance Method Details



215
216
217
218
219
# File 'app/helpers/katello/application_helper.rb', line 215

def a_link(name, href, html_options)
  tag_options = tag_options(html_options)
  link = "<a href=\"#{href}\"#{tag_options}>#{name}</a>"
  return link.respond_to?(:html_safe) ? link.html_safe : link
end


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_indexObject

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_userObject



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(options = {})
  options[:library_clickable] = true if options[:library_clickable].nil? # ||= doesn't work if false
  options[:url_proc] = nil if options[: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)
  options[:path_widget_class] = "" if options[:path_widget_class].nil?
  options[:path_entries_class] = "grid_10" if options[:path_entries_class].nil?

  render :partial => "/katello/common/env_select", :locals => options
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, options = {})
  return I18n.l(date, options) 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, options, entity)
  panel_page = options.key?(:panel_page) ? ("&panelpage=" + options[: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, options = {}, &block)
  options[:builder] = KatelloFormBuilder
  form_for(object, options, &block)
end


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 link_to_authorized(*args, &block)
  if block_given?
    options      = args.first || {}
    html_options = args.second
    link_to_authorized(capture(&block), options, html_options)
  else
    name         = args[0]
    options      = args[1] || {}
    html_options = args[2]

    if options.key? :controller
      ctrl   = options[:controller]
      action = options[:action] || 'index'

      if current_user && current_user.allowed_to?(:controller => ctrl, :action => action)
        link_to(name, options, html_options)
      end
    end
  end
end

#no_content_viewObject



240
241
242
# File 'app/helpers/katello/application_helper.rb', line 240

def no_content_view
  _('No Content View')
end

#notification_polling_timeObject



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, options)
  options[:accessor] ||= "id"
  panel_id ||= "panel"

  render :partial => "katello/common/one_panel",
         :locals => {
           :single_select => options[:single_select] || false,
           :hover_text_cb => options[:hover_text_cb],
           :panel_id => panel_id,
           :title => options[:title],
           :name => options[:name],
           :columns => options[:col],
           :column_titles => options[:col_titles],
           :custom_rows => options[:custom_rows],
           :collection => collection,
           :accessor => options[: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)

   "select", :id => "repo_select", :name => field, "data-url" => url do
    html = ""
    html << ("option", :value => "") { "None" }

    groups = products.map do |prod|
      ("optgroup", :label => "#{h(prod.name)}") do
        options = prod.repositories.select { |repo| repo_ids.include?(repo.id) }.map do |repo|
          selected = record && record.send(field) == repo.id

          ("option", :value => repo.id, :selected => selected) do
            h(repo.name)
          end
        end
        options.join.html_safe
      end
    end

    (html + groups.join).html_safe
  end
end

#select_content_viewObject



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.

Examples:

sort @search, :by => :login
sort @search, :by => :created_at, :as => "Created"

Parameters:

  • options (Hash) (defaults to: {})

    This helper accepts the following options:

Options Hash (options):

  • :by (String)

    the name of the named scope. This helper will prepend this value with “ascend_by_” and “descend_by_”

  • :as (String)

    the text used in the link, defaults to whatever is passed to :by



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, options = {}, html_options = {})
  unless options[:as]
    id           = field.to_s.downcase == "id"
    options[: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 = html_options[:class] ? html_options[:class].split(" ") : []
    if ascending
      options[:as] = "&#9650;&nbsp;#{options[:as]}"
      css_classes << "ascending"
    else
      options[:as] = "&#9660;&nbsp;#{options[:as]}"
      css_classes << "descending"
    end
    html_options[:class] = css_classes.join(" ")
  end

  url_options = params.merge(:order => new_sort)

  options[:as] = raw(options[:as]) if defined?(RailsXss)

  a_link(options[:as], html_escape(url_for(url_options)), html_options)
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, _options = {})
  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, options)
  options[:accessor] ||= "id"
  options[:left_panel_width] ||= nil
  options[:ajax_load] ||= false
  enable_create = options[:enable_create]
  enable_create = true if enable_create.nil?
  enable_sort = options[:enable_sort] ? options[:enable_sort] : false

  fail ":titles option not provided" unless options[:titles]

  render :partial => "katello/common/panel",
         :locals => {
           :title => options[:title],
           :name => options[:name],
           :create => options[:create],
           :enable_create => enable_create,
           :create_label => options[:create_label] || nil,
           :enable_sort => enable_sort,
           :columns => options[:col],
           :titles => options[:titles],
           :custom_rows => options[:custom_rows],
           :collection => collection,
           :accessor => options[:accessor],
           :url => options[:url],
           :left_panel_width => options[:left_panel_width],
           :ajax_load => options[:ajax_load],
           :ajax_scroll => options[:ajax_scroll],
           :search_env => options[:search_env],
           :initial_action => options[:initial_action] || :edit,
           :initial_state => options[:initial_state] || false,
           :actions => options[:actions],
           :search_class => options[:search_class],
           :disable_create => options[:disable_create] || false}
end