Class: Crm::ProductLinePresenter

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

Overview

Presenter: product line presenter.

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

This class inherits a constructor from Crm::BasePresenter

Instance Method Details

Link to refresh the product line cache.

Returns:

  • (ActiveSupport::SafeBuffer)

    refresh link HTML



73
74
75
76
# File 'app/presenters/crm/product_line_presenter.rb', line 73

def cache_link
  options[:class] ||= 'btn btn-outline-primary'
  h.link_to('Refresh Cache', h.refresh_cache_product_line_path, **options)
end

Renders a link to create a sub product line under this one.

Parameters:

  • options (Hash) (defaults to: {})

    html options forwarded to link_to

Options Hash (options):

  • class (String)

    CSS classes, defaults to 'btn btn-outline-primary'

Returns:

  • (String, nil)

    HTML link, or nil when not permitted



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

def create_sub_product_line_link(options = {})
  return unless h.can?(:create, ProductLine)

  options[:class] ||= 'btn btn-outline-primary'
  h.link_to(h.fa_icon('plus-circle', text: 'Add Sub Product Line'),
        h.new_product_line_path(parent_id: r.id),
        **options)
end

Link to delete the product line.

Returns:

  • (ActiveSupport::SafeBuffer)

    delete link HTML



15
16
17
# File 'app/presenters/crm/product_line_presenter.rb', line 15

def delete_link
  h.delete_link r
end

Link to edit the product line.

Returns:

  • (ActiveSupport::SafeBuffer)

    edit link HTML



9
10
11
# File 'app/presenters/crm/product_line_presenter.rb', line 9

def edit_link
  h.edit_link r
end

#headingsArray<ProductLine>

Expanded lineage for heading display.

Returns:



21
22
23
# File 'app/presenters/crm/product_line_presenter.rb', line 21

def headings
  r.lineage_expanded
end

#product_line_breadcrumb(params = {}) ⇒ ActiveSupport::SafeBuffer

Breadcrumb items from Items/Product Lines down to this line's ancestors.

Parameters:

  • params (Hash) (defaults to: {})

    request params; :tab anchors ancestor links

Returns:

  • (ActiveSupport::SafeBuffer)

    breadcrumb <li> HTML



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

def product_line_breadcrumb(params = {})
  capture do
    concat (:li, link_to('Items', h.items_path), class: 'breadcrumb-item')
    concat (:li, link_to('Product Lines', h.product_lines_path), class: 'breadcrumb-item')
    product_line.ancestors.reverse_each do |pl|
      concat h.tag.li(h.link_to(pl.name.presence || pl.name_en, h.product_line_path(pl, anchor: params[:tab])), class: 'breadcrumb-item')
    end
  end
end

#product_line_tab_options(params = {}) ⇒ Hash{Symbol => Hash}

Tab definitions for the CRM product line detail page.

Parameters:

  • params (Hash) (defaults to: {})

    request params; :show_inactive is passed through

Returns:

  • (Hash{Symbol => Hash})

    tab options keyed by tab name



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/presenters/crm/product_line_presenter.rb', line 55

def product_line_tab_options(params = {})
  tabs = %i[main_attributes descriptions seo specifications items publications digital_assets]
  params.slice!(:show_inactive)
  tabs_hsh = tabs.each_with_object({}) do |tab, hsh|
    route_method = "tab_#{tab}_product_line_path"
    # Pass the record (not r.id) so the href carries to_param — the same
    # identifier spelling the pane's frame id is built from. Mixing the
    # numeric id into hrefs while the show URL used the FriendlyId slug made
    # every tab fetch look like a cross-record breakout.
    hsh[tab] = { remote_href: h.send(route_method, r, params) }
  end
  # Allow the :q param to pass through
  tabs_hsh[:items][:param_keys] = [:q]
  tabs_hsh
end