Module: SupportCasesHelper

Defined in:
app/helpers/support_cases_helper.rb

Overview

== Schema Information

Table name: support_cases

id :integer not null, primary key
case_number :string(255)
case_type :string(255)
assigned_to_id :integer
state :string(255)
description :text
priority :string(255)
creator_id :integer
updater_id :integer
created_at :datetime not null
updated_at :datetime not null
opened_at :datetime
closed_at :datetime

Instance Method Summary collapse

Instance Method Details



60
61
62
63
64
65
66
67
# File 'app/helpers/support_cases_helper.rb', line 60

def new_comm_link(email_contact_points_ids = nil)
  email_contact_points_ids ||= @support_case.support_case_participants.map(&:email_id).compact.join(',')
  new_communication_path(recipient_contact_point_ids: email_contact_points_ids,
                         return_path: support_case_path(@support_case),
                         resource_type: 'SupportCase',
                         resource_id: @support_case.id,
                         template_system_code: @support_case.communication_template_system_code)
end

#setup_support_case(support_case) ⇒ Object



69
70
71
72
73
# File 'app/helpers/support_cases_helper.rb', line 69

def setup_support_case(support_case)
  support_case.tap do |sc|
    sc.support_case_participants.build unless sc.support_case_participants.present?
  end
end

#setup_support_case_participant(support_case_participant) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/support_cases_helper.rb', line 75

def setup_support_case_participant(support_case_participant)
  support_case_participant.tap do |scp|
    scp.party ||= Contact.new
    if scp.party.contact_points.empty?
      scp.party.contact_points.build(category: ContactPoint::EMAIL)
      scp.party.contact_points.build(category: ContactPoint::CELL)
      scp.party.contact_points.build(category: ContactPoint::PHONE)
      scp.party.contact_points.build(category: ContactPoint::FAX)
    end
  end
end

#smart_services_tab_optionsObject



138
139
140
141
142
143
144
145
# File 'app/helpers/support_cases_helper.rb', line 138

def smart_services_tab_options
  return {} unless @support_case&.id

  {
    active_services: { remote_href: tab_active_services_support_case_path(@support_case) },
    warehouse: { remote_href: tab_warehouse_support_case_path(@support_case) }
  }
end

#support_case_command_options(support_case) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/support_cases_helper.rb', line 23

def support_case_command_options(support_case)
  links = []
  links << fa_icon('shuffle', text: "State: #{support_case.human_state_name.titleize}")
  links << link_to(fa_icon('envelope', text: 'New Communication'), new_comm_link)
  links << link_to(fa_icon('wrench', text: 'Edit'), edit_support_case_path(support_case)) if can?(:update, support_case)
  links << link_to(fa_icon('trash', text: 'Destroy'), support_case, data: { turbo_confirm: 'Are you sure?', turbo_method: :delete }) if can?(:destroy, support_case)
  links << { class: 'divider' }
  links << link_to(fa_icon('right-to-bracket', text: 'Case Closed'), closed_support_case_path(support_case)) unless support_case.closed?
  links << link_to(fa_icon('right-to-bracket', text: support_case.new? ? 'Case Open' : 'Case Reopen'), reopened_support_case_path(support_case)) unless support_case.open?

  links += available_events_links(support_case, {}, {}, %w[case_open case_closed])

  # Reviews.io
  links << { class: 'divider' }
  existing_reviews = support_case.reviews_io_reviews
  if existing_reviews.any?
    review = existing_reviews.first
    links << link_to(fa_icon('star', text: "Reviewed #{review.review_date&.strftime('%b %d, %Y')} (#{review.rating}/5)"),
                     support_case_path(support_case, tab: 'reviews'), class: 'text-success')
  else
    links << link_to(fa_icon('star', text: 'Get a Review Link'),
                     support_case_path(support_case, tab: 'reviews'))
  end

  links
end

#support_case_index_command_options(case_type) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/helpers/support_cases_helper.rb', line 50

def support_case_index_command_options(case_type)
  links = []
  links << link_to(fa_icon('circle-plus', text: "New #{case_type} Ticket"), new_support_case_path(case_type: case_type)) unless case_type == 'SmartService'
  links << query_template_link(SupportCaseSearch, :default, { in_menu: true, aggregate_method: :none, title: 'Most Recent Cases', query_params: { case_type_in: [case_type] }, sort_columns: ['created_at desc'] })[0]
  SupportCase.case_types.each do |ct|
    links << link_to("Switch To #{ct} Dashboard", support_cases_path(case_type: ct)) unless case_type == ct
  end
  links
end

#support_case_tab_optionsObject



87
88
89
90
91
92
93
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
# File 'app/helpers/support_cases_helper.rb', line 87

def support_case_tab_options
  {
    activities: {
      counter: @support_case.activities.open_activities.size,
      remote_href: support_case_activities_path(@support_case)
    },
    communications: {
      counter: @support_case.communications.size,
      remote_href: support_case_communications_path(@support_case)
    },
    sms: {
      counter: @support_case.sms_messages.unread.size,
      remote_href: support_case_sms_messages_path(@support_case)
    },
    rooms: {
      counter: @support_case.room_configurations.size,
      remote_href: tab_rooms_support_case_path(@support_case)
    },
    orders: {
      counter: @support_case.orders.size,
      remote_href: support_case_orders_path(@support_case)
    },
    quotes: {
      counter: @support_case.quotes.size,
      remote_href: tab_quotes_support_case_path(@support_case)
    },
    rmas: {
      counter: @support_case.all_rmas.size,
      remote_href: tab_rmas_support_case_path(@support_case)
    },
    credit_memos: {
      counter: @support_case.all_credit_memos.size,
      remote_href: tab_credit_memos_support_case_path(@support_case)
    },
    attachments: {
      counter: @support_case.uploads.size,
      remote_href: support_case_uploads_path(@support_case)
    },
    support_cases: {
      counter: @support_case.linked_cases.size + (@support_case.parent_id.present? ? 1 : 0),
      remote_href: tab_support_cases_support_case_path(@support_case)
    },
    reviews: {
      remote_href: tab_reviews_support_case_path(@support_case)
    },
    state_history: {
      remote_href: tab_state_history_support_case_path(@support_case)
    }
  }
end

#tech_counter_badge(support_cases) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/helpers/support_cases_helper.rb', line 147

def tech_counter_badge(support_cases)
  case_load_counters = support_cases.where.not(state: 'closed').group(:state).count.symbolize_keys
  case_load = case_load_counters.values.sum

  return unless case_load.positive?

  css_class = if case_load_counters[:open].to_i.positive?
                'bg-danger'
              elsif case_load_counters[:waiting_on_customer].to_i.positive?
                'bg-warning'
              elsif case_load_counters[:new].to_i.positive?
                'bg-info'
              else
                'bg-secondary'
              end
  counter_span(case_load, css_class)
end