Class: Satis::DateTimePicker::Component
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Satis::DateTimePicker::Component
- Defined in:
- app/components/satis/date_time_picker/component.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#clearable ⇒ Object
readonly
Returns the value of attribute clearable.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#inline ⇒ Object
readonly
Returns the value of attribute inline.
-
#multiple ⇒ Object
readonly
Returns the value of attribute multiple.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#time_picker ⇒ Object
readonly
Returns the value of attribute time_picker.
Attributes inherited from ApplicationComponent
Instance Method Summary collapse
-
#initialize(form:, attribute:, **options, &block) ⇒ Component
constructor
A new instance of Component.
- #week_start ⇒ Object
Methods inherited from ApplicationComponent
Constructor Details
#initialize(form:, attribute:, **options, &block) ⇒ Component
Returns a new instance of Component.
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 39 40 41 |
# File 'app/components/satis/date_time_picker/component.rb', line 8 def initialize(form:, attribute:, **, &block) super @form = form @attribute = attribute @options = @block = block [:input_html] ||= {} @time_picker = .key?(:time_picker) ? [:time_picker] : true @inline = .key?(:inline) ? [:inline] : false @clearable = .key?(:clearable) ? [:clearable] : true @multiple = .key?(:multiple) ? [:multiple] : false @range = .key?(:range) ? [:range] : false @format = if .key?(:format) [:format] else {weekday: "long", month: "short", year: "numeric", day: "numeric", hour: "numeric", minute: "numeric", hour12: false} end [:input_html].merge!("data-satis-date-time-picker-target" => "hiddenInput", "data-action" => "change->satis-date-time-picker#hiddenInputChanged") # FIXME: deal with ranges and multiples hidden_value = [:input_html][:value] hidden_value ||= @form.object.send(attribute) hidden_value = if hidden_value.is_a?(String) hidden_value&.split(" - ")&.map { |d| Time.parse(d).iso8601 }&.join(" - ") else hidden_value&.iso8601 end [:input_html][:value] = hidden_value end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def attribute @attribute end |
#clearable ⇒ Object (readonly)
Returns the value of attribute clearable.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def clearable @clearable end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def form @form end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def format @format end |
#inline ⇒ Object (readonly)
Returns the value of attribute inline.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def inline @inline end |
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def multiple @multiple end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def @options end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def range @range end |
#time_picker ⇒ Object (readonly)
Returns the value of attribute time_picker.
6 7 8 |
# File 'app/components/satis/date_time_picker/component.rb', line 6 def time_picker @time_picker end |
Instance Method Details
#week_start ⇒ Object
43 44 45 |
# File 'app/components/satis/date_time_picker/component.rb', line 43 def week_start Date::DAYS_INTO_WEEK[Date.beginning_of_week] || 1 end |