Class: Crm::PublicationPresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/crm/publication_presenter.rb

Overview

Presenter: publication presenter.

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Delegated Instance Attributes collapse

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #link_to, #number_to_currency, #simple_format

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Methods inherited from BasePresenter

#h, #initialize, #present, presents, #r, #safe_present, #u

Constructor Details

This class inherits a constructor from Crm::BasePresenter

Instance Method Details

#auto_locale_urlsObject



35
36
37
38
39
40
41
42
# File 'app/presenters/crm/publication_presenter.rb', line 35

def auto_locale_urls
  return nil unless publication.available_to_all_locales?

  {
    pdf_url: h.publication_url(id: publication.sku, locale: '', host: WEB_URL, format: :pdf),
    html_url: h.publication_url(id: publication.sku, locale: '', host: WEB_URL)
  }
end

#available_service_locales_with_urlsObject



24
25
26
27
28
29
30
31
32
33
# File 'app/presenters/crm/publication_presenter.rb', line 24

def available_service_locales_with_urls
  publication.available_service_locales.map do |locale|
    {
      locale: locale,
      country_name: LocaleUtility.iso3166_for_locale(locale).common_name,
      pdf_url: h.publication_url(id: publication.sku, locale: locale, host: WEB_URL, format: :pdf),
      html_url: h.publication_url(id: publication.sku, locale: locale, host: WEB_URL)
    }
  end
end

#cover_image_urlObject

Alias for Publication#cover_image_url

Returns:

  • (Object)

    Publication#cover_image_url

See Also:



44
# File 'app/presenters/crm/publication_presenter.rb', line 44

delegate :cover_image_url, to: :publication

#has_attachment?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/presenters/crm/publication_presenter.rb', line 46

def has_attachment?
  publication.literature&.attachment_stored?
end

#publication_tab_optionsObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/presenters/crm/publication_presenter.rb', line 7

def publication_tab_options
  tabs = {}
  tabs[:overview] = { remote_href: h.tab_overview_publication_path(r.id) }
  tabs[:attributes] = { remote_href: h.tab_attributes_publication_path(r.id) }
  tabs[:description] = { remote_href: h.tab_description_publication_path(r.id) } if publication.detailed_description_html.present?
  tabs[:ai_embedding] = { remote_href: h.tab_ai_embedding_publication_path(r.id) }
  tabs[:revisions] = { remote_href: h.tab_revisions_publication_path(r.id), counter: revisions_count }
  tabs[:store_items] = { remote_href: h.tab_store_items_publication_path(r.id), counter: publication.store_items.size }
  tabs[:catalogs] = { remote_href: h.tab_catalogs_publication_path(r.id), counter: publication.catalog_items.size }
  tabs[:specific_items] = { remote_href: h.tab_specific_items_publication_path(r.id), counter: publication.specific_items.size } if publication.specific_items.any?
  tabs
end

#revisions_countObject



20
21
22
# File 'app/presenters/crm/publication_presenter.rb', line 20

def revisions_count
  Item.publications.where('sku ILIKE ?', "#{publication.canonical_sku}%").count
end