Module: PhonesHelper

Defined in:
app/helpers/phones_helper.rb

Constant Summary collapse

PRESENCE_DOT_CLASSES =
%w[
  presence-dot-available
  presence-dot-available-home-office
  presence-dot-available-non-queue
  presence-dot-dnd
  presence-dot-away
  presence-dot-unknown
].freeze

Instance Method Summary collapse

Instance Method Details

#combined_presence(presence, sub_presence = nil) ⇒ Object



65
66
67
68
69
70
# File 'app/helpers/phones_helper.rb', line 65

def combined_presence(presence, sub_presence = nil)
  # {'_forwarding' if sub_presence.present?}"
  cp = [presence]
  cp << sub_presence if sub_presence
  cp.join('-').parameterize
end

#icon_for_presence(status, sub_presence = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/phones_helper.rb', line 11

def icon_for_presence(status, sub_presence = nil)
  normalized_sub = normalize_sub_presence(sub_presence)
  case status.try(:to_sym)
  when :available
    case normalized_sub
    when 'home_office'  then 'house-laptop'
    when 'non_queue'    then 'user-check'
    when 'call_block'   then 'phone-slash'
    else                     'circle-user'
    end
  when :dnd
    case normalized_sub
    when 'lunch'         then 'utensils'
    when 'meeting'       then 'people-group'
    when 'with_customer' then 'handshake'
    else                      'circle-minus'
    end
  when :away
    'ban'
  else
    'question'
  end
end

#my_status_labelObject



41
42
43
44
45
# File 'app/helpers/phones_helper.rb', line 41

def my_status_label
  current_status = current_user.employee_phone_status
  icon_name = icon_for_presence(current_status&.presence, current_status&.sub_presence)
  fa_icon(icon_name, class: 'status-icon', text: current_user.full_name)
end

#my_status_mobile_labelObject



47
48
49
50
51
# File 'app/helpers/phones_helper.rb', line 47

def my_status_mobile_label
  current_status = current_user.employee_phone_status
  icon_name = icon_for_presence(current_status&.presence, current_status&.sub_presence)
  fa_icon(icon_name, class: 'status-icon')
end


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/phones_helper.rb', line 72

def navbar_presence_dot_class(presence, sub_presence = nil)
  normalized_sub = normalize_sub_presence(sub_presence)

  case presence.to_s.downcase
  when 'available'
    case normalized_sub
    when 'home_office' then 'presence-dot-available-home-office'
    when 'non_queue'   then 'presence-dot-available-non-queue'
    else                    'presence-dot-available'
    end
  when 'dnd'   then 'presence-dot-dnd'
  when 'away'  then 'presence-dot-away'
  else              'presence-dot-unknown'
  end
end


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
# File 'app/helpers/phones_helper.rb', line 88

def render_presence_change_link(employee, presence, sub_presence, include_time_in_status: nil)
  include_time_in_status = true if include_time_in_status.nil?
  selected = (employee.presence.to_s == presence.to_s and employee.sub_presence.to_s == sub_presence.to_s)
  icon_name = icon_for_presence(presence, sub_presence)
  display_name = fa_icon(icon_name, class: 'status-icon') + status_title(presence, sub_presence, selected)
  if include_time_in_status
    # `time_by_status` is only consumed when this row IS the currently
    # selected DND row, so gate the report call on that predicate. Without
    # this gate, render_presence_options' loop calls the report once per
    # presence option (9+ per employee card), each time running an
    # EmployeePhoneStatusChange + EmployeePhoneStatus query — pure N+1
    # since the result is discarded in every iteration except one.
    if selected && presence.to_s == 'dnd'
      time_by_status = Report::StatusTimelineReport.get_last_status_by_employee(employee.id)
      if time_by_status.present?
        require 'chronic_duration'
        current_type = [presence, sub_presence].compact.join(' - ')
        last_entry = time_by_status.select { |ts| ts[:type] == current_type }.last
        if last_entry
          time_text = ChronicDuration.output(last_entry[:time], format: :short, limit_to_hours: true, units: 2)
          time_text = time_text.present? ? time_text.delete(' ') : ''
          display_name << (:span, time_text.html_safe, style: 'margin-left:10px')
        end
      end
    end
    display_name << fa_icon('clock', text: employee.auto_away_after + ' CST', style: 'margin-left:5px') if presence.to_s == 'away' and employee.employee_phone_status.auto_away_after
  end
  link_to display_name,
          update_unified_status_employee_phone_statuses_path(employee_id: employee,
                                                             presence: presence,
                                                             sub_presence: sub_presence),
          class: "change-presence #{'selected' if selected}",
          data: {
            turbo_stream: true,
            presence: presence.to_s.parameterize,
            sub_presence: sub_presence.to_s.parameterize,
            combined_presence: combined_presence(presence, sub_presence)
          }
end

#render_presence_options(employee, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/phones_helper.rb', line 53

def render_presence_options(employee, options = {})
  return unless employee.employee_phone_status

  employee.employee_phone_status.curated_presence_list.map do |opts|
    (:li, render_presence_change_link(employee,
                                                 opts[:presence],
                                                 opts[:sub_presence],
                                                 include_time_in_status: options[:include_time_in_status]),
                class: options[:is_dropdown].to_b ? 'dropdown-item' : nil)
  end.join.html_safe
end

#status_title(presence, sub_presence, _selected = false) ⇒ Object



35
36
37
38
39
# File 'app/helpers/phones_helper.rb', line 35

def status_title(presence, sub_presence, _selected = false)
  res = presence.titleize
  res << " - #{sub_presence}" if sub_presence.present?
  (:span, res.html_safe, class: 'status-title')
end