Class: QuickSearch::ContactPointPresenter

Inherits:
PinPresenter
  • Object
show all
Defined in:
app/presenters/quick_search/contact_point_presenter.rb

Instance Method Summary collapse

Instance Method Details

#contact_status_badge_htmlObject



44
45
46
47
48
49
50
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 44

def contact_status_badge_html
  if result.party.inactive?
    '<span class="badge bg-warning text-dark">Inactive</span>'
  else
    '<span class="badge bg-success">Active</span>'
  end
end

#customer_state_badge_htmlObject



33
34
35
36
37
38
39
40
41
42
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 33

def customer_state_badge_html
  color = case result.party.state&.to_s
          when 'active' then 'success'
          when 'lead', 'prospect' then 'info'
          when 'inactive', 'on_hold' then 'warning'
          when 'do_not_contact', 'bad_debt' then 'danger'
          else 'secondary'
          end
  %(<span class="badge bg-#{color}">#{result.party.human_state_name}</span>)
end

#date_badge_html(date) ⇒ Object



52
53
54
55
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 52

def date_badge_html(date)
  formatted = h.render_date(date)
  %(<span class="badge bg-light text-dark border">#{formatted}</span>)
end

#party_badgesObject

Use the same badge logic as the party's presenter would use



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 16

def party_badges
  case result.party
  when Customer
    badges = []
    badges << customer_state_badge_html if result.party.state.present?
    badges << date_badge_html(result.party.created_at) if result.party.created_at.present?
    badges.compact.join(' ')
  when Contact
    badges = []
    badges << contact_status_badge_html
    badges << date_badge_html(result.party.created_at) if result.party.created_at.present?
    badges.compact.join(' ')
  else
    nil
  end
end

#presenting_context?(context_type, context_id) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 79

def presenting_context?(context_type, context_id)
  return false unless context_type.present? and context_id.present?
  match = (result.resource.party_id == context_id.to_i and ['Party', 'Customer', 'Contact'].include?(context_type))
  match
end

#profile_image_urlObject



73
74
75
76
77
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 73

def profile_image_url
  return unless result.party&.profile_image.present?

  result.party.profile_image.image_url(width: 80, height: 80)
end

#set_attributesObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 2

def set_attributes
  if result.party
    @title = result.party.full_name
    @link = polymorphic_path(result.party)
    @reference_number = result.party.try(:reference_number)
    set_result_class(result.party)
    # Delegate sub_header to party-specific logic (same as if you searched the party directly)
    @sub_header = party_badges
  else
    @invalid = true
  end
end

#text_sub_headerObject

Use the same text_sub_header logic as the party's presenter would use



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 58

def text_sub_header
  case result.party
  when Customer
    [result.party.location_name, result.party.primary_sales_rep_name].compact_blank.join('')
  when Contact
    [result.party.customer&.full_name, result.party.job_title].compact_blank.join('')
  when Employee
    result.party.job_title
  when Supplier
    result.party.location_name
  else
    nil
  end
end