Module: ActivitiesHelper
- Defined in:
- app/helpers/activities_helper.rb
Overview
== Schema Information
Table name: activities
id :integer not null, primary key
start_datetime :datetime
completion_datetime :datetime
target_datetime :datetime
activity_type_id :integer
parent_activity_id :integer
assigned_resource_id :integer
resource_id :integer
resource_type :string(255)
created_at :datetime
updated_at :datetime
creator_id :integer
activity_result_type_id :integer
description :string(255)
closed_by_id :integer
party_id :integer
updater_id :integer
uploads_count :integer default(0)
notes :text
lock_target_datetime :boolean default(FALSE)
original_target_datetime :datetime
original_assigned_resource_id :integer
communication_id :integer
customer_id :integer
campaign_id :integer
Instance Method Summary collapse
-
#activity_fast_contact_link(cp, return_path: nil, communication_options: {}) ⇒ String?
Builds a single fast-contact link for a contact point — a new-communication link for transmittable points, a SIP dial link for callable ones.
-
#activity_fast_contact_links(activity, parties: nil, return_path: nil) ⇒ Array<Hash>
Builds the fast-contact dropdown entries for an activity's parties, grouped per party with one entry per contactable contact point.
-
#call_record_for_activity(activity) ⇒ CallRecord?
Returns the call record associated with the activity, if any.
-
#paginate_activities(pagy) ⇒ String?
Renders the pagination bar for an activities list when there is more than one page.
-
#render_activity_form(activity) ⇒ String
Renders the activity form, with a communication preview when the activity is linked to a communication.
-
#setup_activity(activity) ⇒ Activity
Prepares an activity for display or editing.
-
#setup_uploads(activity) ⇒ Activity
Builds a blank nested upload on the activity for the form.
Instance Method Details
#activity_fast_contact_link(cp, return_path: nil, communication_options: {}) ⇒ String?
Builds a single fast-contact link for a contact point — a new-communication
link for transmittable points, a SIP dial link for callable ones.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'app/helpers/activities_helper.rb', line 147 def activity_fast_contact_link(cp, return_path: nil, communication_options: {}) return if (label = cp.formatted_dial_string).blank? # A badly formatted number or email will result in a nil which cannot be handled label << content_tag(:small, " • #{cp.notes}", class: 'text-body-secondary') if cp.notes.present? display = contact_point_category_icon(cp.category, text: label&.html_safe) if cp.transmittable? link_to(display, new_communication_path(recipient_contact_point_id: cp.id, return_path: return_path, **)) elsif cp.callable? sip_dial_link(display, cp.dial_string, party_id: cp.party_id) end end |
#activity_fast_contact_links(activity, parties: nil, return_path: nil) ⇒ Array<Hash>
Builds the fast-contact dropdown entries for an activity's parties,
grouped per party with one entry per contactable contact point.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/helpers/activities_helper.rb', line 94 def activity_fast_contact_links(activity, parties: nil, return_path: nil) links = [] begin contact_points = [] return_path ||= activity_path(activity) if activity.persisted? # If no parties is specified in function param, use parties specified in activity # cast to array so you don't modify by accident the original association parties ||= activity.parties.to_a # could be a new activity record so parties is not set yet, build one parties = [activity.party, activity.party.try(:customer)] if parties.blank? # Sometimes i've noticed parties might not be in sync with the selected party, this ensures that the party is always in the array parties << activity.party # finally make sure we have unique records and non nil records parties = parties.compact.uniq # Iterate through each party and add the contact points parties.each do |party| display = party.full_name # Get a shorthand for the time zone, e.g. EST, CST tz = timezone_abbreviated(party.timezone_name) display << content_tag(:small, " • #{tz}", class: 'text-body-secondary') if tz links << { content: display.html_safe, class: 'text-body-secondary ps-3 mt-1 mb-1' } # Get an array of contact points sorted by natural categories most likely to be used contact_points = party.contact_points.contactable.to_a.sort_by { |cp| [{ phone: 1, cell: 2, fax: 3, email: 4 }[cp.category&.to_sym], cp.position] } if contact_points.present? contact_point_links = contact_points.map do |cp| activity_fast_contact_link(cp, return_path: return_path, communication_options: { resource_type: activity.resource_type, resource_id: activity.resource_id, triggered_by_activity_id: activity.id }) end links += contact_point_links.compact.uniq else links << { content: 'No contact points', class: 'text-body-secondary ps-4 mt-1 mb-1' } end end rescue StandardError => e raise e if Rails.env.development? ErrorReporting.error(e, "Building contact point links for activity #{activity.id}") end links.compact end |
#call_record_for_activity(activity) ⇒ CallRecord?
Returns the call record associated with the activity, if any.
83 84 85 |
# File 'app/helpers/activities_helper.rb', line 83 def call_record_for_activity(activity) activity&.call_record end |
#paginate_activities(pagy) ⇒ String?
Renders the pagination bar for an activities list when there is more than one page.
37 38 39 40 41 42 |
# File 'app/helpers/activities_helper.rb', line 37 def paginate_activities(pagy) return unless pagy&.last&.> 1 safe_frame_id = ERB::Util.html_escape(tab_frame_id.to_s) (pagy, link_extra: %(data-turbo-frame="#{safe_frame_id}")) end |
#render_activity_form(activity) ⇒ String
Renders the activity form, with a communication preview when the activity
is linked to a communication.
68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/activities_helper.rb', line 68 def render_activity_form(activity) if activity.communication && activity.complete? render partial: '/activities/communication_preview', locals: { activity: activity } elsif activity.communication render(partial: '/activities/communication_preview', locals: { activity: activity }) + render(partial: '/activities/activity_form', locals: { activity: activity }) else render partial: '/activities/activity_form', locals: { activity: activity } end end |
#setup_activity(activity) ⇒ Activity
Prepares an activity for display or editing.
48 49 50 51 |
# File 'app/helpers/activities_helper.rb', line 48 def setup_activity(activity) activity.tap do |c| end end |
#setup_uploads(activity) ⇒ Activity
Builds a blank nested upload on the activity for the form.
57 58 59 60 61 |
# File 'app/helpers/activities_helper.rb', line 57 def setup_uploads(activity) activity.tap do |a| a.uploads.build end end |