Class: Avo::Fields::DateTimeField
- Defined in:
- lib/avo/fields/date_time_field.rb
Direct Known Subclasses
Defined Under Namespace
Classes: EditComponent, IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#picker_format ⇒ Object
readonly
Returns the value of attribute picker_format.
-
#relative ⇒ Object
readonly
Returns the value of attribute relative.
-
#time_24hr ⇒ Object
readonly
Returns the value of attribute time_24hr.
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
Attributes inherited from DateField
#disable_mobile, #first_day_of_week, #picker_options
Attributes inherited from TextField
#as_html, #link_to_resource, #protocol
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #index_text_align, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #stacked, #updatable, #user, #view, #visible
Attributes included from Concerns::HasHTMLAttributes
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #edit_formatted_value ⇒ Object
- #fill_field(model, key, value, params) ⇒ Object
- #formatted_value ⇒ Object
-
#initialize(id, **args, &block) ⇒ DateTimeField
constructor
A new instance of DateTimeField.
- #utc_time(value) ⇒ Object
Methods inherited from BaseField
#component_for_view, #custom?, #custom_name?, #database_id, #default_name, #has_own_panel?, #hidden_in_reflection?, #hydrate, #model_errors, #name, #placeholder, #plural_name, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?, #visible_in_reflection?
Methods included from FieldExtensions::HasFieldName
Methods included from Concerns::HasDefault
Methods included from Concerns::IsReadonly
Methods included from Concerns::IsRequired
Methods included from Concerns::HasHTMLAttributes
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update, #visible_on?
Methods included from Concerns::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
Constructor Details
#initialize(id, **args, &block) ⇒ DateTimeField
Returns a new instance of DateTimeField.
10 11 12 13 14 15 16 17 18 |
# File 'lib/avo/fields/date_time_field.rb', line 10 def initialize(id, **args, &block) super(id, **args, &block) add_boolean_prop args, :time_24hr add_string_prop args, :picker_format, "Y-m-d H:i:S" add_string_prop args, :format, "yyyy-LL-dd TT" add_string_prop args, :timezone add_boolean_prop args, :relative, true end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
4 5 6 |
# File 'lib/avo/fields/date_time_field.rb', line 4 def format @format end |
#picker_format ⇒ Object (readonly)
Returns the value of attribute picker_format.
5 6 7 |
# File 'lib/avo/fields/date_time_field.rb', line 5 def picker_format @picker_format end |
#relative ⇒ Object (readonly)
Returns the value of attribute relative.
8 9 10 |
# File 'lib/avo/fields/date_time_field.rb', line 8 def relative @relative end |
#time_24hr ⇒ Object (readonly)
Returns the value of attribute time_24hr.
6 7 8 |
# File 'lib/avo/fields/date_time_field.rb', line 6 def time_24hr @time_24hr end |
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
7 8 9 |
# File 'lib/avo/fields/date_time_field.rb', line 7 def timezone @timezone end |
Instance Method Details
#edit_formatted_value ⇒ Object
26 27 28 29 30 |
# File 'lib/avo/fields/date_time_field.rb', line 26 def edit_formatted_value return nil if value.nil? value.utc.iso8601 end |
#fill_field(model, key, value, params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/avo/fields/date_time_field.rb', line 32 def fill_field(model, key, value, params) if value.in?(["", nil]) model[id] = value return model end return model if value.blank? model[id] = utc_time(value) model end |
#formatted_value ⇒ Object
20 21 22 23 24 |
# File 'lib/avo/fields/date_time_field.rb', line 20 def formatted_value return nil if value.nil? value.utc.to_time.iso8601 end |
#utc_time(value) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/avo/fields/date_time_field.rb', line 46 def utc_time(value) if timezone.present? ActiveSupport::TimeZone.new(timezone).local_to_utc(Time.parse(value)) else value end end |