class Datagrid::Filters::DynamicFilter
Constants
- AVAILABLE_OPERATIONS
- DEFAULT_OPERATIONS
- EQUAL_OPERATION
- LESS_EQUAL_OPERATION
- LIKE_OPERATION
- MORE_EQUAL_OPERATION
Public Class Methods
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 22 def initialize(grid, name, **options, &block) options[:select] ||= default_select options[:operations] ||= DEFAULT_OPERATIONS options[:include_blank] = false unless options.key?(:include_blank) super end
Calls superclass method
Datagrid::Filters::BaseFilter::new
Public Instance Methods
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 41 def default_filter_where(scope, filter) field = filter.field operation = filter.operation value = filter.value date_conversion = value.is_a?(Date) && driver.timestamp_column?(scope, field) return scope if field.blank? || operation.blank? unless operations.include?(operation) raise Datagrid::FilteringError, "Unknown operation: #{operation.inspect}. Available operations: #{operations.join(' ')}" end case operation when EQUAL_OPERATION value = Datagrid::Utils.format_date_as_timestamp(value) if date_conversion driver.where(scope, field, value) when LIKE_OPERATION if column_type(field) == :string driver.contains(scope, field, value) else value = Datagrid::Utils.format_date_as_timestamp(value) if date_conversion driver.where(scope, field, value) end when MORE_EQUAL_OPERATION value = value.beginning_of_day if date_conversion driver.greater_equal(scope, field, value) when LESS_EQUAL_OPERATION value = value.end_of_day if date_conversion driver.less_equal(scope, field, value) else raise Datagrid::FilteringError, "Unknown operation: #{operation.inspect}. Use filter block argument to implement operation" end end
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 29 def default_input_options { **super, type: nil } end
Calls superclass method
Datagrid::Filters::BaseFilter#default_input_options
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 77 def operations options[:operations] end
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 81 def operations_select operations.map do |operation| [I18n.t(operation, scope: "datagrid.filters.dynamic.operations"), operation] end end
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 33 def parse_values(filter) filter ? FilterValue.new(grid_class, filter) : nil end
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 37 def unapplicable_value?(filter) super(filter&.value) end
Calls superclass method
Datagrid::Filters::BaseFilter#unapplicable_value?
Protected Instance Methods
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 99 def column_type(field) grid_class.driver.normalized_column_type(grid_class.scope, field) end
Source
# File lib/datagrid/filters/dynamic_filter.rb, line 89 def default_select proc { |grid| grid.driver.column_names(grid.scope).map do |name| # Mongodb/Rails problem: # '_id'.humanize returns '' [name.gsub(%r{^_}, "").humanize.strip, name] end } end