Class: BetweenOrEqualDateInput

Inherits:
BetweenOrEqualInput show all
Defined in:
app/inputs/between_or_equal_date_input.rb

Overview

SimpleForm input wrapper for a between-or-equal date range filter.

Direct Known Subclasses

BetweenOrEqualDateGteqTimeInput

Instance Method Summary collapse

Methods inherited from BetweenOrEqualInput

#input, #label_target, #literal_and, #span_gteq, #span_lteq

Instance Method Details

#clear_btnActiveSupport::SafeBuffer

Renders the clear button.

Returns:

  • (ActiveSupport::SafeBuffer)

    the clear button markup



70
71
72
73
74
75
76
77
78
# File 'app/inputs/between_or_equal_date_input.rb', line 70

def clear_btn
  template.(:a, {
    class: 'btn btn-outline-primary input-button date-clear-btn h-100 rounded-0',
    title: 'clear',
    data: { clear: true }
  }) do
    template.fa_icon('times', class: 'text-body-secondary')
  end
end

#gteq_fieldActiveSupport::SafeBuffer

Renders the GTEQ input field wrapper.

Returns:

  • (ActiveSupport::SafeBuffer)

    the GTEQ field markup



48
49
50
51
52
53
54
# File 'app/inputs/between_or_equal_date_input.rb', line 48

def gteq_field
  template.(:div, class: 'flex-grow-1 gteq_field') do
    options = gteq_input_html_options.dup
    arel_predicate_gteq = options.delete(:arel_predicate_gteq).to_sym
    @builder.input_field(arel_predicate_gteq, gteq_input_html_options)
  end
end

#gteq_input_html_optionsHash

HTML options for the greater-than-or-equal date input.

Returns:

  • (Hash)

    options for the GTEQ date picker



8
9
10
11
12
13
14
# File 'app/inputs/between_or_equal_date_input.rb', line 8

def gteq_input_html_options
  opts = super.reverse_merge({ arel_predicate_gteq: :"#{attribute_name}_gteq",
                               placeholder: 'After or on',
                               class: 'flex-grow-1' })
  opts[:as] = :date_picker
  opts
end

#gteq_valueDate?

Casts the GTEQ value to a date.

The field being searched may be a timestamp, so we normalize to a date.

Returns:

  • (Date, nil)

    the cast value



32
33
34
# File 'app/inputs/between_or_equal_date_input.rb', line 32

def gteq_value
  super.try(:to_date)
end

#lteq_fieldActiveSupport::SafeBuffer

Renders the LTEQ input field wrapper.

Returns:

  • (ActiveSupport::SafeBuffer)

    the LTEQ field markup



59
60
61
62
63
64
65
# File 'app/inputs/between_or_equal_date_input.rb', line 59

def lteq_field
  template.(:div, class: 'flex-grow-1 lteq_field') do
    options = lteq_input_html_options.dup
    arel_predicate_lteq = options.delete(:arel_predicate_lteq).to_sym
    @builder.input_field(arel_predicate_lteq, lteq_input_html_options)
  end
end

#lteq_input_html_optionsHash

HTML options for the less-than-or-equal date input.

Returns:

  • (Hash)

    options for the LTEQ date picker



19
20
21
22
23
24
25
# File 'app/inputs/between_or_equal_date_input.rb', line 19

def lteq_input_html_options
  opts = super.reverse_merge({ arel_predicate_lteq: :"#{attribute_name}_lteq",
                               placeholder: 'Before or on',
                               class: 'flex-grow-1' })
  opts[:as] = :date_picker
  opts
end

#lteq_valueDate?

Casts the LTEQ value to a date.

The field being searched may be a timestamp, so we normalize to a date.

Returns:

  • (Date, nil)

    the cast value



41
42
43
# File 'app/inputs/between_or_equal_date_input.rb', line 41

def lteq_value
  super.try(:to_date)
end