Class: Crm::EmbeddedAssetsPanelComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Crm::EmbeddedAssetsPanelComponent
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- app/components/crm/embedded_assets_panel_component.rb
Overview
Displays a panel listing all embedded assets (images, videos, FAQs) for an article/post
Used on CRM show pages to show what assets are embedded in the content
Usage:
<%= render Crm::EmbeddedAssetsPanelComponent.new(parent: @article) %>
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #asset_link(embedded_asset) ⇒ Object
- #asset_thumbnail(embedded_asset) ⇒ Object
- #asset_title(embedded_asset) ⇒ Object
- #asset_type_icon(type) ⇒ Object
- #asset_type_label(type) ⇒ Object
- #embedded_assets ⇒ Object
- #grouped_assets ⇒ Object
-
#initialize(parent:) ⇒ EmbeddedAssetsPanelComponent
constructor
A new instance of EmbeddedAssetsPanelComponent.
- #render? ⇒ Boolean
Constructor Details
#initialize(parent:) ⇒ EmbeddedAssetsPanelComponent
Returns a new instance of EmbeddedAssetsPanelComponent.
14 15 16 17 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 14 def initialize(parent:) super() @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
12 13 14 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 12 def parent @parent end |
Instance Method Details
#asset_link(embedded_asset) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 51 def asset_link() case when EmbeddedImageAsset image_link() when EmbeddedVideoAsset video_link() when EmbeddedFaqAsset faq_links() when EmbeddedProductAsset product_link() else nil end end |
#asset_thumbnail(embedded_asset) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 84 def asset_thumbnail() case when EmbeddedImageAsset .asset&.thumbnail_url when EmbeddedVideoAsset .asset&.thumbnail_url when EmbeddedProductAsset .asset&.primary_image&.thumbnail_url else nil end end |
#asset_title(embedded_asset) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 66 def asset_title() case when EmbeddedImageAsset .asset&.title || .asset&.seo_title || "Image ##{.asset_id}" when EmbeddedVideoAsset .asset&.title || "Video ##{.asset_id}" when EmbeddedFaqAsset # Each FAQ has its own record - FAQs use 'subject' for the question article = .asset article&.subject || article&.title || "FAQ ##{.asset_id}" when EmbeddedProductAsset item = .asset item&.public_name || item&.name || item&.sku || "Product ##{.asset_id}" else "Asset ##{.asset_id}" end end |
#asset_type_icon(type) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 41 def asset_type_icon(type) case type when 'EmbeddedImageAsset' then 'fa-regular fa-image' when 'EmbeddedVideoAsset' then 'fa-regular fa-video' when 'EmbeddedFaqAsset' then 'fa-regular fa-circle-question' when 'EmbeddedProductAsset' then 'fa-regular fa-tag' else 'fa-regular fa-file' end end |
#asset_type_label(type) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 31 def asset_type_label(type) case type when 'EmbeddedImageAsset' then 'Images' when 'EmbeddedVideoAsset' then 'Videos' when 'EmbeddedFaqAsset' then 'FAQs' when 'EmbeddedProductAsset' then 'Products' else type.demodulize.titleize end end |
#embedded_assets ⇒ Object
23 24 25 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 23 def @embedded_assets ||= parent..includes(:asset).order(:created_at) end |
#grouped_assets ⇒ Object
27 28 29 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 27 def grouped_assets @grouped_assets ||= .group_by(&:type) end |
#render? ⇒ Boolean
19 20 21 |
# File 'app/components/crm/embedded_assets_panel_component.rb', line 19 def render? .any? end |