Class: Datagrid::Columns::Column
- Inherits:
-
Object
- Object
- Datagrid::Columns::Column
- Defined in:
- lib/datagrid/columns/column.rb
Defined Under Namespace
Classes: ResponseFormat
Instance Attribute Summary collapse
-
#data_block ⇒ Object
Returns the value of attribute data_block.
-
#grid_class ⇒ Object
Returns the value of attribute grid_class.
-
#html_block ⇒ Object
Returns the value of attribute html_block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #append_preload(relation) ⇒ Object
- #data? ⇒ Boolean
- #data_value(model, grid) ⇒ Object
- #driver ⇒ Object
- #enabled?(grid) ⇒ Boolean
- #generic_value(model, grid) ⇒ Object
- #header ⇒ Object
- #html? ⇒ Boolean
- #html_class ⇒ Object
- #html_value(context, asset, grid) ⇒ Object
-
#initialize(grid_class, name, query, options = {}, &block) ⇒ Column
constructor
A new instance of Column.
- #inspect ⇒ Object
- #label ⇒ Object
- #mandatory? ⇒ Boolean
- #mandatory_explicitly_set? ⇒ Boolean
- #order ⇒ Object
- #order_by_value(model, grid) ⇒ Object
- #order_by_value? ⇒ Boolean
- #order_desc ⇒ Object
- #preload ⇒ Object
- #supports_order? ⇒ Boolean
- #tag_options ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(grid_class, name, query, options = {}, &block) ⇒ Column
Returns a new instance of Column.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/datagrid/columns/column.rb', line 38 def initialize(grid_class, name, query, = {}, &block) self.grid_class = grid_class self.name = name.to_sym self. = if [:class] Datagrid::Utils.warn_once( "column[class] option is deprecated. Use {tag_options: {class: ...}} instead.", ) self.[:tag_options] = { **self..fetch(:tag_options, {}), class: [:class], } end if [:html] == true self.html_block = block else self.data_block = block self.html_block = [:html] if [:html].is_a? Proc end self.query = query end |
Instance Attribute Details
#data_block ⇒ Object
Returns the value of attribute data_block.
36 37 38 |
# File 'lib/datagrid/columns/column.rb', line 36 def data_block @data_block end |
#grid_class ⇒ Object
Returns the value of attribute grid_class.
36 37 38 |
# File 'lib/datagrid/columns/column.rb', line 36 def grid_class @grid_class end |
#html_block ⇒ Object
Returns the value of attribute html_block.
36 37 38 |
# File 'lib/datagrid/columns/column.rb', line 36 def html_block @html_block end |
#name ⇒ Object
Returns the value of attribute name.
36 37 38 |
# File 'lib/datagrid/columns/column.rb', line 36 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
36 37 38 |
# File 'lib/datagrid/columns/column.rb', line 36 def @options end |
#query ⇒ Object
Returns the value of attribute query.
36 37 38 |
# File 'lib/datagrid/columns/column.rb', line 36 def query @query end |
Instance Method Details
#append_preload(relation) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/datagrid/columns/column.rb', line 155 def append_preload(relation) return relation unless preload if preload.respond_to?(:call) return relation unless preload if preload.arity == 1 preload.call(relation) else relation.instance_exec(&preload) end else driver.default_preload(relation, preload) end end |
#data? ⇒ Boolean
112 113 114 |
# File 'lib/datagrid/columns/column.rb', line 112 def data? data_block != nil end |
#data_value(model, grid) ⇒ Object
61 62 63 64 |
# File 'lib/datagrid/columns/column.rb', line 61 def data_value(model, grid) # backward compatibility method grid.data_value(name, model) end |
#driver ⇒ Object
181 182 183 |
# File 'lib/datagrid/columns/column.rb', line 181 def driver grid_class.driver end |
#enabled?(grid) ⇒ Boolean
135 136 137 |
# File 'lib/datagrid/columns/column.rb', line 135 def enabled?(grid) ::Datagrid::Utils.process_availability(grid, [:if], [:unless]) end |
#generic_value(model, grid) ⇒ Object
151 152 153 |
# File 'lib/datagrid/columns/column.rb', line 151 def generic_value(model, grid) grid.generic_value(self, model) end |
#header ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/datagrid/columns/column.rb', line 70 def header if (header = [:header]) Datagrid::Utils.callable(header) else Datagrid::Utils.translate_from_namespace(:columns, grid_class, name) end end |
#html? ⇒ Boolean
108 109 110 |
# File 'lib/datagrid/columns/column.rb', line 108 def html? [:html] != false end |
#html_class ⇒ Object
124 125 126 127 128 129 |
# File 'lib/datagrid/columns/column.rb', line 124 def html_class Datagrid::Utils.warn_once( "Column#html_class is deprecated. Use Column#tag_options instead.", ) [:class] end |
#html_value(context, asset, grid) ⇒ Object
147 148 149 |
# File 'lib/datagrid/columns/column.rb', line 147 def html_value(context, asset, grid) grid.html_value(name, context, asset) end |
#inspect ⇒ Object
139 140 141 |
# File 'lib/datagrid/columns/column.rb', line 139 def inspect "#<#{self.class} #{grid_class}##{name} #{.inspect}>" end |
#label ⇒ Object
66 67 68 |
# File 'lib/datagrid/columns/column.rb', line 66 def label [:label] end |
#mandatory? ⇒ Boolean
116 117 118 |
# File 'lib/datagrid/columns/column.rb', line 116 def mandatory? !![:mandatory] end |
#mandatory_explicitly_set? ⇒ Boolean
131 132 133 |
# File 'lib/datagrid/columns/column.rb', line 131 def mandatory_explicitly_set? .key?(:mandatory) end |
#order ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/datagrid/columns/column.rb', line 78 def order if .key?(:order) && [:order] != true [:order] else driver.default_order(grid_class.scope, name) end end |
#order_by_value(model, grid) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/datagrid/columns/column.rb', line 90 def order_by_value(model, grid) if [:order_by_value] == true grid.data_value(self, model) else Datagrid::Utils.apply_args(model, grid, &[:order_by_value]) end end |
#order_by_value? ⇒ Boolean
98 99 100 |
# File 'lib/datagrid/columns/column.rb', line 98 def order_by_value? !![:order_by_value] end |
#order_desc ⇒ Object
102 103 104 105 106 |
# File 'lib/datagrid/columns/column.rb', line 102 def order_desc return nil unless order [:order_desc] end |
#preload ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/datagrid/columns/column.rb', line 171 def preload preload = [:preload] if preload == true && driver.can_preload?(grid_class.scope, name) name else preload end end |
#supports_order? ⇒ Boolean
86 87 88 |
# File 'lib/datagrid/columns/column.rb', line 86 def supports_order? order || order_by_value? end |
#tag_options ⇒ Object
120 121 122 |
# File 'lib/datagrid/columns/column.rb', line 120 def [:tag_options] || {} end |
#to_s ⇒ Object
143 144 145 |
# File 'lib/datagrid/columns/column.rb', line 143 def to_s header end |