Class: ActiveElement::Components::Util::DisplayValueMapping

Inherits:
Object
  • Object
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

Constants included from RecordMapping

RecordMapping::DATABASE_TYPES

Instance Method Summary collapse

Methods included from RecordMapping

#initialize, #type, #value

Instance Method Details

#boolean_valueObject



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_valueObject



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_valueObject



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_valueObject



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_valueObject



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_recordObject



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_recordObject



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_valueObject



20
21
22
# File 'lib/active_element/components/util/display_value_mapping.rb', line 20

def numeric_value
  value_from_record
end

#string_valueObject



31
32
33
# File 'lib/active_element/components/util/display_value_mapping.rb', line 31

def string_value
  value_from_record
end

#time_valueObject



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_pathObject



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