Module: Models::EmployeeWatchList

Extended by:
ActiveSupport::Concern
Included in:
Employee
Defined in:
app/concerns/models/employee_watch_list.rb

Overview

Watch-list and monitoring-group management for Employee.

Instance Method Summary collapse

Instance Method Details

#effective_watch_list_ids(include_role_list: true) ⇒ Array<Integer>

All employee IDs this employee effectively watches.

Parameters:

  • include_role_list (Boolean) (defaults to: true)

    whether to include employees covered by
    the selected roles

Returns:

  • (Array<Integer>)

    unique employee IDs; falls back to this
    employee's own ID when nothing is selected



74
75
76
77
78
79
80
# File 'app/concerns/models/employee_watch_list.rb', line 74

def effective_watch_list_ids(include_role_list: true)
  list = []
  list += selected_watch_list_roles_employees.ids if include_role_list && selected_watch_list_role_ids.present?
  list += selected_watch_list_employee_ids
  list << id if list.empty?
  list.uniq
end

#monitor_group_sms_numbers=(val) ⇒ Boolean

Sets whether monitor-group SMS numbers are included for this employee.

Parameters:

  • val (Boolean, nil)

    truthy enables monitoring; nil disables it

Returns:

  • (Boolean)

    the value assigned to the employee record



86
87
88
# File 'app/concerns/models/employee_watch_list.rb', line 86

def monitor_group_sms_numbers=(val)
  employee_record.monitor_group_sms_numbers = val || false
end

#monitor_unlinked_extensions=(val) ⇒ Boolean

Sets whether calls on unlinked extensions are monitored for this employee.

Parameters:

  • val (Boolean, nil)

    truthy enables monitoring; nil disables it

Returns:

  • (Boolean)

    the value assigned to the employee record



94
95
96
# File 'app/concerns/models/employee_watch_list.rb', line 94

def monitor_unlinked_extensions=(val)
  employee_record.monitor_unlinked_extensions = val || false
end

#selected_queue_coverage_idsArray<Integer>

Phone queues this employee last chose on the queue coverage dashboard.
An empty array is intentional: first-time visitors start with no queue
selected, and turning the final queue off must remain sticky.

Returns:

  • (Array<Integer>)

    normalized queue IDs persisted in the employee's
    preferences



53
54
55
# File 'app/concerns/models/employee_watch_list.rb', line 53

def selected_queue_coverage_ids
  normalize_queue_coverage_ids(employee_record&.heatwave_preferences&.dig('queue_coverage_queue_ids'))
end

#selected_queue_coverage_ids=(val) ⇒ Hash

Persists the employee's queue coverage selection in their preferences.

Parameters:

  • val (Array, nil)

    queue IDs to store; values are coerced to integers
    and deduplicated

Returns:

  • (Hash)

    the updated preferences hash assigned to the employee record



62
63
64
65
66
# File 'app/concerns/models/employee_watch_list.rb', line 62

def selected_queue_coverage_ids=(val)
  preferences = (employee_record.heatwave_preferences || {}).dup
  preferences['queue_coverage_queue_ids'] = normalize_queue_coverage_ids(val)
  employee_record.heatwave_preferences = preferences
end

#selected_watch_list_employee_idsArray<Integer>

IDs of the individual employees on this employee's watch list.

Returns:

  • (Array<Integer>)

    selected employee IDs, or an empty array when no
    employee record exists



35
36
37
# File 'app/concerns/models/employee_watch_list.rb', line 35

def selected_watch_list_employee_ids
  employee_record&.watch_list_ids || []
end

#selected_watch_list_employee_ids=(val) ⇒ Array<Integer>

Replaces the employees on this employee's watch list.

Parameters:

  • val (Array<Integer>, nil)

    employee IDs to watch; nil clears the list

Returns:

  • (Array<Integer>)

    the deduplicated employee IDs that were assigned



43
44
45
# File 'app/concerns/models/employee_watch_list.rb', line 43

def selected_watch_list_employee_ids=(val)
  employee_record.watch_list_ids = (val || []).compact.uniq
end

#selected_watch_list_role_idsArray<Integer>

IDs of the roles this employee selected for their watch list.

Returns:

  • (Array<Integer>)

    selected role IDs, or an empty array when no
    employee record exists



11
12
13
# File 'app/concerns/models/employee_watch_list.rb', line 11

def selected_watch_list_role_ids
  employee_record&.watch_list_role_ids || []
end

#selected_watch_list_role_ids=(val) ⇒ Array<Integer>

Replaces the employee's selected watch-list roles.

Parameters:

  • val (Array<Integer>, nil)

    role IDs to select; nil clears the list

Returns:

  • (Array<Integer>)

    the deduplicated role IDs that were assigned



19
20
21
# File 'app/concerns/models/employee_watch_list.rb', line 19

def selected_watch_list_role_ids=(val)
  employee_record.watch_list_role_ids = (val || []).compact.uniq
end

#selected_watch_list_roles_employeesActiveRecord::Relation<Employee>

Active employees covered by the selected watch-list roles.

Returns:

  • (ActiveRecord::Relation<Employee>)

    employees holding any of the
    selected roles



27
28
29
# File 'app/concerns/models/employee_watch_list.rb', line 27

def selected_watch_list_roles_employees
  Employee.active_employees.joins(account: :roles).where(roles: { id: selected_watch_list_role_ids })
end

#watch_listActiveRecord::Relation<Employee>

Employees available to add to a watch list.

Returns:

  • (ActiveRecord::Relation<Employee>)

    active employees in sorted order



101
102
103
# File 'app/concerns/models/employee_watch_list.rb', line 101

def watch_list
  Employee.active_employees.sorted
end