Sha256: 0626c0dedb4b3a7bbfca062fc406888c9fd5d798b9d4570853a3c519a67af610

Contents?: true

Size: 1.8 KB

Versions: 39

Compression:

Stored size: 1.8 KB

Contents

module Datagrid
  module Filters
    module CompositeFilters #:nodoc:

      def self.included(base)
        base.extend         ClassMethods
        base.class_eval do

        end
        base.send :include, InstanceMethods
      end # self.included

      module ClassMethods

        def date_range_filters(field, from_options = {}, to_options = {})
          from_options = normalize_composite_filter_options(from_options, field)
          to_options = normalize_composite_filter_options(to_options, field)

          filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :date, from_options) do |date, scope, grid|
            grid.driver.greater_equal(scope, field, date)
          end
          filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :date, to_options) do |date, scope, grid|
            grid.driver.less_equal(scope, field, date)
          end
        end

        def integer_range_filters(field, from_options = {}, to_options = {})
          from_options = normalize_composite_filter_options(from_options, field)
          to_options = normalize_composite_filter_options(to_options, field)
          filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :integer, from_options) do |value, scope, grid|
            grid.driver.greater_equal(scope, field, value)
          end
          filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :integer, to_options) do |value, scope, grid|
            grid.driver.less_equal(scope, field, value)
          end
        end

        def normalize_composite_filter_options(options, field)
          if options.is_a?(String) || options.is_a?(Symbol)
            options = {:name => options}
          end
          options
        end
      end # ClassMethods

      module InstanceMethods


      end # InstanceMethods

    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
datagrid-1.6.2 lib/datagrid/filters/composite_filters.rb
datagrid-1.6.1 lib/datagrid/filters/composite_filters.rb
datagrid-1.6.0 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.9 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.8 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.7 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.6 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.5 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.4 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.3 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.2 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.1 lib/datagrid/filters/composite_filters.rb
datagrid-1.5.0 lib/datagrid/filters/composite_filters.rb
datagrid-1.4.4 lib/datagrid/filters/composite_filters.rb
datagrid-1.4.3 lib/datagrid/filters/composite_filters.rb
datagrid-1.4.2 lib/datagrid/filters/composite_filters.rb
datagrid-1.4.1 lib/datagrid/filters/composite_filters.rb
datagrid-1.4.0 lib/datagrid/filters/composite_filters.rb
datagrid-1.3.9 lib/datagrid/filters/composite_filters.rb
datagrid-1.3.7 lib/datagrid/filters/composite_filters.rb