Class: Search::ActivityPresenter

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

Overview

Row presenter for ViewActivity — renders the cells in the CRM activity
search/results table.

Direct Known Subclasses

ActivityTextPresenter

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

Linked activity task type → activity show page, styled by open/closed state.

Returns:

  • (ActiveSupport::SafeBuffer)


38
39
40
41
42
43
44
45
46
# File 'app/presenters/search/activity_presenter.rb', line 38

def activity_link
  css_classes = %w[btn btn-block]
  css_classes << if open_activity?
                   'btn-success'
                 else
                   'btn-outline-primary'
                 end
  h.link_to(r.activity_type_task_type, h.activity_path(r.id), class: css_classes.join(' '))
end

#assigned_resourceActiveSupport::SafeBuffer?

Assigned-resource block, highlighting the current user and showing
the original assignee when reassigned.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


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

def assigned_resource
  h.capture do
    h.concat h. :p, r.assigned_resource_full_name, class: ('text-success' if assigned_to_current_user?)
    h.concat h. :del, r.original_assigned_resource_full_name, class: 'text-body-secondary' if r.original_assigned_resource_id && r.assigned_resource_id && original_assigned_resource_id != r.assigned_resource_id
  end
end

#assigned_to_current_user?Boolean

Whether this activity is assigned to the currently logged-in user.

Returns:

  • (Boolean)


13
14
15
# File 'app/presenters/search/activity_presenter.rb', line 13

def assigned_to_current_user?
  h.current_user.id == r.assigned_resource_id
end

#campaignActiveSupport::SafeBuffer?

Linked campaign name → campaign show page.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


159
160
161
162
163
# File 'app/presenters/search/activity_presenter.rb', line 159

def campaign
  return unless r.has_columns?(:campaign_id, :campaign_name) && r.campaign_id && r.campaign_name

  h.link_to(r.campaign_name, h.campaign_path(r.campaign_id))
end

#compact_notesString?

Sanitized activity notes/description with bracketed text removed.

Returns:

  • (String, nil)


186
187
188
189
190
# File 'app/presenters/search/activity_presenter.rb', line 186

def compact_notes
  cn = r.try(:notes) || r.try(:description)
  cn = cn.gsub(/\[.*\]/, '').strip if cn
  cn
end

#completion_dateString

Completion date rendered through the shared render_date helper.

Returns:

  • (String)


97
98
99
# File 'app/presenters/search/activity_presenter.rb', line 97

def completion_date
  h.render_date(r.completion_datetime)
end

#completion_datetimeString

Completion datetime rendered through the shared render_datetime helper.

Returns:

  • (String)


90
91
92
# File 'app/presenters/search/activity_presenter.rb', line 90

def completion_datetime
  h.render_datetime(r.completion_datetime)
end

#completion_timeString

Completion time rendered through the shared render_time helper.

Returns:

  • (String)


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

def completion_time
  h.render_time(r.completion_datetime)
end

#contactActiveSupport::SafeBuffer?

Linked contact name → contact show page.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


150
151
152
153
154
# File 'app/presenters/search/activity_presenter.rb', line 150

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

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

#contact_buttonActiveSupport::SafeBuffer

Dropdown of callable contact points for the activity's customer.

Returns:

  • (ActiveSupport::SafeBuffer)


195
196
197
198
# File 'app/presenters/search/activity_presenter.rb', line 195

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

#customerActiveSupport::SafeBuffer?

Linked customer name → customer show page.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


141
142
143
144
145
# File 'app/presenters/search/activity_presenter.rb', line 141

def customer
  return unless r.has_columns?(:customer_id, :customer_full_name) && r.customer_id && r.customer_full_name

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

#customer_watch_symbolActiveSupport::SafeBuffer?

Customer watch / open-sales-activity indicator symbol.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


118
119
120
121
122
# File 'app/presenters/search/activity_presenter.rb', line 118

def customer_watch_symbol
  return unless r.has_columns?(:customer_watch, :customer_open_sales_activity)

  h.concat h.customer_watch_symbol_raw(r.customer_watch, r.customer_open_sales_activity)
end

#notes_indicatorActiveSupport::SafeBuffer

Notes popover for the activity.

Returns:

  • (ActiveSupport::SafeBuffer)


179
180
181
# File 'app/presenters/search/activity_presenter.rb', line 179

def notes_indicator
  h.notes_popover compact_notes
end

#open_activity?Boolean

Whether the activity is still open (has a task type but no result code).

Returns:

  • (Boolean)


20
21
22
# File 'app/presenters/search/activity_presenter.rb', line 20

def open_activity?
  r.activity_type_task_type && r.activity_result_type_result_code.nil?
end

#original_target_datetimeString

Original target datetime rendered through the shared render_date helper.

Returns:

  • (String)


111
112
113
# File 'app/presenters/search/activity_presenter.rb', line 111

def original_target_datetime
  h.render_date(r.original_target_datetime)
end

#recordsActiveSupport::SafeBuffer

Unordered list of customer, contact, and resource links.

Returns:

  • (ActiveSupport::SafeBuffer)


168
169
170
171
172
173
174
# File 'app/presenters/search/activity_presenter.rb', line 168

def records
  h.(:ul, class: 'list-unstyled') do
    [customer, contact, resource].compact.each do |link|
      h.concat h.(:li, link)
    end
  end
end

#resourceActiveSupport::SafeBuffer, ...

Linked polymorphic resource (opportunity, order, etc.) → its show page.

Returns:

  • (ActiveSupport::SafeBuffer, String, nil)


127
128
129
130
131
132
133
134
135
136
# File 'app/presenters/search/activity_presenter.rb', line 127

def resource
  return unless r.has_columns?(:resource_id, :resource_type) && r.resource_type && r.resource_id

  begin
    res = r.resource
    h.link_to(res.to_s, h.polymorphic_url(res))
  rescue StandardError
    res.to_s
  end
end

#target_dateString

Target date rendered through the shared render_date helper.

Returns:

  • (String)


76
77
78
# File 'app/presenters/search/activity_presenter.rb', line 76

def target_date
  h.render_date(r.target_datetime)
end

#target_datetimeString

Target datetime rendered through the shared render_datetime helper.

Returns:

  • (String)


69
70
71
# File 'app/presenters/search/activity_presenter.rb', line 69

def target_datetime
  h.render_datetime(r.target_datetime)
end

#target_timeString

Target time rendered through the shared render_time helper.

Returns:

  • (String)


83
84
85
# File 'app/presenters/search/activity_presenter.rb', line 83

def target_time
  h.render_time(r.target_datetime)
end

#time_at_locationActiveSupport::SafeBuffer?

Time-at-location value wrapped in a non-breaking <time> tag.

Returns:

  • (ActiveSupport::SafeBuffer, nil)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/presenters/search/activity_presenter.rb', line 51

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

  h.(:time, r.time_at_location, class: 'text-nowrap')
  # this time at location was set incorrectly in the view, for e.g.:
  # irb(main):082:0> ViewActivity.last.time_at_location
  # Sat, 01 Jan 2000 04:19:25.806658000 CST -06:00
  # So, let's assume the time part is correct at UTC and render it in the viewer's time zone
  # t = nil
  # Time.use_zone('UTC') do
  #   t=Time.zone.parse(r.time_at_location.to_s)
  # end
  # h.render_time(t)
end