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.
-
#sort_joins ⇒ Object
a collection of associations to do left join when the list is sorted by this column.
- #sort_joins=(value) ⇒ Object
- #sortable? ⇒ Boolean
- #subform_includes=(value) ⇒ Object
-
#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
225 226 227 228 |
# File 'lib/active_scaffold/data_structures/column.rb', line 225 def <=>(other) order_weight = weight <=> other.weight order_weight.nonzero? ? order_weight : name.to_s <=> other.name.to_s end |
#associated_number? ⇒ Boolean
210 211 212 |
# File 'lib/active_scaffold/data_structures/column.rb', line 210 def associated_number? @associated_number end |
#attributes=(opts) ⇒ Object
380 381 382 383 384 |
# File 'lib/active_scaffold/data_structures/column.rb', line 380 def attributes=(opts) opts.each do |setting, value| send :"#{setting}=", value end end |
#cache_count? ⇒ Boolean
376 377 378 |
# File 'lib/active_scaffold/data_structures/column.rb', line 376 def cache_count? includes.blank? && associated_number? && association&.cache_count? end |
#calculation? ⇒ Boolean
get whether to run a calculation on this column
124 125 126 |
# File 'lib/active_scaffold/data_structures/column.rb', line 124 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
118 119 120 121 |
# File 'lib/active_scaffold/data_structures/column.rb', line 118 def clear_link @link = nil @autolink = false end |
#convert_to_native? ⇒ Boolean
230 231 232 |
# File 'lib/active_scaffold/data_structures/column.rb', line 230 def convert_to_native? number? && [:format] && form_ui != :number end |
#description(record = nil, scope = nil) ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'lib/active_scaffold/data_structures/column.rb', line 152 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
257 258 259 260 |
# File 'lib/active_scaffold/data_structures/column.rb', line 257 def form_ui=(value) check_valid_action_ui_params(value) @form_ui, @form_ui_options = *value end |
#includes=(value) ⇒ Object
304 305 306 307 308 309 310 |
# File 'lib/active_scaffold/data_structures/column.rb', line 304 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
112 113 114 115 |
# File 'lib/active_scaffold/data_structures/column.rb', line 112 def inplace_edit=(value) clear_link if value @inplace_edit = value end |
#label(record = nil, scope = nil) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/active_scaffold/data_structures/column.rb', line 140 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
355 356 357 358 359 360 361 362 |
# File 'lib/active_scaffold/data_structures/column.rb', line 355 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
268 269 270 |
# File 'lib/active_scaffold/data_structures/column.rb', line 268 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
263 264 265 266 |
# File 'lib/active_scaffold/data_structures/column.rb', line 263 def list_ui=(value) check_valid_action_ui_params(value) @list_ui, @list_ui_options = *value end |
#list_ui_options ⇒ Object
272 273 274 |
# File 'lib/active_scaffold/data_structures/column.rb', line 272 def @list_ui ? @list_ui_options : end |
#number? ⇒ Boolean
221 222 223 |
# File 'lib/active_scaffold/data_structures/column.rb', line 221 def number? @number end |
#number_to_native(value) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/active_scaffold/data_structures/column.rb', line 234 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
136 137 138 |
# File 'lib/active_scaffold/data_structures/column.rb', line 136 def placeholder @placeholder || I18n.t(name, scope: [:activerecord, :placeholder, active_record_class.to_s.underscore.to_sym], default: '') end |
#required?(action = nil) ⇒ Boolean
128 129 130 131 132 133 134 |
# File 'lib/active_scaffold/data_structures/column.rb', line 128 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
321 322 323 |
# File 'lib/active_scaffold/data_structures/column.rb', line 321 def search_joins @search_joins || includes end |
#search_joins=(value) ⇒ Object
325 326 327 328 329 330 331 |
# File 'lib/active_scaffold/data_structures/column.rb', line 325 def search_joins=(value) @search_joins = case value when Array then value else [value] # automatically convert to an array end end |
#search_sql ⇒ Object
346 347 348 349 |
# File 'lib/active_scaffold/data_structures/column.rb', line 346 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
337 338 339 340 341 342 343 344 |
# File 'lib/active_scaffold/data_structures/column.rb', line 337 def search_sql=(value) @search_sql = if value value == true || value.is_a?(Proc) ? value : Array(value) else value end end |
#search_ui ⇒ Object
296 297 298 |
# File 'lib/active_scaffold/data_structures/column.rb', line 296 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
291 292 293 294 |
# File 'lib/active_scaffold/data_structures/column.rb', line 291 def search_ui=(value) check_valid_action_ui_params(value) @search_ui, @search_ui_options = *value end |
#search_ui_options ⇒ Object
300 301 302 |
# File 'lib/active_scaffold/data_structures/column.rb', line 300 def @search_ui ? @search_ui_options : end |
#searchable? ⇒ Boolean
351 352 353 |
# File 'lib/active_scaffold/data_structures/column.rb', line 351 def searchable? search_sql.present? || (logical_search.present? && ActiveScaffold::Finder.logical_comparators.present?) end |
#set_link(action, options = {}) ⇒ Object
associate an action_link with this column
365 366 367 368 369 370 371 372 373 374 |
# File 'lib/active_scaffold/data_structures/column.rb', line 365 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
214 215 216 217 218 219 |
# File 'lib/active_scaffold/data_structures/column.rb', line 214 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
282 283 284 |
# File 'lib/active_scaffold/data_structures/column.rb', line 282 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
277 278 279 280 |
# File 'lib/active_scaffold/data_structures/column.rb', line 277 def show_ui=(value) check_valid_action_ui_params(value) @show_ui, @show_ui_options = *value end |
#show_ui_options ⇒ Object
286 287 288 |
# File 'lib/active_scaffold/data_structures/column.rb', line 286 def @show_ui ? @show_ui_options : end |
#sort ⇒ Object
183 184 185 186 |
# File 'lib/active_scaffold/data_structures/column.rb', line 183 def sort initialize_sort if @sort == true @sort if @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!
174 175 176 177 178 179 180 181 |
# File 'lib/active_scaffold/data_structures/column.rb', line 174 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.
193 194 195 |
# File 'lib/active_scaffold/data_structures/column.rb', line 193 def sort_by() self.sort = end |
#sort_joins ⇒ Object
a collection of associations to do left join when the list is sorted by this column
198 199 200 |
# File 'lib/active_scaffold/data_structures/column.rb', line 198 def sort_joins @sort_joins || includes end |
#sort_joins=(value) ⇒ Object
202 203 204 205 206 207 208 |
# File 'lib/active_scaffold/data_structures/column.rb', line 202 def sort_joins=(value) @sort_joins = case value when Array then value else [value] # automatically convert to an array end end |
#sortable? ⇒ Boolean
188 189 190 |
# File 'lib/active_scaffold/data_structures/column.rb', line 188 def sortable? sort != false && !sort.nil? end |
#subform_includes=(value) ⇒ Object
312 313 314 315 316 317 318 |
# File 'lib/active_scaffold/data_structures/column.rb', line 312 def subform_includes=(value) @subform_includes = case value when Array, TrueClass then value else value ? [value] : value # not convert nil to [nil] end end |
#update_columns=(column_names) ⇒ Object
update dependent columns after value change in form
update_columns = :name
update_columns = [:name, :age]
165 166 167 |
# File 'lib/active_scaffold/data_structures/column.rb', line 165 def update_columns=(column_names) @update_columns = column_names.is_a?(Array) ? column_names : [column_names] end |