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.
Instance Method Summary collapse
-
#category_name ⇒ Object
Uses pre-loaded product_category association to avoid N+1.
- #counter_text ⇒ Object
- #fancybox_type ⇒ Object
- #has_newer_revision? ⇒ Boolean
-
#initialize(publication:, most_recent_revision: nil, cover_image_url: nil) ⇒ PublicationCardComponent
constructor
A new instance of PublicationCardComponent.
- #literature ⇒ Object
- #literature_present? ⇒ Boolean
- #most_recent_revision_path ⇒ Object
- #most_recent_revision_sku ⇒ Object
- #publication_name ⇒ Object
- #publication_path ⇒ Object
- #publication_sku ⇒ Object
- #requested_counter ⇒ Object
- #upload_path ⇒ Object
Constructor Details
#initialize(publication:, most_recent_revision: nil, cover_image_url: nil) ⇒ PublicationCardComponent
Returns a new instance of PublicationCardComponent.
16 17 18 19 20 21 |
# File 'app/components/crm/publication_card_component.rb', line 16 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.
14 15 16 |
# File 'app/components/crm/publication_card_component.rb', line 14 def cover_image_url @cover_image_url end |
#most_recent_revision ⇒ Object (readonly)
Returns the value of attribute most_recent_revision.
14 15 16 |
# File 'app/components/crm/publication_card_component.rb', line 14 def most_recent_revision @most_recent_revision end |
#publication ⇒ Object (readonly)
Returns the value of attribute publication.
14 15 16 |
# File 'app/components/crm/publication_card_component.rb', line 14 def publication @publication end |
Instance Method Details
#category_name ⇒ Object
Uses pre-loaded product_category association to avoid N+1
44 45 46 |
# File 'app/components/crm/publication_card_component.rb', line 44 def category_name publication.product_category&.name end |
#counter_text ⇒ Object
52 53 54 |
# File 'app/components/crm/publication_card_component.rb', line 52 def counter_text "Requested #{requested_counter} #{'time'.pluralize(requested_counter)}" end |
#fancybox_type ⇒ Object
72 73 74 |
# File 'app/components/crm/publication_card_component.rb', line 72 def fancybox_type helpers.fancybox_type_for_upload(literature) if literature_present? end |
#has_newer_revision? ⇒ Boolean
56 57 58 |
# File 'app/components/crm/publication_card_component.rb', line 56 def has_newer_revision? most_recent_revision.present? end |
#literature ⇒ Object
23 24 25 |
# File 'app/components/crm/publication_card_component.rb', line 23 def literature publication.literature end |
#literature_present? ⇒ Boolean
27 28 29 |
# File 'app/components/crm/publication_card_component.rb', line 27 def literature_present? literature.present? end |
#most_recent_revision_path ⇒ Object
64 65 66 |
# File 'app/components/crm/publication_card_component.rb', line 64 def most_recent_revision_path helpers.publication_path(most_recent_revision.id) if most_recent_revision end |
#most_recent_revision_sku ⇒ Object
60 61 62 |
# File 'app/components/crm/publication_card_component.rb', line 60 def most_recent_revision_sku most_recent_revision&.sku end |
#publication_name ⇒ Object
31 32 33 |
# File 'app/components/crm/publication_card_component.rb', line 31 def publication_name publication.name end |
#publication_path ⇒ Object
39 40 41 |
# File 'app/components/crm/publication_card_component.rb', line 39 def publication_path helpers.publication_path(publication.id) end |
#publication_sku ⇒ Object
35 36 37 |
# File 'app/components/crm/publication_card_component.rb', line 35 def publication_sku publication.sku end |
#requested_counter ⇒ Object
48 49 50 |
# File 'app/components/crm/publication_card_component.rb', line 48 def requested_counter publication.requested_counter end |
#upload_path ⇒ Object
68 69 70 |
# File 'app/components/crm/publication_card_component.rb', line 68 def upload_path helpers.upload_path(literature) if literature_present? end |