class RailsAiAdmin::Presentation::IndexSettings
Static index table presentation. Columns and the default sort only narrow or order what current read/sort grants already allow; nothing here grants.
Constants
- COMPACT_TYPES
-
Short machine-formatted values (IDs, numbers, ISO dates) stay on one line in index cells; hyphens in dates are otherwise legal break points.
- COUNT_LIMIT
-
Exact counts stop here so a large table never needs a full COUNT(*).
- COUNT_STRATEGIES
- MAX_COLUMNS
- MAX_PAGE_SIZE
Public Class Methods
Source
# File lib/rails_ai_admin/presentation/index_settings.rb, line 17 def initialize(columns: nil, default_sort: nil, default_direction: "asc", page_size: 25, count: :none) unless columns.nil? || columns.is_a?(Array) && columns.size.between?(1, MAX_COLUMNS) && columns.all? { |name| name.is_a?(Symbol) } && columns.uniq.size == columns.size raise ConfigurationError, "Index columns must be 1 to #{MAX_COLUMNS} distinct field-name symbols" end raise ConfigurationError, "Index default sort must be a field-name symbol" unless default_sort.nil? || default_sort.is_a?(Symbol) raise ConfigurationError, "Index default direction must be asc or desc" unless %w[asc desc].include?(default_direction) raise ConfigurationError, "Index page size must be an integer from 1 to #{MAX_PAGE_SIZE}" unless page_size.is_a?(Integer) && page_size.between?(1, MAX_PAGE_SIZE) raise ConfigurationError, "Index count must be :none or :exact" unless COUNT_STRATEGIES.include?(count) super(columns: columns&.dup&.freeze, default_sort: default_sort, default_direction: String.new(default_direction).freeze, page_size: page_size, count: count) end
Calls superclass method
Public Instance Methods
Source
# File lib/rails_ai_admin/presentation/index_settings.rb, line 45 def order(fields) return fields unless columns by_name = fields.index_by(&:name) columns.filter_map { |name| by_name[name] } end
Orders already-authorized index fields; unlisted fields are omitted.
Source
# File lib/rails_ai_admin/presentation/index_settings.rb, line 29 def validate!(fields) by_name = fields.index_by(&:name) Array(columns).each do |name| field = by_name[name] unless field && !field.hidden? && field.options[:index] raise ConfigurationError, "Index column #{name} must be a declared field visible on index" end end if default_sort field = by_name[default_sort] raise ConfigurationError, "Index default sort #{default_sort} must be a declared sortable field" unless field && !field.hidden? && !field.virtual? && field.options[:sortable] end self end
Checks references against the resourceโs declarations at registration.