Class: Search::ActivityPresenter

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

Overview

Presenter: activity presenter.

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



23
24
25
26
27
28
29
30
31
# File 'app/presenters/search/activity_presenter.rb', line 23

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_resourceObject



16
17
18
19
20
21
# File 'app/presenters/search/activity_presenter.rb', line 16

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-muted' 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

Returns:

  • (Boolean)


8
9
10
# File 'app/presenters/search/activity_presenter.rb', line 8

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

#campaignObject



105
106
107
108
109
# File 'app/presenters/search/activity_presenter.rb', line 105

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_notesObject



123
124
125
126
127
# File 'app/presenters/search/activity_presenter.rb', line 123

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

#completion_dateObject



64
65
66
# File 'app/presenters/search/activity_presenter.rb', line 64

def completion_date
  h.render_date(r.completion_datetime)
end

#completion_datetimeObject



60
61
62
# File 'app/presenters/search/activity_presenter.rb', line 60

def completion_datetime
  h.render_datetime(r.completion_datetime)
end

#completion_timeObject



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

def completion_time
  h.render_time(r.completion_datetime)
end

#contactObject



99
100
101
102
103
# File 'app/presenters/search/activity_presenter.rb', line 99

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_buttonObject



129
130
131
132
# File 'app/presenters/search/activity_presenter.rb', line 129

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

#customerObject



93
94
95
96
97
# File 'app/presenters/search/activity_presenter.rb', line 93

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_symbolObject



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

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_indicatorObject



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

def notes_indicator
  h.notes_popover compact_notes
end

#open_activity?Boolean

Returns:

  • (Boolean)


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

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

#original_target_datetimeObject



72
73
74
# File 'app/presenters/search/activity_presenter.rb', line 72

def original_target_datetime
  h.render_date(r.original_target_datetime)
end

#recordsObject



111
112
113
114
115
116
117
# File 'app/presenters/search/activity_presenter.rb', line 111

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

#resourceObject



82
83
84
85
86
87
88
89
90
91
# File 'app/presenters/search/activity_presenter.rb', line 82

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_dateObject



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

def target_date
  h.render_date(r.target_datetime)
end

#target_datetimeObject



48
49
50
# File 'app/presenters/search/activity_presenter.rb', line 48

def target_datetime
  h.render_datetime(r.target_datetime)
end

#target_timeObject



56
57
58
# File 'app/presenters/search/activity_presenter.rb', line 56

def target_time
  h.render_time(r.target_datetime)
end

#time_at_locationObject



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

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