Module: RailsDb::RailsDbDataTableHelper

Defined in:
app/helpers/rails_db/rails_db_data_table_helper.rb

Constant Summary collapse

STYLES =

TODO check styles

{
  default: {
    table: 'table',
    tr: 'table_tr',
    th: 'table_th',
    td: 'table_td',
    thead: 'table_thead',
    tfoot: 'table_tfoot'
  },
  bootstrap: {
    table: 'table table-bordered table-striped table-hover',
    tr: 'table_tr',
    th: 'table_th',
    td: 'table_td',
    thead: 'table_thead',
    tfoot: 'table_tfoot'
  },
  foundation: {
    table: 'table',
    tr: 'table_tr',
    th: 'table_th',
    td: 'table_td',
    thead: 'table_thead',
    tfoot: 'table_tfoot'
  }
}

Instance Method Summary collapse

Instance Method Details

#rails_db_data_table(table_name, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/rails_db/rails_db_data_table_helper.rb', line 31

def rails_db_data_table(table_name, options = {})
  options.reverse_merge!(
    style: :default,
    header: true,
    footer: false,
    columns: [],
    limit: nil,
    order_by: nil,
    order: :asc
  )
  table = RailsDb::Table.new(table_name)
    .limit(options[:limit])
    .order_by(options[:order_by])
    .select(options[:columns])
    .order(options[:order])

  render '/rails_db/shared/data_table', table: table,
                                        header: options[:header],
                                        footer: options[:footer],
                                        style:  options[:style]
end

#rails_db_data_table_sql(sql, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/rails_db/rails_db_data_table_helper.rb', line 53

def rails_db_data_table_sql(sql, options = {})
  options.reverse_merge!(
    style: :default,
    header: true,
    footer: false,
  )
  sql        = "#{sql}".strip
  sql_query  = RailsDb::SqlQuery.new(sql, false).execute

  render '/rails_db/shared/sql_result', sql_query: sql_query,
                                        header: options[:header],
                                        footer: options[:footer],
                                        style:  options[:style]
end

#rails_db_table_style(tag, style) ⇒ Object



68
69
70
71
# File 'app/helpers/rails_db/rails_db_data_table_helper.rb', line 68

def rails_db_table_style(tag, style)
  style = STYLES[style] || STYLES[:default]
  style[tag.to_sym]
end