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_urlsHash?

Locale-agnostic download URLs when the publication serves all locales.

Returns:

  • (Hash, nil)

    PDF and HTML URLs, or nil



43
44
45
46
47
48
49
50
# File 'app/presenters/crm/publication_presenter.rb', line 43

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_urlsArray<Hash>

Per-locale download URLs and country names for the publication.

Returns:

  • (Array<Hash>)

    one entry per available service locale



30
31
32
33
34
35
36
37
38
39
# File 'app/presenters/crm/publication_presenter.rb', line 30

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:



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

delegate :cover_image_url, to: :publication

#has_attachment?Boolean?

Whether the publication has a stored literature attachment.

Returns:

  • (Boolean, nil)

    true when an attachment is stored



56
57
58
# File 'app/presenters/crm/publication_presenter.rb', line 56

def has_attachment?
  publication.literature&.attachment_stored?
end

#publication_tab_optionsHash{Symbol => Hash}

Tab definitions for the CRM publication detail page.

Returns:

  • (Hash{Symbol => Hash})

    tab options keyed by tab name



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

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

#revisions_countInteger

Number of revisions in the publication's revision chain.

Returns:

  • (Integer)

    revision count



24
25
26
# File 'app/presenters/crm/publication_presenter.rb', line 24

def revisions_count
  publication.revision_chain.size
end