Class: Crm::EmbeddedAssetsPanelComponent

Inherits:
ViewComponent::Base
  • Object
show all
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

Instance Method Summary collapse

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

#parentObject (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



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(embedded_asset)
  case embedded_asset
  when EmbeddedImageAsset
    image_link(embedded_asset)
  when EmbeddedVideoAsset
    video_link(embedded_asset)
  when EmbeddedFaqAsset
    faq_links(embedded_asset)
  when EmbeddedProductAsset
    product_link(embedded_asset)
  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(embedded_asset)
  case embedded_asset
  when EmbeddedImageAsset
    embedded_asset.asset&.thumbnail_url
  when EmbeddedVideoAsset
    embedded_asset.asset&.thumbnail_url
  when EmbeddedProductAsset
    embedded_asset.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(embedded_asset)
  case embedded_asset
  when EmbeddedImageAsset
    embedded_asset.asset&.title || embedded_asset.asset&.seo_title || "Image ##{embedded_asset.asset_id}"
  when EmbeddedVideoAsset
    embedded_asset.asset&.title || "Video ##{embedded_asset.asset_id}"
  when EmbeddedFaqAsset
    # Each FAQ has its own record - FAQs use 'subject' for the question
    article = embedded_asset.asset
    article&.subject || article&.title || "FAQ ##{embedded_asset.asset_id}"
  when EmbeddedProductAsset
    item = embedded_asset.asset
    item&.public_name || item&.name || item&.sku || "Product ##{embedded_asset.asset_id}"
  else
    "Asset ##{embedded_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_assetsObject



23
24
25
# File 'app/components/crm/embedded_assets_panel_component.rb', line 23

def embedded_assets
  @embedded_assets ||= parent.embedded_assets.includes(:asset).order(:created_at)
end

#grouped_assetsObject



27
28
29
# File 'app/components/crm/embedded_assets_panel_component.rb', line 27

def grouped_assets
  @grouped_assets ||= embedded_assets.group_by(&:type)
end

#render?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/components/crm/embedded_assets_panel_component.rb', line 19

def render?
  embedded_assets.any?
end