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



59
60
61
62
63
# File 'app/helpers/katello/application_helper.rb', line 59

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

#current_userObject



5
6
7
# File 'app/helpers/katello/application_helper.rb', line 5

def current_user
  User.current
end

#format_time(date, options = {}) ⇒ Object

formats the date time if the dat is not nil



10
11
12
13
# File 'app/helpers/katello/application_helper.rb', line 10

def format_time(date, options = {})
  return I18n.l(date, options) if date
  ""
end

#no_content_viewObject



69
70
71
# File 'app/helpers/katello/application_helper.rb', line 69

def no_content_view
  _('No Content View')
end

#select_content_viewObject



65
66
67
# File 'app/helpers/katello/application_helper.rb', line 65

def select_content_view
  _('Select Content View')
end

#selected_content_view(content_view) ⇒ Object



73
74
75
# File 'app/helpers/katello/application_helper.rb', line 73

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/katello/application_helper.rb', line 27

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