Class: Www::SupportItemPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- Www::SupportItemPresenter
- Includes:
- Memery
- Defined in:
- app/presenters/www/support_item_presenter.rb
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
80 81 82 |
# File 'app/presenters/www/support_item_presenter.rb', line 80 def articles ArticleTechnical.published.for_product_line_url_with_ancestors(primary_product_line.slug_ltree.to_s).order(:subject) end |
#breadcrumb ⇒ Object
29 30 31 32 33 |
# File 'app/presenters/www/support_item_presenter.rb', line 29 def bcs = support_product_line_presenter. bcs << { name: "#{sku} – #{item.public_name}", url: nil } h. bcs end |
#cache_key ⇒ Object
9 10 11 |
# File 'app/presenters/www/support_item_presenter.rb', line 9 def cache_key "#{I18n.locale}/v4/#{item.cache_key}" end |
#can_be_purchased? ⇒ Boolean
126 127 128 |
# File 'app/presenters/www/support_item_presenter.rb', line 126 def can_be_purchased? product_catalog.present? end |
#display_faqs? ⇒ Boolean
157 158 159 |
# File 'app/presenters/www/support_item_presenter.rb', line 157 def display_faqs? faqs.present? end |
#documents(all_product_lines: false) ⇒ Object
59 60 61 |
# File 'app/presenters/www/support_item_presenter.rb', line 59 def documents(all_product_lines: false) retrieve_documents(all_product_lines:).all_publications end |
#documents_grouped_by_category ⇒ Object
64 65 66 67 |
# File 'app/presenters/www/support_item_presenter.rb', line 64 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
161 162 163 164 165 166 167 168 169 170 171 |
# File 'app/presenters/www/support_item_presenter.rb', line 161 def dynamic_introduction str = 'This support page provides ' 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? str << contents.to_sentence str end |
#faqs ⇒ Object
85 86 87 |
# File 'app/presenters/www/support_item_presenter.rb', line 85 def faqs Item::ArticleRetriever.new(article_types: %w[faq], support: true, add_vote_data: true).process(item:).articles end |
#image_tag(options = {}) ⇒ Object
47 48 49 50 51 52 |
# File 'app/presenters/www/support_item_presenter.rb', line 47 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
40 41 42 43 44 |
# File 'app/presenters/www/support_item_presenter.rb', line 40 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
7 |
# File 'app/presenters/www/support_item_presenter.rb', line 7 delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true |
#og_image ⇒ Object
25 26 27 |
# File 'app/presenters/www/support_item_presenter.rb', line 25 def og_image item.image_url2(size: '400x400') end |
#page_description ⇒ Object
17 18 19 |
# File 'app/presenters/www/support_item_presenter.rb', line 17 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
21 22 23 |
# File 'app/presenters/www/support_item_presenter.rb', line 21 def page_keywords [sku, public_name, 'Support', 'Specifications', 'Documents', 'Videos', 'Manuals', 'Articles'].join(',') end |
#page_title ⇒ Object
13 14 15 |
# File 'app/presenters/www/support_item_presenter.rb', line 13 def page_title "#{sku} | Support | #{h.company_locale}" end |
#product_catalog ⇒ Object
130 131 132 |
# File 'app/presenters/www/support_item_presenter.rb', line 130 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
134 135 136 137 138 |
# File 'app/presenters/www/support_item_presenter.rb', line 134 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
7 |
# File 'app/presenters/www/support_item_presenter.rb', line 7 delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true |
#product_schema ⇒ Object
140 141 142 143 144 |
# File 'app/presenters/www/support_item_presenter.rb', line 140 def product_schema return nil unless product_catalog product_catalog_presenter&.schema_dot_org_structure end |
#public_specifications ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/presenters/www/support_item_presenter.rb', line 90 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
108 109 110 |
# File 'app/presenters/www/support_item_presenter.rb', line 108 def public_specifications_grouped public_specifications.sort_by(&:name).group_by(&:grouping) end |
#purchase_url ⇒ Object
146 147 148 149 150 |
# File 'app/presenters/www/support_item_presenter.rb', line 146 def purchase_url h.catalog_link(item) rescue ArgumentError nil end |
#related_items(include_self: false) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
119 120 121 122 123 |
# File 'app/presenters/www/support_item_presenter.rb', line 119 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
54 55 56 |
# File 'app/presenters/www/support_item_presenter.rb', line 54 def retrieve_documents(all_product_lines: false) Item::PublicationRetriever.new.process(sku, categories: [:support], all_product_lines:) end |
#retrieve_videos ⇒ Object
69 70 71 |
# File 'app/presenters/www/support_item_presenter.rb', line 69 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 205 206 |
# 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? if .present? s[:related_items] = { title: 'Related Items', counter: .size, partial: 'www/support_portals/section_related_items_with_images', data: } end 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?
7 |
# File 'app/presenters/www/support_item_presenter.rb', line 7 delegate :product_notices, :show_notices_section?, :notices_for_side_links, to: :product_catalog_presenter, allow_nil: true |
#sibling_items(include_self: false) ⇒ Object
112 113 114 115 116 |
# File 'app/presenters/www/support_item_presenter.rb', line 112 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
6 |
# File 'app/presenters/www/support_item_presenter.rb', line 6 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
152 153 154 |
# File 'app/presenters/www/support_item_presenter.rb', line 152 def support_product_line_presenter Www::SupportProductLinePresenter.new(item.primary_product_line, @view) end |
#title ⇒ Object
36 37 38 |
# File 'app/presenters/www/support_item_presenter.rb', line 36 def title item.public_name end |
#videos ⇒ Object
74 75 76 |
# File 'app/presenters/www/support_item_presenter.rb', line 74 def videos retrieve_videos.all_videos end |
#videos_grouped ⇒ Object
Alias for Retrieve_videos#videos_grouped
78 |
# File 'app/presenters/www/support_item_presenter.rb', line 78 delegate :videos_grouped, to: :retrieve_videos |