Module: CoreTableHelper

Defined in:
app/helpers/core_table_helper.rb

Overview

Methods useful for building out tables

Instance Method Summary collapse

Instance Method Details

#dynamic_custom_modal(anchor, label, title, view_endpoint, _options = {}) ⇒ Object



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
# File 'app/helpers/core_table_helper.rb', line 55

def dynamic_custom_modal(anchor, label, title, view_endpoint, _options = {})
  datum = { view_url: view_endpoint }
  (:span) do
    concat((:a, href: "##{anchor}", class: 'modal-trigger') do
      concat(materialize_icon(label))
    end)
    concat((:div, id: anchor, class: 'modal modal-fixed-footer', data: datum) do
      concat((:div, class: 'modal-content') do
        concat((:h2, class: 'center') do
          concat((:span, title))
        end)
        concat((:div, class: 'center-align') do
          concat((:div, class: 'progress red lighten-4') do
            tag(:div, class: 'indeterminate red')
          end)
        end)
      end)
      concat((:div, class: 'modal-footer') do
        concat((:a, href: '#', class: 'modal-action modal-close btn btn-flat') do
          concat('Close')
        end)
      end)
    end)
  end
end

#table_header_actions_tag(name: :actions, classes: %w[actions], priority: 2, visible: true) ⇒ Object

Format the table header

Parameters:

  • name (defaults to: :actions)
    • Name of the header, either the text or a localized value

  • classes (defaults to: %w[actions])
    • Additional classes to apply to the header

  • priority (defaults to: 2)
    • Priority to show the column when the screen gets small, the lower value is higher priority

  • visible (defaults to: true)
    • This column should be visible



14
15
16
17
18
# File 'app/helpers/core_table_helper.rb', line 14

def table_header_actions_tag(name: :actions, classes: %w[actions], priority: 2, visible: true)
  return unless visible

  table_header_tag(name, classes: classes, priority: priority, visible: visible)
end

#table_header_tag(name, classes: [], priority: 1, visible: true) ⇒ Object

Format the table header

Parameters:

  • name
    • Name of the header, either the text or a localized value

  • classes (defaults to: [])
    • Additional classes to apply to the header

  • priority (defaults to: 1)
    • Priority to show the column when the screen gets small, the lower value is higher priority

  • visible (defaults to: true)
    • This column should be visible



27
28
29
30
31
32
33
# File 'app/helpers/core_table_helper.rb', line 27

def table_header_tag(name, classes: [], priority: 1, visible: true)
  return unless visible

  options = { data: { priority: priority } }
  options[:class] = classes if classes.present?
  (:th, options) { table_header_text(name) }
end

#table_header_text(name) ⇒ Object

First look to see if a localized string was passed in, then try to look in table.headers.… lastly return the titleized string

Parameters:

  • name
    • Name of the header, either the text or a localized value



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/core_table_helper.rb', line 41

def table_header_text(name)
  if I18n.exists?(name)
    t(name)
  elsif I18n.exists?("table.headers.#{name}")
    t("table.headers.#{name}")
  elsif I18n.exists?("core_table.headers.#{name}")
    t("core_table.headers.#{name}")
  else
    name.to_s.titleize
  end
rescue StandardError
  name
end