Module: ActiveScaffold::DataStructures::Column::ProxyableMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveScaffold::DataStructures::Column, ProxyColumn
- Defined in:
- lib/active_scaffold/data_structures/column.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #associated_number? ⇒ Boolean
- #attributes=(opts) ⇒ Object
- #cache_count? ⇒ Boolean
-
#calculation? ⇒ Boolean
get whether to run a calculation on this column.
-
#clear_link ⇒ Object
this should not only delete any existing link but also prevent column links from being automatically added by later routines.
- #convert_to_native? ⇒ Boolean
- #description(record = nil, scope = nil) ⇒ Object
-
#form_ui=(value) ⇒ Object
value must be a Symbol, or an Array of form_ui and options hash which will be used with form_ui only.
- #includes=(value) ⇒ Object
- #inplace_edit=(value) ⇒ Object
- #label(record = nil, scope = nil) ⇒ Object
- #link ⇒ Object
- #list_ui ⇒ Object
-
#list_ui=(value) ⇒ Object
value must be a Symbol, or an Array of list_ui and options hash which will be used with list_ui only.
- #list_ui_options ⇒ Object
- #number? ⇒ Boolean
- #number_to_native(value) ⇒ Object
- #placeholder ⇒ Object
- #required?(action = nil) ⇒ Boolean
-
#search_joins ⇒ Object
a collection of associations to do left join when this column is included on search.
- #search_joins=(value) ⇒ Object
- #search_sql ⇒ Object
-
#search_sql=(value) ⇒ Object
describes how to search on a column search = true default, uses intelligent search sql search = “CONCAT(a, b)” define your own sql for searching.
- #search_ui ⇒ Object
-
#search_ui=(value) ⇒ Object
value must be a Symbol, or an Array of search_ui and options hash which will be used with search_ui only.
- #search_ui_options ⇒ Object
- #searchable? ⇒ Boolean
-
#set_link(action, options = {}) ⇒ Object
associate an action_link with this column.
- #show_blank_record?(associated) ⇒ Boolean
- #show_ui ⇒ Object
-
#show_ui=(value) ⇒ Object
value must be a Symbol, or an Array of show_ui and options hash which will be used with show_ui only.
- #show_ui_options ⇒ Object
- #sort ⇒ Object
-
#sort=(value) ⇒ Object
sorting on a column can be configured four ways: sort = true default, uses intelligent sorting sql default sort = false sometimes sorting doesn’t make sense sort = “” define your own sql for sorting.
-
#sort_by(options) ⇒ Object
a configuration helper for the self.sort property.
- #sortable? ⇒ Boolean
-
#update_columns=(column_names) ⇒ Object
update dependent columns after value change in form update_columns = :name update_columns = [:name, :age].
Instance Method Details
#<=>(other) ⇒ Object
199 200 201 202 |
# File 'lib/active_scaffold/data_structures/column.rb', line 199 def <=>(other) order_weight = weight <=> other.weight order_weight.nonzero? ? order_weight : name.to_s <=> other.name.to_s end |
#associated_number? ⇒ Boolean
184 185 186 |
# File 'lib/active_scaffold/data_structures/column.rb', line 184 def associated_number? @associated_number end |
#attributes=(opts) ⇒ Object
346 347 348 349 350 |
# File 'lib/active_scaffold/data_structures/column.rb', line 346 def attributes=(opts) opts.each do |setting, value| send :"#{setting}=", value end end |
#cache_count? ⇒ Boolean
342 343 344 |
# File 'lib/active_scaffold/data_structures/column.rb', line 342 def cache_count? includes.blank? && associated_number? && association&.cache_count? end |
#calculation? ⇒ Boolean
get whether to run a calculation on this column
111 112 113 |
# File 'lib/active_scaffold/data_structures/column.rb', line 111 def calculation? !(calculate == false || calculate.nil?) end |
#clear_link ⇒ Object
this should not only delete any existing link but also prevent column links from being automatically added by later routines
105 106 107 108 |
# File 'lib/active_scaffold/data_structures/column.rb', line 105 def clear_link @link = nil @autolink = false end |
#convert_to_native? ⇒ Boolean
204 205 206 |
# File 'lib/active_scaffold/data_structures/column.rb', line 204 def convert_to_native? number? && [:format] && form_ui != :number end |
#description(record = nil, scope = nil) ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/active_scaffold/data_structures/column.rb', line 139 def description(record = nil, scope = nil) if @description.respond_to?(:call) @description.call(record, self, scope) elsif @description @description else I18n.t name, scope: [:activerecord, :description, active_record_class.to_s.underscore.to_sym], default: '' end end |
#form_ui=(value) ⇒ Object
value must be a Symbol, or an Array of form_ui and options hash which will be used with form_ui only
231 232 233 234 |
# File 'lib/active_scaffold/data_structures/column.rb', line 231 def form_ui=(value) check_valid_action_ui_params(value) @form_ui, @form_ui_options = *value end |
#includes=(value) ⇒ Object
278 279 280 281 282 283 284 |
# File 'lib/active_scaffold/data_structures/column.rb', line 278 def includes=(value) @includes = case value when Array then value else value ? [value] : value # not convert nil to [nil] end end |
#inplace_edit=(value) ⇒ Object
99 100 101 102 |
# File 'lib/active_scaffold/data_structures/column.rb', line 99 def inplace_edit=(value) clear_link if value @inplace_edit = value end |
#label(record = nil, scope = nil) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/active_scaffold/data_structures/column.rb', line 127 def label(record = nil, scope = nil) label = if @label.respond_to?(:call) # sometimes label is called without a record in context (ie, from table # headers). In this case fall back to the default instead of the Proc. @label.call(record, self, scope) if record elsif @label as_(@label) end label || active_record_class.human_attribute_name(name.to_s) end |
#link ⇒ Object
321 322 323 324 325 326 327 328 |
# File 'lib/active_scaffold/data_structures/column.rb', line 321 def link if frozen? && @link.is_a?(Proc) ActiveScaffold::Registry.cache(:column_links, cache_key) { @link.call(self).deep_freeze! } else @link = @link.call(self) if @link.is_a? Proc @link end end |
#list_ui ⇒ Object
242 243 244 |
# File 'lib/active_scaffold/data_structures/column.rb', line 242 def list_ui @list_ui || form_ui end |
#list_ui=(value) ⇒ Object
value must be a Symbol, or an Array of list_ui and options hash which will be used with list_ui only
237 238 239 240 |
# File 'lib/active_scaffold/data_structures/column.rb', line 237 def list_ui=(value) check_valid_action_ui_params(value) @list_ui, @list_ui_options = *value end |
#list_ui_options ⇒ Object
246 247 248 |
# File 'lib/active_scaffold/data_structures/column.rb', line 246 def @list_ui ? @list_ui_options : end |
#number? ⇒ Boolean
195 196 197 |
# File 'lib/active_scaffold/data_structures/column.rb', line 195 def number? @number end |
#number_to_native(value) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/active_scaffold/data_structures/column.rb', line 208 def number_to_native(value) return value if value.blank? || !value.is_a?(String) native = '.' # native ruby separator format = {separator: '', delimiter: ''}.merge! I18n.t('number.format', default: {}) specific = case [:format] when :currency I18n.t('number.currency.format', default: nil) when :size I18n.t('number.human.format', default: nil) when :percentage I18n.t('number.percentage.format', default: nil) end format.merge! specific unless specific.nil? if format[:separator].blank? || (value.exclude?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/)) value else value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native) end end |
#placeholder ⇒ Object
123 124 125 |
# File 'lib/active_scaffold/data_structures/column.rb', line 123 def placeholder @placeholder || I18n.t(name, scope: [:activerecord, :placeholder, active_record_class.to_s.underscore.to_sym], default: '') end |
#required?(action = nil) ⇒ Boolean
115 116 117 118 119 120 121 |
# File 'lib/active_scaffold/data_structures/column.rb', line 115 def required?(action = nil) if action && @required @required == true || @required.include?(action) else @required end end |
#search_joins ⇒ Object
a collection of associations to do left join when this column is included on search
287 288 289 |
# File 'lib/active_scaffold/data_structures/column.rb', line 287 def search_joins @search_joins || includes end |
#search_joins=(value) ⇒ Object
291 292 293 294 295 296 297 |
# File 'lib/active_scaffold/data_structures/column.rb', line 291 def search_joins=(value) @search_joins = case value when Array then value else [value] # automatically convert to an array end end |
#search_sql ⇒ Object
312 313 314 315 |
# File 'lib/active_scaffold/data_structures/column.rb', line 312 def search_sql initialize_search_sql if @search_sql == true @search_sql end |
#search_sql=(value) ⇒ Object
describes how to search on a column
search = true default, uses intelligent search sql
search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold.
search = [:a, :b] searches in both fields
303 304 305 306 307 308 309 310 |
# File 'lib/active_scaffold/data_structures/column.rb', line 303 def search_sql=(value) @search_sql = if value value == true || value.is_a?(Proc) ? value : Array(value) else value end end |
#search_ui ⇒ Object
270 271 272 |
# File 'lib/active_scaffold/data_structures/column.rb', line 270 def search_ui @search_ui || form_ui || (:select if association && !association.polymorphic?) end |
#search_ui=(value) ⇒ Object
value must be a Symbol, or an Array of search_ui and options hash which will be used with search_ui only
265 266 267 268 |
# File 'lib/active_scaffold/data_structures/column.rb', line 265 def search_ui=(value) check_valid_action_ui_params(value) @search_ui, @search_ui_options = *value end |
#search_ui_options ⇒ Object
274 275 276 |
# File 'lib/active_scaffold/data_structures/column.rb', line 274 def @search_ui ? @search_ui_options : end |
#searchable? ⇒ Boolean
317 318 319 |
# File 'lib/active_scaffold/data_structures/column.rb', line 317 def searchable? search_sql.present? end |
#set_link(action, options = {}) ⇒ Object
associate an action_link with this column
331 332 333 334 335 336 337 338 339 340 |
# File 'lib/active_scaffold/data_structures/column.rb', line 331 def set_link(action, = {}) if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc) @link = action else [:label] ||= label [:position] ||= :after unless .key?(:position) [:type] ||= :member @link = ActiveScaffold::DataStructures::ActionLink.new(action, ) end end |
#show_blank_record?(associated) ⇒ Boolean
188 189 190 191 192 193 |
# File 'lib/active_scaffold/data_structures/column.rb', line 188 def show_blank_record?(associated) return false unless @show_blank_record return false unless association.klass.(crud_type: :create) && !association.readonly? association.collection? || (association.singular? && associated.blank?) end |
#show_ui ⇒ Object
256 257 258 |
# File 'lib/active_scaffold/data_structures/column.rb', line 256 def show_ui @show_ui || list_ui end |
#show_ui=(value) ⇒ Object
value must be a Symbol, or an Array of show_ui and options hash which will be used with show_ui only
251 252 253 254 |
# File 'lib/active_scaffold/data_structures/column.rb', line 251 def show_ui=(value) check_valid_action_ui_params(value) @show_ui, @show_ui_options = *value end |
#show_ui_options ⇒ Object
260 261 262 |
# File 'lib/active_scaffold/data_structures/column.rb', line 260 def @show_ui ? @show_ui_options : end |
#sort ⇒ Object
170 171 172 173 |
# File 'lib/active_scaffold/data_structures/column.rb', line 170 def sort initialize_sort if @sort == true @sort end |
#sort=(value) ⇒ Object
sorting on a column can be configured four ways:
sort = true default, uses intelligent sorting sql default
sort = false sometimes sorting doesn't make sense
sort = {sql: ""} define your own sql for sorting. this should be result in a sortable value in SQL. ActiveScaffold will handle the ascending/descending.
sort = {method: ""} define ruby-side code for sorting. this is SLOW with large recordsets!
161 162 163 164 165 166 167 168 |
# File 'lib/active_scaffold/data_structures/column.rb', line 161 def sort=(value) if value.is_a? Hash value.assert_valid_keys(:sql, :method) @sort = value else @sort = value ? true : false # force true or false end end |
#sort_by(options) ⇒ Object
a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax.
180 181 182 |
# File 'lib/active_scaffold/data_structures/column.rb', line 180 def sort_by() self.sort = end |
#sortable? ⇒ Boolean
175 176 177 |
# File 'lib/active_scaffold/data_structures/column.rb', line 175 def sortable? sort != false && !sort.nil? end |
#update_columns=(column_names) ⇒ Object
update dependent columns after value change in form
update_columns = :name
update_columns = [:name, :age]
152 153 154 |
# File 'lib/active_scaffold/data_structures/column.rb', line 152 def update_columns=(column_names) @update_columns = Array(column_names) end |