Class: Plutonium::Query::Filters::DateRange
Overview
DateRange filter for filtering between two dates
Instance Attribute Summary
#key, #resource_class
Instance Method Summary
collapse
lookup
Methods inherited from Base
#humanize_value
#description, #icon, #label
Constructor Details
#initialize(from_label: nil, to_label: nil) ⇒ DateRange
13
14
15
16
17
|
# File 'lib/plutonium/query/filters/date_range.rb', line 13
def initialize(from_label: nil, to_label: nil, **)
super(**)
@from_label = from_label
@to_label = to_label
end
|
Instance Method Details
#apply(scope, from: nil, to: nil) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/plutonium/query/filters/date_range.rb', line 19
def apply(scope, from: nil, to: nil)
from_date = parse_date(from)
to_date = parse_date(to)
if from_date && to_date
scope.where(key => from_date.beginning_of_day..to_date.end_of_day)
elsif from_date
scope.where(key => from_date.beginning_of_day..)
elsif to_date
scope.where(key => ..to_date.end_of_day)
else
scope
end
end
|
34
35
36
37
38
39
|
# File 'lib/plutonium/query/filters/date_range.rb', line 34
def customize_inputs
input :from, as: :date
input :to, as: :date
field :from, placeholder: @from_label || "#{key.to_s.humanize} from..."
field :to, placeholder: @to_label || "#{key.to_s.humanize} to..."
end
|