Class: Www::SupportItemPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- Www::SupportItemPresenter
- Includes:
- Memery
- Defined in:
- app/presenters/www/support_item_presenter.rb
Overview
Presenter: support item presenter.
Delegated Instance Attributes collapse
-
#notices_for_side_links ⇒ Object
Alias for Product_catalog_presenter#notices_for_side_links.
-
#product_notices ⇒ Object
Alias for Product_catalog_presenter#product_notices.
-
#show_notices_section? ⇒ Object
Alias for Product_catalog_presenter#show_notices_section?.
-
#support_intro ⇒ Object
Alias for Support_product_line_presenter#support_intro.
-
#videos_grouped ⇒ Object
Alias for Retrieve_videos#videos_grouped.
Instance Method Summary collapse
- #articles ⇒ Object
- #breadcrumb ⇒ Object
- #cache_key ⇒ Object
- #can_be_purchased? ⇒ Boolean
- #display_faqs? ⇒ Boolean
- #documents(all_product_lines: false) ⇒ Object
- #documents_grouped_by_category ⇒ Object
- #dynamic_introduction ⇒ Object
- #faqs ⇒ Object
- #image_tag(options = {}) ⇒ Object
- #last_sold_date_formatted ⇒ Object
- #og_image ⇒ Object
- #page_description ⇒ Object
- #page_keywords ⇒ Object
- #page_title ⇒ Object
- #product_catalog ⇒ Object
- #product_catalog_presenter ⇒ Object
- #product_schema ⇒ Object
- #public_specifications ⇒ Object
- #public_specifications_grouped ⇒ Object
- #purchase_url ⇒ Object
-
#related_items(include_self: false) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- #retrieve_documents(all_product_lines: false) ⇒ Object
- #retrieve_videos ⇒ Object
- #sections ⇒ Object
- #sibling_items(include_self: false) ⇒ Object
- #support_portal_should_use_images? ⇒ Boolean
- #support_product_line_presenter ⇒ Object
- #title ⇒ Object
- #videos ⇒ Object
Instance Method Details
#articles ⇒ Object
82 83 84 |
# File 'app/presenters/www/support_item_presenter.rb', line 82 def articles ArticleTechnical.published.for_product_line_url_with_ancestors(primary_product_line.slug_ltree.to_s).order(:subject) end |
#breadcrumb ⇒ Object
31 32 33 34 35 |
# File 'app/presenters/www/support_item_presenter.rb', line 31 def bcs = support_product_line_presenter. bcs << { name: "#{sku} – #{item.public_name}", url: nil } h. bcs end |
#cache_key ⇒ Object
11 12 13 |
# File 'app/presenters/www/support_item_presenter.rb', line 11 def cache_key "#{I18n.locale}/v4/#{item.cache_key}" end |
#can_be_purchased? ⇒ Boolean
128 129 130 |
# File 'app/presenters/www/support_item_presenter.rb', line 128 def can_be_purchased? product_catalog.present? end |
#display_faqs? ⇒ Boolean
159 160 161 |
# File 'app/presenters/www/support_item_presenter.rb', line 159 def display_faqs? faqs.present? end |
#documents(all_product_lines: false) ⇒ Object
61 62 63 |
# File 'app/presenters/www/support_item_presenter.rb', line 61 def documents(all_product_lines: false) retrieve_documents(all_product_lines:).all_publications end |
#documents_grouped_by_category ⇒ Object
66 67 68 69 |
# File 'app/presenters/www/support_item_presenter.rb', line 66 def documents_grouped_by_category documents.sort_by { |d| [d.star? ? 0 : 1, d.featured_position.to_i, d.name.to_s] } .group_by(&:product_category_name) end |
#dynamic_introduction ⇒ Object
163 164 165 166 167 168 169 170 171 |
# File 'app/presenters/www/support_item_presenter.rb', line 163 def dynamic_introduction contents = [] contents += %w[publications manuals] if retrieve_documents.present? contents << 'specifications' if public_specifications.present? contents << 'videos' if videos_grouped.present? contents << 'support articles' if articles.present? contents << 'common support questions' if display_faqs? "This support page provides #{contents.to_sentence}" end |
#faqs ⇒ Object
87 88 89 |
# File 'app/presenters/www/support_item_presenter.rb', line 87 def faqs Item::ArticleRetriever.new(article_types: %w[faq], support: true, add_vote_data: true).process(item:).articles end |
#image_tag(options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'app/presenters/www/support_item_presenter.rb', line 49 def image_tag( = {}) return unless primary_image && primary_image. > 300 = .merge({ width: 400, height: 400, background: 'ffffff' }) h.image_asset_tag(primary_image, ) end |
#last_sold_date_formatted ⇒ Object
42 43 44 45 46 |
# File 'app/presenters/www/support_item_presenter.rb', line 42 def last_sold_date_formatted return unless (item.is_discontinued || !item.is_available_to_public?) && item.last_sale_date item.last_sale_date.strftime('%B %Y') end |
#notices_for_side_links ⇒ Object
Alias for Product_catalog_presenter#notices_for_side_links
9 |
# File 'app/presenters/www/support_item_presenter.rb', line 9 delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true |
#og_image ⇒ Object
27 28 29 |
# File 'app/presenters/www/support_item_presenter.rb', line 27 def og_image item.image_url2(size: '400x400') end |
#page_description ⇒ Object
19 20 21 |
# File 'app/presenters/www/support_item_presenter.rb', line 19 def page_description "Support page for #{item.effective_seo_title} - #{item.sku}. Installation guides, specifications, wiring diagrams, operation manuals and more. Provided by #{h.company_locale}" end |
#page_keywords ⇒ Object
23 24 25 |
# File 'app/presenters/www/support_item_presenter.rb', line 23 def page_keywords [sku, public_name, 'Support', 'Specifications', 'Documents', 'Videos', 'Manuals', 'Articles'].join(',') end |
#page_title ⇒ Object
15 16 17 |
# File 'app/presenters/www/support_item_presenter.rb', line 15 def page_title "#{sku} | Support | #{h.company_locale}" end |
#product_catalog ⇒ Object
132 133 134 |
# File 'app/presenters/www/support_item_presenter.rb', line 132 def product_catalog @product_catalog ||= ViewProductCatalog.where(catalog_id: Catalog.locale_to_catalog_id).where(item_id: item.id).where(item_is_web_accessible: true).first end |
#product_catalog_presenter ⇒ Object
136 137 138 139 140 |
# File 'app/presenters/www/support_item_presenter.rb', line 136 def product_catalog_presenter return nil unless product_catalog @product_catalog_presenter ||= Www::ProductCatalogPresenter.new(product_catalog, h) end |
#product_notices ⇒ Object
Alias for Product_catalog_presenter#product_notices
9 |
# File 'app/presenters/www/support_item_presenter.rb', line 9 delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true |
#product_schema ⇒ Object
142 143 144 145 146 |
# File 'app/presenters/www/support_item_presenter.rb', line 142 def product_schema return nil unless product_catalog product_catalog_presenter&.schema_dot_org_structure end |
#public_specifications ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/presenters/www/support_item_presenter.rb', line 92 def public_specifications # For kits we break specs down per component so visitors can compare each unit. # Exception: spare-parts kits (e.g. AK* parts kits) contain many small commodity # components whose individual specs (SKU, UPC, weight) are meaningless when listed # separately — show the kit-level specs instead. if is_kit? && !parts_kit? item.get_kit_items(spec_only: true).flat_map do |ki| ki.public_specifications.map do |s| s.grouping = "#{s.grouping} (#{ki.sku})" s end end else item.public_specifications end end |
#public_specifications_grouped ⇒ Object
110 111 112 |
# File 'app/presenters/www/support_item_presenter.rb', line 110 def public_specifications_grouped public_specifications.sort_by(&:name).group_by(&:grouping) end |
#purchase_url ⇒ Object
148 149 150 151 152 |
# File 'app/presenters/www/support_item_presenter.rb', line 148 def purchase_url h.catalog_link(item) rescue ArgumentError nil end |
#related_items(include_self: false) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
121 122 123 124 125 |
# File 'app/presenters/www/support_item_presenter.rb', line 121 def (include_self: false) # rubocop:disable Lint/UnusedMethodArgument r_items = [] r_items += Item::Materials::CompatibleControls.new.process(item:, context: :support).items r_items + Item::Materials::CompatibleAccessories.new.process(item:, context: :support).items end |
#retrieve_documents(all_product_lines: false) ⇒ Object
56 57 58 |
# File 'app/presenters/www/support_item_presenter.rb', line 56 def retrieve_documents(all_product_lines: false) Item::PublicationRetriever.new.process(sku, categories: [:support], all_product_lines:) end |
#retrieve_videos ⇒ Object
71 72 73 |
# File 'app/presenters/www/support_item_presenter.rb', line 71 def retrieve_videos Item::VideoRetriever.new(tags: 'for-support-page', ignore_individual_query_limits: true).process(item) end |
#sections ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/presenters/www/support_item_presenter.rb', line 177 def sections s = {} if show_notices_section? notices = product_notices s[:notices] = { title: 'Notices', counter: notices.size, partial: 'www/support_portals/section_notices', data: notices, fa_icon: 'info-circle' } end s[:faqs] = { title: 'Support Questions', counter: faqs.size, partial: 'www/support_portals/section_faqs', data: faqs, referral_sku: item.sku, pl: item.primary_product_line, fa_icon: 'question-mark' } if display_faqs? if retrieve_documents.present? s[:publications] = { title: 'Documents', counter: documents.size, component: Www::SupportPublicationsComponent, component_args: { publications_by_category: documents_grouped_by_category }, fa_icon: 'publication' } end if public_specifications.present? s[:specifications] = { title: 'Specifications', counter: public_specifications.size, component: Www::SupportSpecificationsComponent, component_args: { specifications_grouped: public_specifications_grouped }, fa_icon: 'specifications' } end s[:videos] = { title: 'Videos', counter: videos.size, partial: 'www/support_portals/section_videos', data: videos_grouped, pl: item.primary_product_line, fa_icon: 'video' } if videos_grouped.present? s[:articles] = { title: 'Articles', counter: articles.size, partial: 'www/support_portals/section_articles_links', data: articles, pl: item.primary_product_line, fa_icon: 'document' } if articles.present? s[:related_items] = { title: 'Related Items', counter: .size, partial: 'www/support_portals/section_related_items_with_images', data: } if .present? if sibling_items.present? partial = support_portal_should_use_images? ? 'www/support_portals/section_related_items_with_images' : 'www/support_portals/section_related_items' s[:sibling_items] = { title: 'Similar Items', counter: sibling_items.size, partial:, data: sibling_items } end s end |
#show_notices_section? ⇒ Object
Alias for Product_catalog_presenter#show_notices_section?
9 |
# File 'app/presenters/www/support_item_presenter.rb', line 9 delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true |
#sibling_items(include_self: false) ⇒ Object
114 115 116 117 118 |
# File 'app/presenters/www/support_item_presenter.rb', line 114 def sibling_items(include_self: false) sibling_items = item_grouping_info(include_self:, context: :support)&.variants || Item.none sibling_items.non_publications.where(visible_for_support: true) .includes(:primary_image, :primary_product_line) end |
#support_intro ⇒ Object
Alias for Support_product_line_presenter#support_intro
8 |
# File 'app/presenters/www/support_item_presenter.rb', line 8 delegate :support_intro, to: :support_product_line_presenter |
#support_portal_should_use_images? ⇒ Boolean
173 174 175 |
# File 'app/presenters/www/support_item_presenter.rb', line 173 def support_portal_should_use_images? primary_product_line&.support_portal_should_use_images end |
#support_product_line_presenter ⇒ Object
154 155 156 |
# File 'app/presenters/www/support_item_presenter.rb', line 154 def support_product_line_presenter Www::SupportProductLinePresenter.new(item.primary_product_line, @view) end |
#title ⇒ Object
38 39 40 |
# File 'app/presenters/www/support_item_presenter.rb', line 38 def title item.public_name end |
#videos ⇒ Object
76 77 78 |
# File 'app/presenters/www/support_item_presenter.rb', line 76 def videos retrieve_videos.all_videos end |
#videos_grouped ⇒ Object
Alias for Retrieve_videos#videos_grouped
80 |
# File 'app/presenters/www/support_item_presenter.rb', line 80 delegate :videos_grouped, to: :retrieve_videos |