Sha256: e364cae2e30433a6659af23f8f9afe97196b2b177d22d09b848d858045d875fa
Contents?: true
Size: 1.68 KB
Versions: 15
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true module ActiveElement module Components module Util # Maps ActiveRecord record fields to values for display (e.g. in tables). class DisplayValueMapping include RecordMapping def mapped_association_from_record association_mapping.link_tag end def mapped_value_from_record return value_record_path if value_from_record.is_a?(ActiveRecord::Base) super end def numeric_value value_from_record end 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 def string_value value_from_record end def datetime_value with_timezone_offset(value_from_record).strftime('%Y-%m-%d %H:%M:%S') end def time_value with_timezone_offset(value_from_record).strftime('%H:%M:%S') end def date_value with_timezone_offset(value_from_record).strftime('%Y-%m-%d') end def boolean_value component.controller.render_to_string( partial: 'active_element/components/fields/boolean', locals: { value: value_from_record } ) end def geometry_value require 'rgeo/geo_json' Util.json_pretty_print(RGeo::GeoJSON.encode(value_from_record)) end def value_record_path RecordPath.new(record: value_from_record, controller: component.controller, type: :show).link end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems