Module: Faalis::DashboardHelper

Defined in:
app/helpers/faalis/dashboard_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) action_buttons(buttons)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/faalis/dashboard_helper.rb', line 28

def action_buttons(buttons)
  buttons_html = ''

  buttons.each do |button|
    href    = button.fetch(:href, '#')
    klass   = button.fetch(:class, 'btn-success')
    remote  = button.fetch(:remote, false).to_s
    icons   = button.fetch(:icon_class, "")
    label   = button.fetch(:label, '')
    model   = button.fetch(:model, nil)
    action  = button.fetch(:policy, nil)

    with_policy(model, action) do
      buttons_html += "<a class='action-button btn pull-right " +
                      "#{klass}' href='#{href}' data-remote='#{remote}'"+
                      "data-disable-with='#{spinner} #{label}'>\n" +
                      "<i class='fa fa-#{icons}'></i>" +
                      label +
                      '</a>'
    end
  end
  buttons_html.html_safe
end

- (Object) draw_menu(menu)



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
# File 'app/helpers/faalis/dashboard_helper.rb', line 58

def draw_menu(menu)
  klass = menu.class || ''
  klass += 'treeview' if sidebar.children?
  href  = menu.url || '#'

  result = "<li class='#{klass}'> \
        <a href='#{href}'> \
          <i class='#{menu.icon}'></i>
          <span>#{menu.title}</span>
          <span class='label label-primary pull-right'>4</span>
        </a>"

  if sidebar.respond_to? :children
    result += "<ul class='treeview-menu slide'>"
    sidebar.children.each do |submenu|
      result += "<li>\
                  <a href='#{submenu.url}'>
                    <i class='#{submenu.icon}'></i>
                    #{submenu.title}
                  </a>"
      result += draw_menu submenu
      result += '</li>'
    end
    result += '</ul>'
  end
end

- (Object) get_url(route_name, id = nil, engine = Rails.application)

Translate route name to url dynamically



53
54
55
56
# File 'app/helpers/faalis/dashboard_helper.rb', line 53

def get_url(route_name, id = nil, engine = Rails.application)
  return engine.routes.url_helpers.send(route_name, id.to_s) unless id.nil?
  engine.routes.url_helpers.send(route_name)
end


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/faalis/dashboard_helper.rb', line 9

def link_button(title, **options)
  classes    = "btn pull-right btn-sm #{options.fetch(:classes, '')}"
  icon_class = options[:icon_class]
  href       = options.fetch(:href, '#')
  remote     = options.fetch(:remote, false).to_s

  button = "<a class='#{classes}' href='#{href}'" +
           "data-disable-with='#{title} . . .' data-remote='#{remote}'" +
           "data-disable-class='disabled'>"

  if icon_class
    button += "<i class='fa fa-#{icon_class}'></i>"
  end

  button += title + '</a>'

  button.html_safe
end

- (Object) localized_time(time)



4
5
6
7
# File 'app/helpers/faalis/dashboard_helper.rb', line 4

def localized_time(time)
  # Fixme: Setup and use Rails l10n
  time.strftime("%Y-%m-%d %H:%M")
end

- (Object) spinner (private)



87
88
89
# File 'app/helpers/faalis/dashboard_helper.rb', line 87

def spinner
  h "<i class='fa fa-cog fa-lg fa-spin'></i>"
end

- (Object) with_policy(model, action, &block) (private)



91
92
93
94
95
96
97
98
99
# File 'app/helpers/faalis/dashboard_helper.rb', line 91

def with_policy(model, action, &block)
  if model && action
    if policy(model).send("#{action}?")
      block.call
    end
  else
    block.call
  end
end