Class: ActiveList::Definition::Table
- Inherits:
-
Object
- Object
- ActiveList::Definition::Table
- Defined in:
- lib/active_list/definition/table.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
-
#action(name, options = {}) ⇒ Object
Add a new method in Table which permit to define action columns.
-
#check_box(name, options = {}) ⇒ Object
Add a new method in Table which permit to define check_box columns.
- #children ⇒ Object
-
#column(name, options = {}) ⇒ Object
Add a new method in Table which permit to define data columns.
- #data_columns ⇒ Object
- #exportable_columns ⇒ Object
- #hidden_columns ⇒ Object
-
#initialize(name, model = nil, options = {}) ⇒ Table
constructor
A new instance of Table.
- #load_default_columns ⇒ Object
- #model_columns ⇒ Object
- #new_column_id ⇒ Object
- #paginate? ⇒ Boolean
-
#reflections ⇒ Object
Compute includes Hash.
- #sortable_columns ⇒ Object
- #status(*args) ⇒ Object
-
#table_columns ⇒ Object
Retrieves all columns in database.
-
#text_field(name, options = {}) ⇒ Object
Add a new method in Table which permit to define text_field columns.
Constructor Details
#initialize(name, model = nil, options = {}) ⇒ Table
Returns a new instance of Table.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/active_list/definition/table.rb', line 8 def initialize(name, model = nil, = {}) @name = name @model = model || name.to_s.classify.constantize @options = @paginate = !(@options[:pagination]==:none || @options[:paginate].is_a?(FalseClass)) @options[:renderer] ||= :simple_renderer @options[:per_page] = 20 if @options[:per_page].to_i <= 0 @options[:page] = 1 if @options[:page].to_i <= 0 @columns = [] @id = ActiveList.new_uid end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
6 7 8 |
# File 'lib/active_list/definition/table.rb', line 6 def columns @columns end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/active_list/definition/table.rb', line 6 def id @id end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/active_list/definition/table.rb', line 6 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/active_list/definition/table.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/active_list/definition/table.rb', line 6 def @options end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/active_list/definition/table.rb', line 6 def parameters @parameters end |
Instance Method Details
#action(name, options = {}) ⇒ Object
Add a new method in Table which permit to define action columns
86 87 88 |
# File 'lib/active_list/definition/table.rb', line 86 def action(name, = {}) add :action, name, end |
#check_box(name, options = {}) ⇒ Object
Add a new method in Table which permit to define check_box columns
81 82 83 |
# File 'lib/active_list/definition/table.rb', line 81 def check_box(name, = {}) add :check_box, name, end |
#children ⇒ Object
39 40 41 |
# File 'lib/active_list/definition/table.rb', line 39 def children @columns.map(&:child) end |
#column(name, options = {}) ⇒ Object
Add a new method in Table which permit to define data columns
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/active_list/definition/table.rb', line 102 def column(name, = {}) if @model.reflect_on_association(name) [:through] ||= name add :association, name, elsif @model.reflect_on_association([:through]) [:label_method] ||= name add :association, name, else add :attribute, name, end end |
#data_columns ⇒ Object
53 54 55 |
# File 'lib/active_list/definition/table.rb', line 53 def data_columns @columns.select{|c| c.is_a? DataColumn} end |
#exportable_columns ⇒ Object
35 36 37 |
# File 'lib/active_list/definition/table.rb', line 35 def exportable_columns @columns.select{|c| c.exportable?} end |
#hidden_columns ⇒ Object
57 58 59 |
# File 'lib/active_list/definition/table.rb', line 57 def hidden_columns self.data_columns.select(&:hidden?) end |
#load_default_columns ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/active_list/definition/table.rb', line 121 def load_default_columns for column in self.model_columns reflections = @model.reflections.values.select{|r| r.macro == :belongs_to and r.foreign_key.to_s == column.name.to_s} if reflections.size == 1 reflection = reflections.first columns = reflection.class_name.constantize.columns.collect{ |c| c.name.to_s } self.column([:label, :name, :code, :number].detect{ |l| columns.include?(l.to_s) }, :through => reflection.name, :url => true) else self.column(column.name) end end return true end |
#model_columns ⇒ Object
27 28 29 |
# File 'lib/active_list/definition/table.rb', line 27 def model_columns @model.columns_hash.values end |
#new_column_id ⇒ Object
20 21 22 23 24 25 |
# File 'lib/active_list/definition/table.rb', line 20 def new_column_id @current_column_id ||= 0 id = @current_column_id.to_s(36).to_sym @current_column_id += 1 return id end |
#paginate? ⇒ Boolean
43 44 45 |
# File 'lib/active_list/definition/table.rb', line 43 def paginate? @paginate end |
#reflections ⇒ Object
Compute includes Hash
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/active_list/definition/table.rb', line 62 def reflections hash = [] for column in self.columns if column.respond_to?(:reflection) unless hash.detect{|r| r.name == column.reflection.name } hash << column.reflection end end end return hash end |
#sortable_columns ⇒ Object
31 32 33 |
# File 'lib/active_list/definition/table.rb', line 31 def sortable_columns @columns.select{|c| c.sortable?} end |
#status(*args) ⇒ Object
114 115 116 117 118 |
# File 'lib/active_list/definition/table.rb', line 114 def status(*args) = args. name = args.shift || :status add :status, name, end |
#table_columns ⇒ Object
Retrieves all columns in database
48 49 50 51 |
# File 'lib/active_list/definition/table.rb', line 48 def table_columns cols = self.model_columns.map(&:name) @columns.select{|c| c.is_a? DataColumn and cols.include? c.name.to_s} end |
#text_field(name, options = {}) ⇒ Object
Add a new method in Table which permit to define text_field columns
76 77 78 |
# File 'lib/active_list/definition/table.rb', line 76 def text_field(name, = {}) add :text_field, name, end |