Module: Faalis::DashboardHelper

Includes:
ActionView::Helpers::TranslationHelper, Faalis::Dashboard::Helpers::BoxHelpers
Defined in:
app/helpers/faalis/dashboard_helper.rb

Instance Method Summary collapse

Methods included from ActionView::Helpers::TranslationHelper

#t

Methods included from Faalis::Dashboard::Helpers::BoxHelpers

#box, #tabbed_box

Instance Method Details

#action_buttons(buttons) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/faalis/dashboard_helper.rb', line 34

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(:name, '')
    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

#draw_menu(menu) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/faalis/dashboard_helper.rb', line 64

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

#form_label(resource, name) ⇒ Object



7
8
9
10
# File 'app/helpers/faalis/dashboard_helper.rb', line 7

def form_label(resource, name)
  key = "forms.#{@resource.class.name.underscore.to_s.gsub('/', '.')}.#{name}"
  t(key)
end

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

Translate route name to url dynamically



59
60
61
62
# File 'app/helpers/faalis/dashboard_helper.rb', line 59

def get_url(route_name, id = nil, engine = Rails.application)
  return route_name.call if id.nil?
  return route_name.call(id) unless id.nil?
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/faalis/dashboard_helper.rb', line 17

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-remote='#{remote}'>"

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

  button += "<span>#{title}</span>" + '</a>'

  button.html_safe
end

#localized_time(time) ⇒ Object



12
13
14
15
# File 'app/helpers/faalis/dashboard_helper.rb', line 12

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