Class: Crm::PublicationCardComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Crm::PublicationCardComponent
- Defined in:
- app/components/crm/publication_card_component.rb
Overview
Component for displaying a publication card in the publications index.
Optimized to avoid N+1 queries by accepting pre-loaded associations and
precomputed most_recent_revision data.
Usage:
render Crm::PublicationCardComponent.new(
publication: publication,
most_recent_revision: most_recent_revisions[publication.id]
)
Instance Attribute Summary collapse
-
#cover_image_url ⇒ Object
readonly
Returns the value of attribute cover_image_url.
-
#most_recent_revision ⇒ Object
readonly
Returns the value of attribute most_recent_revision.
-
#publication ⇒ Object
readonly
Returns the value of attribute publication.
Delegated Instance Attributes collapse
-
#literature ⇒ Object
Alias for Publication#literature.
-
#literature_present? ⇒ Object
Alias for Literature#present?.
-
#publication_name ⇒ Object
Alias for Publication#name.
-
#publication_sku ⇒ Object
Alias for Publication#sku.
-
#updated_at ⇒ Object
Alias for Publication#updated_at.
Instance Method Summary collapse
-
#category_name ⇒ Object
Uses pre-loaded product_category association to avoid N+1.
-
#fancybox_group ⇒ Object
Unique group per publication so clicking a cover opens only that publication's document in the lightbox, instead of grouping every cover on the page into a single carousel.
- #fancybox_type ⇒ Object
- #has_newer_revision? ⇒ Boolean
-
#initialize(publication:, most_recent_revision: nil, cover_image_url: nil) ⇒ PublicationCardComponent
constructor
A new instance of PublicationCardComponent.
- #most_recent_revision_path ⇒ Object
- #most_recent_revision_sku ⇒ Object
- #publication_path ⇒ Object
- #upload_path ⇒ Object
Constructor Details
#initialize(publication:, most_recent_revision: nil, cover_image_url: nil) ⇒ PublicationCardComponent
Returns a new instance of PublicationCardComponent.
15 16 17 18 19 20 |
# File 'app/components/crm/publication_card_component.rb', line 15 def initialize(publication:, most_recent_revision: nil, cover_image_url: nil) super() @publication = publication @most_recent_revision = most_recent_revision @cover_image_url = cover_image_url end |
Instance Attribute Details
#cover_image_url ⇒ Object (readonly)
Returns the value of attribute cover_image_url.
13 14 15 |
# File 'app/components/crm/publication_card_component.rb', line 13 def cover_image_url @cover_image_url end |
#most_recent_revision ⇒ Object (readonly)
Returns the value of attribute most_recent_revision.
13 14 15 |
# File 'app/components/crm/publication_card_component.rb', line 13 def most_recent_revision @most_recent_revision end |
#publication ⇒ Object (readonly)
Returns the value of attribute publication.
13 14 15 |
# File 'app/components/crm/publication_card_component.rb', line 13 def publication @publication end |
Instance Method Details
#category_name ⇒ Object
Uses pre-loaded product_category association to avoid N+1
37 38 39 |
# File 'app/components/crm/publication_card_component.rb', line 37 def category_name publication.product_category&.name end |
#fancybox_group ⇒ Object
Unique group per publication so clicking a cover opens only that
publication's document in the lightbox, instead of grouping every cover
on the page into a single carousel. Mirrors Crm::UploadCardComponent.
64 65 66 |
# File 'app/components/crm/publication_card_component.rb', line 64 def fancybox_group "publication-#{publication.id}" end |
#fancybox_type ⇒ Object
57 58 59 |
# File 'app/components/crm/publication_card_component.rb', line 57 def fancybox_type helpers.fancybox_type_for_upload(literature) if literature_present? end |
#has_newer_revision? ⇒ Boolean
41 42 43 |
# File 'app/components/crm/publication_card_component.rb', line 41 def has_newer_revision? most_recent_revision.present? end |
#literature ⇒ Object
Alias for Publication#literature
22 |
# File 'app/components/crm/publication_card_component.rb', line 22 delegate :literature, to: :publication |
#literature_present? ⇒ Object
Alias for Literature#present?
24 |
# File 'app/components/crm/publication_card_component.rb', line 24 delegate :present?, to: :literature, prefix: true |
#most_recent_revision_path ⇒ Object
49 50 51 |
# File 'app/components/crm/publication_card_component.rb', line 49 def most_recent_revision_path helpers.publication_path(most_recent_revision.id) if most_recent_revision end |
#most_recent_revision_sku ⇒ Object
45 46 47 |
# File 'app/components/crm/publication_card_component.rb', line 45 def most_recent_revision_sku most_recent_revision&.sku end |
#publication_name ⇒ Object
Alias for Publication#name
26 |
# File 'app/components/crm/publication_card_component.rb', line 26 delegate :name, to: :publication, prefix: true |
#publication_path ⇒ Object
32 33 34 |
# File 'app/components/crm/publication_card_component.rb', line 32 def publication_path helpers.publication_path(publication.id) end |
#publication_sku ⇒ Object
Alias for Publication#sku
28 |
# File 'app/components/crm/publication_card_component.rb', line 28 delegate :sku, to: :publication, prefix: true |
#updated_at ⇒ Object
Alias for Publication#updated_at
30 |
# File 'app/components/crm/publication_card_component.rb', line 30 delegate :updated_at, to: :publication |
#upload_path ⇒ Object
53 54 55 |
# File 'app/components/crm/publication_card_component.rb', line 53 def upload_path helpers.upload_path(literature) if literature_present? end |