Module: RailsDb::TablesHelper

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

Instance Method Summary collapse

Instance Method Details

#column_is_checked?(table_name, column_name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'app/helpers/rails_db/tables_helper.rb', line 39

def column_is_checked?(table_name, column_name)
  if cookies["Table: #{table_name}"].present?
    !cookies["Table: #{table_name}"].split(',').include?(column_name)
  else
    true
  end
end

#delete_row_path(table, record) ⇒ Object



26
27
28
29
30
31
32
# File 'app/helpers/rails_db/tables_helper.rb', line 26

def delete_row_path(table, record)
  options = params.permit!
  table_destroy_path(table,
    pk_id: record[table.primary_key],
    page: options[:page],
    q: options[:q])
end

#display_style_column(table_name, column_name) ⇒ Object



47
48
49
# File 'app/helpers/rails_db/tables_helper.rb', line 47

def display_style_column(table_name, column_name)
  column_is_checked?(table_name, column_name) ? 'display' : 'display:none'
end

#format_value(column, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/rails_db/tables_helper.rb', line 4

def format_value(column, value)
  return value
  # TODO here
  return nil unless value
  case column.type
  when :datetime
    I18n.l(DateTime.parse(value), format: :long)
  when :date
    I18n.l(Date.parse(value), format: :long)
  else
    value
  end
end

#search_form_classObject



51
52
53
54
55
56
57
# File 'app/helpers/rails_db/tables_helper.rb', line 51

def search_form_class
  hash = params.permit!.to_hash.fetch('q', {})
  keys = hash.keys
  return 'hide' if keys.empty?
  return 'hide' if keys == ['s']
  nil
end

#select_top_from_table(table) ⇒ Object



22
23
24
# File 'app/helpers/rails_db/tables_helper.rb', line 22

def select_top_from_table(table)
  link_to raw("#{fa_icon('database')} SQL Query"), rails_db.sql_path(sql: "select * from #{table} limit 10")
end

#table_pagination_pathObject



34
35
36
37
# File 'app/helpers/rails_db/tables_helper.rb', line 34

def table_pagination_path
  params.delete(:pk_id)
  params_to_hash params.merge({action: :data})
end

#titleize_column(column, title = nil) ⇒ Object



18
19
20
# File 'app/helpers/rails_db/tables_helper.rb', line 18

def titleize_column(column, title = nil)
  column
end