Class: QuickSearch::ContactPointPresenter
- Inherits:
-
PinPresenter
- Object
- PinPresenter
- QuickSearch::ContactPointPresenter
- Defined in:
- app/presenters/quick_search/contact_point_presenter.rb
Overview
Presents a ContactPoint as a quick search result / pinned item, delegating
the card content to the underlying party's presenter conventions.
Instance Method Summary collapse
-
#contact_status_badge_html ⇒ String
HTML badge for the contact's active/inactive status.
-
#customer_state_badge_html ⇒ String
HTML badge for the customer state.
-
#date_badge_html(date) ⇒ String
HTML badge showing the formatted date.
-
#party_badges ⇒ String?
Use the same badge logic as the party's presenter would use.
-
#presenting_context?(context_type, context_id) ⇒ Boolean
Whether this contact point belongs to the party currently being viewed.
-
#profile_image_url ⇒ String?
The party's 80x80 profile image URL, or nil.
-
#set_attributes ⇒ void
Sets the card title, link, reference number, and party badges from the contact point's party; marks the pin invalid when there is no party.
-
#text_sub_header ⇒ String?
Use the same text_sub_header logic as the party's presenter would use.
Instance Method Details
#contact_status_badge_html ⇒ String
Returns HTML badge for the contact's active/inactive status.
56 57 58 59 60 61 62 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 56 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_html ⇒ String
Returns HTML badge for the customer state.
44 45 46 47 48 49 50 51 52 53 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 44 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) ⇒ String
Returns HTML badge showing the formatted date.
66 67 68 69 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 66 def date_badge_html(date) formatted = h.render_date(date) %(<span class="badge bg-light text-dark border">#{formatted}</span>) end |
#party_badges ⇒ String?
Use the same badge logic as the party's presenter would use
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 28 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(' ') end end |
#presenting_context?(context_type, context_id) ⇒ Boolean
Whether this contact point belongs to the party currently being viewed.
99 100 101 102 103 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 99 def presenting_context?(context_type, context_id) return false unless context_type.present? && context_id.present? (result.resource.party_id == context_id.to_i and %w[Party Customer Contact].include?(context_type)) end |
#profile_image_url ⇒ String?
Returns the party's 80x80 profile image URL, or nil.
88 89 90 91 92 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 88 def profile_image_url return if result.party&.profile_image.blank? result.party.profile_image.image_url(width: 80, height: 80) end |
#set_attributes ⇒ void
This method returns an undefined value.
Sets the card title, link, reference number, and party badges from the
contact point's party; marks the pin invalid when there is no party.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 12 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_header ⇒ String?
Use the same text_sub_header logic as the party's presenter would use
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/presenters/quick_search/contact_point_presenter.rb', line 74 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 end end |