Module: ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers

Defined in:
lib/active_scaffold/bridges/shared/date_bridge.rb

Instance Method Summary collapse

Instance Method Details

#active_scaffold_date_bridge_trend_tag(column, options, trend_options) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 47

def active_scaffold_date_bridge_trend_tag(column, options, trend_options)
  trend_controls = [
    text_field_tag("#{options[:name]}[number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off'),
    select_tag("#{options[:name]}[unit]",
               options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:unit_value]),
               :class => 'text-input')
  ]
  ('span', safe_join(trend_controls, ' '),
              :id => "#{options[:id]}_trend", :class => 'search-date-trend',
              :style => trend_options[:show] ? nil : 'display: none')
end

#active_scaffold_search_date_bridge(column, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 6

def active_scaffold_search_date_bridge(column, options)
  current_search = {'from' => nil, 'to' => nil, 'opt' => 'BETWEEN',
                    'number' => 1, 'unit' => 'DAYS', 'range' => nil}
  current_search.merge!(options[:value]) unless options[:value].nil?
  tags = []
  tags << active_scaffold_search_date_bridge_comparator_tag(column, options, current_search)
  tags << active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
  tags << active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
  tags << active_scaffold_search_date_bridge_range_tag(column, options, current_search)
  safe_join tags, '&nbsp;'.html_safe # rubocop:disable Rails/OutputSafety
end

#active_scaffold_search_date_bridge_comparator_options(column) ⇒ Object



18
19
20
21
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 18

def active_scaffold_search_date_bridge_comparator_options(column)
  select_options = ActiveScaffold::Finder::DATE_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] }
  select_options + ActiveScaffold::Finder::NUMERIC_COMPARATORS.collect { |comp| [as_(comp.downcase.to_sym), comp] }
end

#active_scaffold_search_date_bridge_comparator_tag(column, options, current_search) ⇒ Object



23
24
25
26
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 23

def active_scaffold_search_date_bridge_comparator_tag(column, options, current_search)
  choices = options_for_select(active_scaffold_search_date_bridge_comparator_options(column), current_search['opt'])
  select_tag("#{options[:name]}[opt]", choices, :id => "#{options[:id]}_opt", :class => 'as_search_range_option as_search_date_time_option')
end

#active_scaffold_search_date_bridge_numeric_tag(column, options, current_search) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 28

def active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
  numeric_controls = [
    active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'from'),
    (:span, safe_join([' - ', active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'to')]),
                :id => "#{options[:id]}_between", :class => 'as_search_range_between',
                :style => current_search['opt'] == 'BETWEEN' ? nil : 'display: none')
  ]
  ('span', safe_join(numeric_controls),
              :id => "#{options[:id]}_numeric", :class => 'search-date-numeric',
              :style => ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(current_search['opt']) ? nil : 'display: none')
end

#active_scaffold_search_date_bridge_range_tag(column, options, current_search) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 65

def active_scaffold_search_date_bridge_range_tag(column, options, current_search)
  values = ActiveScaffold::Finder::DATE_RANGES.collect { |range| [as_(range.downcase.to_sym), range] }
  range_controls = select_tag("#{options[:name]}[range]",
                              options_for_select(values, current_search['range']),
                              :class => 'text-input', :id => nil)
  ('span', range_controls,
              :id => "#{options[:id]}_range", :class => 'search-date-range',
              :style => ('display: none' unless current_search['opt'] == 'RANGE'))
end

#active_scaffold_search_date_bridge_trend_tag(column, options, current_search) ⇒ Object



40
41
42
43
44
45
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 40

def active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
  active_scaffold_date_bridge_trend_tag(column, options,
                                        :number_value => current_search['number'],
                                        :unit_value => current_search['unit'],
                                        :show => (current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE'))
end

#active_scaffold_search_date_bridge_trend_units(column) ⇒ Object



59
60
61
62
63
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 59

def active_scaffold_search_date_bridge_trend_units(column)
  options = ActiveScaffold::Finder::DATE_UNITS.collect { |unit| [as_(unit.downcase.to_sym), unit] }
  options = ActiveScaffold::Finder::TIME_UNITS.collect { |unit| [as_(unit.downcase.to_sym), unit] } + options if column_datetime?(column)
  options
end

#column_datetime?(column) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 75

def column_datetime?(column)
  (!column.column.nil? && %i[datetime time].include?(column.column.type))
end