module CmAdmin::ViewHelpers::FieldDisplayHelper
def show_field_value(ar_object, field)
def show_field_value(ar_object, field) case field.field_type || :string when :integer ar_object.send(field.field_name).to_s when :decimal ar_object.send(field.field_name).to_f.round(field.precision).to_s if ar_object.send(field.field_name) when :string ar_object.send(field.field_name).to_s when :datetime self.extend LocalTimeHelper local_time(ar_object.send(field.field_name).strftime(field.format || "%d/%m/%Y").to_s) if ar_object.send(field.field_name) when :date self.extend LocalTimeHelper local_date(ar_object.send(field.field_name), (field.format || '%B %e, %Y')) when :text ar_object.send(field.field_name) when :custom send(field.helper_method, ar_object, field.field_name) when :link if field.custom_link link = field.custom_link else link = ar_object.send(field.field_name) end content_tag :a, href: link do ar_object.send(field.field_name).to_s end when :enum ar_object.send(field.field_name).to_s.titleize when :tag tag_class = field.tag_class.dig("#{ar_object.send(field.field_name.to_s)}".to_sym).to_s content_tag :span, class: "status-tag #{tag_class}" do ar_object.send(field.field_name).to_s.upcase end when :attachment show_attachment_value(ar_object, field) when :drawer content_tag :div, class: 'd-flex' do concat content_tag(:div, ar_object.send(field.field_name).to_s, class: 'text-ellipsis') concat content_tag(:div, 'View', class: 'drawer-btn') end when :image content_tag(:div, class: 'd-flex') do if ar_object.send(field.field_name).attached? image_tag(ar_object.send(field.field_name).url, height: field.height, width: field.height) else image_tag('https://cm-admin.s3.ap-south-1.amazonaws.com/gem_static_assets/image_not_available.png', height: 50, width: 50) end end when :association if field.association_type.to_s == 'polymorphic' association_name = ar_object.send(field.association_name).class.to_s.underscore field_name = find_field_name(field, association_name) link_to ar_object.send(field.association_name).send(field_name), cm_admin.send("#{association_name}_show_path", ar_object.send(field.association_name).id) elsif ['belongs_to', 'has_one'].include? field.association_type.to_s link_to ar_object.send(field.association_name).send(field.field_name), cm_admin.send("#{field.association_name}_show_path", ar_object.send(field.association_name).id) end end end