module ActiveScaffold::DataStructures::Column::ProxyableMethods
Attributes
Whether to enable add_existing for this column
what string to use to join records from plural associations
define a calculation for the column. anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do.
Whether this column set is collapsed by default in contexts where collapsing is supported
this will be /joined/ to the :name for the td’s class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names.
a textual description of the column and its contents. this will be displayed with any associated form input widget, so you may want to consider adding a content example.
disable the form while the request to refresh other columns is sent
text to display when the column is empty, defaults nil, so list.empty_field_text is used
supported options:
* for association columns * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records
add a custom attr_accessor that can contain a Proc (or boolean or symbol) that will be called when the column renders, such that we can dynamically hide or show the column with an element that can be replaced by update_columns
, but won’t affect the form submission. The value can be set in the scaffold controller as follows to dynamically hide the column based on a Proc’s output: config.columns.hide_form_column_if = Proc.new { |record, column, scope| record.vehicle_type == ‘tractor’ } OR to always hide the column: config.columns.hide_form_column_if = true OR to call a method on the record to determine whether to hide the column: config.columns.hide_form_column_if = :hide_tractor_fields?
a collection of associations to pre-load when finding the records on a page
Whether to enable inplace editing for this column. Currently works for text columns, in the List.
:table to refresh list true or :row to refresh row
the display-name of the column. this will be used, for instance, as the column title in the table and as the field name in the form. if left alone it will utilize human_attribute_name which includes localization
a place to store dev’s column specific options
A placeholder text, to be used inside blank text fields to describe, what should be typed in
whether the field is required or not. used on the form for visually indicating the fact to the user.
a collection of columns to load from the association when eager loading is disabled, if it’s nil all columns will be loaded
What columns load from main table
send all the form instead of only new value when this column changes
to modify the default order of columns
Public Instance Methods
Source
# 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
Source
# File lib/active_scaffold/data_structures/column.rb, line 184 def associated_number? @associated_number end
Source
# File lib/active_scaffold/data_structures/column.rb, line 346 def attributes=(opts) opts.each do |setting, value| send :"#{setting}=", value end end
Source
# File lib/active_scaffold/data_structures/column.rb, line 342 def cache_count? includes.blank? && associated_number? && association&.cache_count? end
Source
# File lib/active_scaffold/data_structures/column.rb, line 111 def calculation? !(calculate == false || calculate.nil?) end
get whether to run a calculation on this column
Source
# File lib/active_scaffold/data_structures/column.rb, line 105 def clear_link @link = nil @autolink = false end
this should not only delete any existing link but also prevent column links from being automatically added by later routines
Source
# File lib/active_scaffold/data_structures/column.rb, line 204 def convert_to_native? number? && options[:format] && form_ui != :number end
Source
# 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
Source
Source
# 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
Source
# File lib/active_scaffold/data_structures/column.rb, line 99 def inplace_edit=(value) clear_link if value @inplace_edit = value end
Source
# 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
Source
# 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
Source
# File lib/active_scaffold/data_structures/column.rb, line 242 def list_ui @list_ui || form_ui end
Source
Source
# File lib/active_scaffold/data_structures/column.rb, line 246 def list_ui_options @list_ui ? @list_ui_options : form_ui_options end
Source
# File lib/active_scaffold/data_structures/column.rb, line 195 def number? @number end
Source
# 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 options[: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
Source
# 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
Source
# File lib/active_scaffold/data_structures/column.rb, line 287 def search_joins @search_joins || includes end
a collection of associations to do left join when this column is included on search
Source
# 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
Source
# File lib/active_scaffold/data_structures/column.rb, line 312 def search_sql initialize_search_sql if @search_sql == true @search_sql end
Source
# 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
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
Source
# File lib/active_scaffold/data_structures/column.rb, line 270 def search_ui @search_ui || form_ui || (:select if association && !association.polymorphic?) end
Source
Source
# File lib/active_scaffold/data_structures/column.rb, line 274 def search_ui_options @search_ui ? @search_ui_options : form_ui_options end
Source
# File lib/active_scaffold/data_structures/column.rb, line 317 def searchable? search_sql.present? end
Source
# File lib/active_scaffold/data_structures/column.rb, line 331 def set_link(action, options = {}) if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc) @link = action else options[:label] ||= label options[:position] ||= :after unless options.key?(:position) options[:type] ||= :member @link = ActiveScaffold::DataStructures::ActionLink.new(action, options) end end
associate an action_link with this column
Source
# 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.authorized_for?(crud_type: :create) && !association.readonly? association.collection? || (association.singular? && associated.blank?) end
Source
# File lib/active_scaffold/data_structures/column.rb, line 256 def show_ui @show_ui || list_ui end
Source
Source
# File lib/active_scaffold/data_structures/column.rb, line 260 def show_ui_options @show_ui ? @show_ui_options : list_ui_options end
Source
# File lib/active_scaffold/data_structures/column.rb, line 170 def sort initialize_sort if @sort == true @sort end
Source
# 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
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!
Source
# File lib/active_scaffold/data_structures/column.rb, line 180 def sort_by(options) self.sort = options end
a configuration helper for the self.sort property. simply provides a method syntax instead of setter syntax.
Source
# File lib/active_scaffold/data_structures/column.rb, line 175 def sortable? sort != false && !sort.nil? end
Source
# File lib/active_scaffold/data_structures/column.rb, line 152 def update_columns=(column_names) @update_columns = Array(column_names) end
update dependent columns after value change in form
update_columns = :name update_columns = [:name, :age]
Protected Instance Methods
Source
# File lib/active_scaffold/data_structures/column.rb, line 363 def initialize_search_sql self.search_sql = unless virtual? if association.nil? field.to_s unless tableless? elsif association.allow_join? [association.quoted_table_name, association.quoted_primary_key].join('.') unless association.klass < ActiveScaffold::Tableless end end end
Source
# File lib/active_scaffold/data_structures/column.rb, line 354 def initialize_sort self.sort = if column && !tableless? {sql: field} else false end end