Class: Search::OpportunityPresenter

Inherits:
BasePresenter
  • Object
show all
Includes:
Presenters::Timeable
Defined in:
app/presenters/search/opportunity_presenter.rb

Overview

HTML presenter for opportunity search results backed by ViewOpportunity.

Direct Known Subclasses

OpportunityTextPresenter

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

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 BasePresenter

Instance Method Details

#close_dateString

Returns the close date formatted for display.

Returns:

  • (String)


52
53
54
# File 'app/presenters/search/opportunity_presenter.rb', line 52

def close_date
  h.render_date r.close_date
end

#contact_buttonActiveSupport::SafeBuffer

Returns a dropdown of callable contact point dial links.

Returns:

  • (ActiveSupport::SafeBuffer)


103
104
105
106
# File 'app/presenters/search/opportunity_presenter.rb', line 103

def contact_button
  list = r.callable_contact_points_array.map { |cp| h.sip_dial_link(h.number_to_phone(cp.detail), cp.detail, party_id: cp.party_id) }
  h.render_simple_drop_down list, main_link_class: 'btn-link'
end

Returns a link to the associated contact, if available.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


29
30
31
32
33
# File 'app/presenters/search/opportunity_presenter.rb', line 29

def contact_link
  return unless r.has_columns?(:contact_id, :contact_full_name)

  h.link_to r.contact_full_name, h.contact_path(r.contact_id)
end

Returns a link to the associated customer.

Returns:

  • (ActiveSupport::SafeBuffer)


22
23
24
# File 'app/presenters/search/opportunity_presenter.rb', line 22

def customer_link
  h.link_to r.customer_full_name, h.customer_path(r.customer_id)
end

#distanceString?

Returns the distance formatted with a "mi" suffix, if present.

Returns:

  • (String, nil)


80
81
82
83
84
# File 'app/presenters/search/opportunity_presenter.rb', line 80

def distance
  return unless r.has_columns?(:distance)

  "#{r.distance.round(2)} mi"
end

#last_sales_activity_completed_onString

Returns the last completed sales activity date formatted for display.

Returns:

  • (String)


45
46
47
# File 'app/presenters/search/opportunity_presenter.rb', line 45

def last_sales_activity_completed_on
  h.render_date r.last_sales_activity_completed_on
end

#next_sales_activityActiveSupport::SafeBuffer?

Returns a button popover with details of the next sales activity, if any.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/presenters/search/opportunity_presenter.rb', line 111

def next_sales_activity
  return unless r.has_columns?(:next_sales_activity_id) &&
                r.next_sales_activity_id &&
                (a = Activity.find(r.next_sales_activity_id))

  activity_summary = []
  activity_summary << h.(:p, "Due Date: #{a.target_datetime.to_date}")
  activity_summary << h.(:p, "Assigned to: #{a.assigned_resource&.full_name}")
  activity_summary << h.(:p, "Notes: #{a.notes}") if a.notes.present?
  activity_summary << h.link_to(h.fa_icon('external-link', text: 'Open Activity'), h.activity_path(a))
  h.button_tag(type: 'button', class: 'btn btn-outline-primary', title: 'Open Sales Activity Details',
      'data-bs-html': true,
      'data-bs-container': 'body',
      'data-bs-toggle': 'popover',
      'data-bs-content': activity_summary.join.html_safe) do
    a.display_type
  end
end

#notes_indicatorActiveSupport::SafeBuffer

Returns a notes popover for the last activity notes.

Returns:

  • (ActiveSupport::SafeBuffer)


38
39
40
# File 'app/presenters/search/opportunity_presenter.rb', line 38

def notes_indicator
  h.notes_popover r.last_activity_notes
end

Returns a link to the opportunity.

Returns:

  • (ActiveSupport::SafeBuffer)


15
16
17
# File 'app/presenters/search/opportunity_presenter.rb', line 15

def opportunity_link
  h.link_to r.name, h.opportunity_path(r.id)
end

#opportunity_typeString

Returns the human-readable opportunity type label.

Returns:

  • (String)


66
67
68
# File 'app/presenters/search/opportunity_presenter.rb', line 66

def opportunity_type
  OpportunityConstants::OPPORTUNITY_TYPES[r.opportunity_type] || 'unknown'
end

#participants_comboActiveSupport::SafeBuffer

Returns an unordered list of links to opportunity participants.

Returns:

  • (ActiveSupport::SafeBuffer)


133
134
135
136
137
138
139
140
141
# File 'app/presenters/search/opportunity_presenter.rb', line 133

def participants_combo
  h. :ul, class: 'list-unstyled' do
    h.concat(h.(:li, h.link_to(h.fa_icon('industry', text: r.customer_full_name), h.customer_path(r.customer_id)), style: 'margin-bottom: 5px')) if r.customer_id
    h.concat(h.(:li, h.link_to(h.fa_icon('user', text: r.contact_full_name), h.contact_path(r.contact_id)), style: 'margin-bottom: 5px')) if r.contact_id
    r.opportunity.opportunity_participants.each do |op|
      h.concat(h.(:li, h.link_to(h.fa_icon('user', text: op.party.full_name), h.polymorphic_path(op.party)), style: 'margin-bottom: 5px'))
    end
  end
end

#planned_installation_dateString

Returns the planned installation date formatted for display.

Returns:

  • (String)


89
90
91
# File 'app/presenters/search/opportunity_presenter.rb', line 89

def planned_installation_date
  h.render_date r.planned_installation_date
end

#stateString

Returns the human-readable state name.

Returns:

  • (String)


59
60
61
# File 'app/presenters/search/opportunity_presenter.rb', line 59

def state
  Opportunity.human_state_name(r.state)
end

#valueString

Returns the opportunity value formatted as currency.

Returns:

  • (String)


73
74
75
# File 'app/presenters/search/opportunity_presenter.rb', line 73

def value
  h.number_to_currency(r.value)
end

#won_lost_dateString

Returns the won/lost date formatted for display.

Returns:

  • (String)


96
97
98
# File 'app/presenters/search/opportunity_presenter.rb', line 96

def won_lost_date
  h.render_date r.won_lost_date
end