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 ⇒ Publication?
readonly
Precomputed most recent revision of the publication, if one exists.
-
#publication ⇒ Publication
readonly
The publication being rendered.
Delegated Instance Attributes collapse
-
#literature ⇒ Upload?
The publication's uploaded document.
-
#literature_present? ⇒ Boolean
Whether the publication has an uploaded document.
-
#publication_name ⇒ String
The publication's name.
-
#publication_sku ⇒ String
The publication's SKU.
-
#updated_at ⇒ ActiveSupport::TimeWithZone
When the publication was last updated.
Instance Method Summary collapse
-
#category_name ⇒ String?
Uses pre-loaded product_category association to avoid N+1.
-
#fancybox_group ⇒ String
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 ⇒ String?
Fancybox content type for the uploaded document.
-
#has_newer_revision? ⇒ Boolean
Whether a newer revision of this publication exists.
-
#initialize(publication:, most_recent_revision: nil, cover_image_url: nil) ⇒ PublicationCardComponent
constructor
A new instance of PublicationCardComponent.
-
#most_recent_revision_path ⇒ String?
URL path to the most recent revision's detail page.
-
#most_recent_revision_sku ⇒ String?
SKU of the most recent revision, if any.
-
#publication_path ⇒ String
URL path to this publication's detail page.
-
#upload_path ⇒ String?
URL path to the uploaded document, if one exists.
Constructor Details
#initialize(publication:, most_recent_revision: nil, cover_image_url: nil) ⇒ PublicationCardComponent
Returns a new instance of PublicationCardComponent.
26 27 28 29 30 31 |
# File 'app/components/crm/publication_card_component.rb', line 26 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.
20 |
# File 'app/components/crm/publication_card_component.rb', line 20 attr_reader :publication, :most_recent_revision, :cover_image_url |
#most_recent_revision ⇒ Publication? (readonly)
Returns precomputed most recent revision of the
publication, if one exists.
20 |
# File 'app/components/crm/publication_card_component.rb', line 20 attr_reader :publication, :most_recent_revision, :cover_image_url |
#publication ⇒ Publication (readonly)
Returns the publication being rendered.
20 21 22 |
# File 'app/components/crm/publication_card_component.rb', line 20 def publication @publication end |
Instance Method Details
#category_name ⇒ String?
Uses pre-loaded product_category association to avoid N+1
60 61 62 |
# File 'app/components/crm/publication_card_component.rb', line 60 def category_name publication.product_category&.name end |
#fancybox_group ⇒ String
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.
93 94 95 |
# File 'app/components/crm/publication_card_component.rb', line 93 def fancybox_group "publication-#{publication.id}" end |
#fancybox_type ⇒ String?
Returns Fancybox content type for the uploaded document.
85 86 87 |
# File 'app/components/crm/publication_card_component.rb', line 85 def fancybox_type helpers.fancybox_type_for_upload(literature) if literature_present? end |
#has_newer_revision? ⇒ Boolean
Returns whether a newer revision of this publication exists.
65 66 67 |
# File 'app/components/crm/publication_card_component.rb', line 65 def has_newer_revision? most_recent_revision.present? end |
#literature ⇒ Upload?
Returns the publication's uploaded document.
35 |
# File 'app/components/crm/publication_card_component.rb', line 35 delegate :literature, to: :publication |
#literature_present? ⇒ Boolean
Returns whether the publication has an uploaded document.
39 |
# File 'app/components/crm/publication_card_component.rb', line 39 delegate :present?, to: :literature, prefix: true |
#most_recent_revision_path ⇒ String?
Returns URL path to the most recent revision's detail page.
75 76 77 |
# File 'app/components/crm/publication_card_component.rb', line 75 def most_recent_revision_path helpers.publication_path(most_recent_revision.id) if most_recent_revision end |
#most_recent_revision_sku ⇒ String?
Returns SKU of the most recent revision, if any.
70 71 72 |
# File 'app/components/crm/publication_card_component.rb', line 70 def most_recent_revision_sku most_recent_revision&.sku end |
#publication_name ⇒ String
Returns the publication's name.
43 |
# File 'app/components/crm/publication_card_component.rb', line 43 delegate :name, to: :publication, prefix: true |
#publication_path ⇒ String
Returns URL path to this publication's detail page.
54 55 56 |
# File 'app/components/crm/publication_card_component.rb', line 54 def publication_path helpers.publication_path(publication.id) end |
#publication_sku ⇒ String
Returns the publication's SKU.
47 |
# File 'app/components/crm/publication_card_component.rb', line 47 delegate :sku, to: :publication, prefix: true |
#updated_at ⇒ ActiveSupport::TimeWithZone
Returns when the publication was last updated.
51 |
# File 'app/components/crm/publication_card_component.rb', line 51 delegate :updated_at, to: :publication |
#upload_path ⇒ String?
Returns URL path to the uploaded document, if one exists.
80 81 82 |
# File 'app/components/crm/publication_card_component.rb', line 80 def upload_path helpers.upload_path(literature) if literature_present? end |