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: {}) ⇒ Object
- #activity_fast_contact_links(activity, parties: nil, return_path: nil) ⇒ Object
- #paginate_activities(pagy) ⇒ Object
- #render_activity_form(activity) ⇒ Object
- #setup_activity(activity) ⇒ Object
- #setup_uploads(activity) ⇒ Object
Instance Method Details
#activity_fast_contact_link(cp, return_path: nil, communication_options: {}) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/helpers/activities_helper.rb', line 110 def activity_fast_contact_link(cp, return_path: nil, communication_options: {}) return unless (label = cp.formatted_dial_string).present? # A badly formatted number or email will result in a nil which cannot be handled label << content_tag(:small, " • #{cp.notes}", class: 'text-muted') 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) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/activities_helper.rb', line 64 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)] unless parties.present? # 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-muted') if tz links << { content: display.html_safe, class: 'text-muted 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-muted 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 |
#paginate_activities(pagy) ⇒ Object
35 36 37 38 39 40 |
# File 'app/helpers/activities_helper.rb', line 35 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) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/activities_helper.rb', line 53 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) ⇒ Object
42 43 44 45 |
# File 'app/helpers/activities_helper.rb', line 42 def setup_activity(activity) activity.tap do |c| end end |
#setup_uploads(activity) ⇒ Object
47 48 49 50 51 |
# File 'app/helpers/activities_helper.rb', line 47 def setup_uploads(activity) activity.tap do |a| a.uploads.build end end |