Module: CmAdmin::ViewHelpers::FieldDisplayHelper
- Included in:
- CmAdmin::ViewHelpers
- Defined in:
- lib/cm_admin/view_helpers/field_display_helper.rb
Instance Method Summary collapse
- #show_attachment_value(ar_object, field) ⇒ Object
- #show_field(ar_object, field) ⇒ Object
- #show_field_label(ar_object, field) ⇒ Object
- #show_field_value(ar_object, field) ⇒ Object
- #value_with_prefix_and_suffix(ar_object, field) ⇒ Object
Instance Method Details
#show_attachment_value(ar_object, field) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cm_admin/view_helpers/field_display_helper.rb', line 79 def (ar_object, field) if ar_object.send(field.field_name).attached? if ar_object.send(field.field_name).class.name.include?('One') content_tag :a, href: rails_blob_path(ar_object.send(field.field_name), disposition: "attachment") do ar_object.send(field.field_name).filename.to_s end elsif ar_object.send(field.field_name).class.name.include?('Many') ar_object.send(field.field_name).map do |asset| content_tag :a, href: rails_blob_path(asset, disposition: "attachment") do asset.filename.to_s end end.join("\n").html_safe end end end |
#show_field(ar_object, field) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/cm_admin/view_helpers/field_display_helper.rb', line 4 def show_field(ar_object, field) return unless field.display_if.call(ar_object) content_tag(:div, class: "info-split") do concat show_field_label(ar_object, field) concat value_with_prefix_and_suffix(ar_object, field) end end |
#show_field_label(ar_object, field) ⇒ Object
12 13 14 15 16 |
# File 'lib/cm_admin/view_helpers/field_display_helper.rb', line 12 def show_field_label(ar_object, field) content_tag(:div, class: "info-split__lhs") do p = field.label.present? ? field.label.to_s : field.field_name.to_s.titleize end end |
#show_field_value(ar_object, field) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cm_admin/view_helpers/field_display_helper.rb', line 27 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 (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 end end |
#value_with_prefix_and_suffix(ar_object, field) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/cm_admin/view_helpers/field_display_helper.rb', line 18 def value_with_prefix_and_suffix(ar_object, field) value = show_field_value(ar_object, field) content_tag(:div, class: "info-split__rhs") do concat field.prefix concat value concat field.suffix end end |