Module: PhonesHelper

Defined in:
app/helpers/phones_helper.rb

Overview

View helper: phones.

Constant Summary collapse

PRESENCE_DOT_CLASSES =

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



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

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



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

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



44
45
46
47
48
# File 'app/helpers/phones_helper.rb', line 44

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



50
51
52
53
54
# File 'app/helpers/phones_helper.rb', line 50

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


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/phones_helper.rb', line 75

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


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

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 duration-tracked row (DND or Available - Non Queue), 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 && status_tracks_duration?(presence, sub_presence)
      time_by_status = Report::StatusTimelineReport.get_last_status_by_employee(employee.id)
      if time_by_status.present?
        current_type = [presence, sub_presence].compact.join(' - ')
        last_entry = time_by_status.reverse.find { |ts| ts[:type] == current_type }
        if last_entry
          time_text = Heatwave::Duration.humanize(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') && 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



56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/phones_helper.rb', line 56

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



38
39
40
41
42
# File 'app/helpers/phones_helper.rb', line 38

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