Class: ActiveElement::Components::Util::DisplayValueMapping
- Inherits:
-
Object
- Object
- ActiveElement::Components::Util::DisplayValueMapping
show all
- Includes:
- RecordMapping
- Defined in:
- lib/active_element/components/util/display_value_mapping.rb
Overview
Maps ActiveRecord record fields to values for display (e.g. in tables).
Constant Summary
RecordMapping::DATABASE_TYPES
Instance Method Summary
collapse
#initialize, #type, #value
Instance Method Details
#boolean_value ⇒ Object
47
48
49
50
51
52
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 47
def boolean_value
component.controller.render_to_string(
partial: 'active_element/components/fields/boolean',
locals: { value: value_from_record }
)
end
|
#date_value ⇒ Object
43
44
45
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 43
def date_value
with_timezone_offset(value_from_record).strftime('%Y-%m-%d')
end
|
#datetime_value ⇒ Object
35
36
37
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 35
def datetime_value
with_timezone_offset(value_from_record).strftime('%Y-%m-%d %H:%M:%S')
end
|
#geometry_value ⇒ Object
54
55
56
57
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 54
def geometry_value
require 'rgeo/geo_json'
Util.json_pretty_print(RGeo::GeoJSON.encode(value_from_record))
end
|
#json_value ⇒ Object
24
25
26
27
28
29
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 24
def json_value
component.controller.render_to_string(
partial: 'active_element/components/fields/json',
locals: { value: value_from_record, field_id: ActiveElement.element_id }
)
end
|
#mapped_association_from_record ⇒ Object
10
11
12
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 10
def mapped_association_from_record
association_mapping.link_tag
end
|
#mapped_value_from_record ⇒ Object
14
15
16
17
18
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 14
def mapped_value_from_record
return value_record_path if value_from_record.is_a?(ActiveRecord::Base)
super
end
|
#numeric_value ⇒ Object
20
21
22
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 20
def numeric_value
value_from_record
end
|
#string_value ⇒ Object
31
32
33
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 31
def string_value
value_from_record
end
|
#time_value ⇒ Object
39
40
41
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 39
def time_value
with_timezone_offset(value_from_record).strftime('%H:%M:%S')
end
|
#value_record_path ⇒ Object
59
60
61
|
# File 'lib/active_element/components/util/display_value_mapping.rb', line 59
def value_record_path
RecordPath.new(record: value_from_record, controller: component.controller, type: :show).link
end
|