Module: Wice::WiceGridExtentionToActiveRecordColumn

Defined in:
lib/wice_grid.rb

Overview

to be mixed in into ActiveRecord::ConnectionAdapters::Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#model_klassObject

Returns the value of attribute model_klass


591
592
593
# File 'lib/wice_grid.rb', line 591

def model_klass
  @model_klass
end

Instance Method Details

#alias_or_table_name(table_alias) ⇒ Object


593
594
595
# File 'lib/wice_grid.rb', line 593

def alias_or_table_name(table_alias)
  table_alias || self.model_klass.table_name
end

#wg_generate_conditions(table_alias, custom_filter_active) ⇒ Object

:nodoc:


644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
# File 'lib/wice_grid.rb', line 644

def wg_generate_conditions(table_alias, custom_filter_active)  #:nodoc:
  return nil if @request_params.nil?

  if custom_filter_active
    return ::Wice::FilterConditionsGeneratorCustomFilter.new(self).generate_conditions(table_alias, @request_params)
  end

  column_type = self.type.to_s

  processor_class = ::Wice::FilterConditionsGenerator.handled_type[column_type]

  if processor_class
    return processor_class.new(self).generate_conditions(table_alias, @request_params)
  else
    Wice.log("No processor for database type #{column_type}!!!")
    nil
  end
end

#wg_initialize_request_parameters(all_filter_params, main_table, table_alias, custom_filter_active) ⇒ Object

:nodoc:


597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/wice_grid.rb', line 597

def wg_initialize_request_parameters(all_filter_params, main_table, table_alias, custom_filter_active)  #:nodoc:
  @request_params = nil
  return if all_filter_params.nil?

  # if the parameter does not specify the table name we only allow columns in the default table to use these parameters
  if main_table && @request_params  = all_filter_params[self.name]
    current_parameter_name = self.name
  elsif @request_params = all_filter_params[alias_or_table_name(table_alias) + '.' + self.name]
    current_parameter_name = alias_or_table_name(table_alias) + '.' + self.name
  end

  # Preprocess incoming parameters for datetime, if what's coming in is
  # a datetime (with custom_filter it can be anything else, and not
  # the datetime hash {:fr => ..., :to => ...})
  if @request_params
    if (self.type == :datetime || self.type == :timestamp) && @request_params.is_a?(Hash)
      [:fr, :to].each do |sym|
        if @request_params[sym]
          if @request_params[sym].is_a?(String)
            @request_params[sym] = Wice::ConfigurationProvider.value_for(:DATETIME_PARSER).call(@request_params[sym])
          elsif @request_params[sym].is_a?(Hash)
            @request_params[sym] = Wice::GridTools.params_2_datetime(@request_params[sym])
          end
        end
      end

    end

    # Preprocess incoming parameters for date, if what's coming in is
    # a date (with custom_filter it can be anything else, and not
    # the date hash {:fr => ..., :to => ...})
    if self.type == :date && @request_params.is_a?(Hash)
      [:fr, :to].each do |sym|
        if @request_params[sym]
          if @request_params[sym].is_a?(String)
            @request_params[sym] = Wice::ConfigurationProvider.value_for(:DATE_PARSER).call(@request_params[sym])
          elsif @request_params[sym].is_a?(Hash)
            @request_params[sym] = ::Wice::GridTools.params_2_date(@request_params[sym])
          end
        end
      end
    end
  end

  return wg_generate_conditions(table_alias, custom_filter_active), current_parameter_name
end