Class: Search::ActivityPresenter

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

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 = ['btn','btn-block']
  if open_activity?
    css_classes << 'btn-success'
  else
    css_classes << 'btn-outline-primary'
  end
  h.link_to(r.activity_type_task_type, h.activity_path(r.id), class: css_classes.join(' '))
end

#assigned_resourceObject



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

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

#assigned_to_current_user?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/presenters/search/activity_presenter.rb', line 6

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

#campaignObject



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

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



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

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

#completion_dateObject



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

def completion_date
  h.render_date(r.completion_datetime)
end

#completion_datetimeObject



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

def completion_datetime
  h.render_datetime(r.completion_datetime)
end

#completion_timeObject



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

def completion_time
  h.render_time(r.completion_datetime)
end

#contactObject



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

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



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

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



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

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



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

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



113
114
115
# File 'app/presenters/search/activity_presenter.rb', line 113

def notes_indicator
  h.notes_popover compact_notes
end

#open_activity?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/presenters/search/activity_presenter.rb', line 10

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

#original_target_datetimeObject



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

def original_target_datetime
  h.render_date(r.original_target_datetime)
end

#recordsObject



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

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

#resourceObject



80
81
82
83
84
85
86
87
88
# File 'app/presenters/search/activity_presenter.rb', line 80

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 => exc
    res.to_s
  end
end

#target_dateObject



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

def target_date
  h.render_date(r.target_datetime)
end

#target_datetimeObject



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

def target_datetime
  h.render_datetime(r.target_datetime)
end

#target_timeObject



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

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
# 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