Module: ActiveScaffold::Helpers::HumanConditionHelpers
- Included in:
- ViewHelpers
- Defined in:
- lib/active_scaffold/helpers/human_condition_helpers.rb
Overview
Helpers that assist with rendering of a human readable search statement
Instance Method Summary collapse
- #active_scaffold_human_condition_for(column) ⇒ Object
-
#override_human_condition(search_ui) ⇒ Object
the naming convention for overriding human condition search_ui types.
- #override_human_condition?(search_ui) ⇒ Boolean
-
#override_human_condition_column(column) ⇒ Object
the naming convention for overriding form fields with helpers.
- #override_human_condition_column?(column) ⇒ Boolean
Instance Method Details
#active_scaffold_human_condition_for(column) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_scaffold/helpers/human_condition_helpers.rb', line 6 def active_scaffold_human_condition_for(column) value = field_search_params[column.name] search_ui = column.search_ui search_ui ||= column.column.type if column.column if override_human_condition_column?(column) send(override_human_condition_column(column), value, {}) elsif search_ui and override_human_condition?(column.search_ui) send(override_human_condition(column.search_ui), column, value) else case search_ui when :integer, :decimal, :float "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{format_number_value(controller.class.condition_value_for_numeric(column, value[:from]), column.)} #{value[:opt] == 'BETWEEN' ? '- ' + format_number_value(controller.class.condition_value_for_numeric(column, value[:to]), column.).to_s : ''}" when :string opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}" when :date, :time, :datetime, :timestamp conversion = column.column.type == :date ? :to_date : :to_time from = controller.condition_value_for_datetime(value[:from], conversion) to = controller.condition_value_for_datetime(value[:to], conversion) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" when :select, :multi_select, :record_select associated = value associated = [associated].compact unless associated.is_a? Array associated = column.association.klass.find(associated.map(&:to_i)).collect(&:to_label) if column.association "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.join(', ')}" when :boolean, :checkbox label = column.column.type_cast(value) ? as_(:true) : as_(:false) "#{column.active_record_class.human_attribute_name(column.name)} = #{label}" when :null "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value.to_sym)}" end end unless value.nil? end |
#override_human_condition(search_ui) ⇒ Object
the naming convention for overriding human condition search_ui types
54 55 56 |
# File 'lib/active_scaffold/helpers/human_condition_helpers.rb', line 54 def override_human_condition(search_ui) "active_scaffold_human_condition_#{search_ui}" end |
#override_human_condition?(search_ui) ⇒ Boolean
49 50 51 |
# File 'lib/active_scaffold/helpers/human_condition_helpers.rb', line 49 def override_human_condition?(search_ui) respond_to?(override_human_condition(search_ui)) end |
#override_human_condition_column(column) ⇒ Object
the naming convention for overriding form fields with helpers
45 46 47 |
# File 'lib/active_scaffold/helpers/human_condition_helpers.rb', line 45 def override_human_condition_column(column) "#{column.name}_human_condition_column" end |
#override_human_condition_column?(column) ⇒ Boolean
40 41 42 |
# File 'lib/active_scaffold/helpers/human_condition_helpers.rb', line 40 def override_human_condition_column?(column) respond_to?(override_human_condition_column(column)) end |