Class: AssignmentQueue
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AssignmentQueue
- Extended by:
- Memery
- Includes:
- Memery, Models::Auditable
- Defined in:
- app/models/assignment_queue.rb
Overview
== Schema Information
Table name: assignment_queues
Database name: primary
id :integer not null, primary key
queue :string(255) default([]), not null, is an Array
created_at :datetime not null
updated_at :datetime
creator_id :integer
updater_id :integer
Indexes
idx_assignment_queues_queue (queue) UNIQUE
Defined Under Namespace
Classes: UnassignableActivity
Constant Summary collapse
- VARIABLE_OPTIONS =
Available variable options.
[['Logged-in User', 'current_user'], ['Primary Sales Rep', 'primary_sales_rep'], ['Primary Sales Rep Backup', 'primary_sales_rep_backup'], ['Secondary Sales Rep', 'secondary_sales_rep'], ['Local Sales Rep', 'local_sales_rep'], ['Service Rep', 'service_rep']].freeze
- TICKET_VARIABLE_OPTIONS =
Available ticket variable options.
[['Assigned Rep', 'ticket_assigned_rep']].freeze
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
-
#lbr_method ⇒ Object
Returns the value of attribute lbr_method.
Has many collapse
- #activity_type_assignment_queues ⇒ ActiveRecord::Relation<ActivityTypeAssignmentQueue>
- #activity_types ⇒ ActiveRecord::Relation<ActivityType>
Class Method Summary collapse
-
.containing_entry_named ⇒ ActiveRecord::Relation<AssignmentQueue>
A relation of AssignmentQueues that are containing entry named.
-
.employee_select_options ⇒ Object
Builds a list of possible employees to use in activity assignment queues.
-
.grouped_queue_select_options ⇒ Object
Returns a grouped list of queue options suitable for an options for select grouped.
-
.interpolate_with_customer(q, c, current_user_id = nil, target_date = nil, excluded_rep_ids = [], assignment_matrix = nil, resource = nil) ⇒ Integer?
Resolves a queue entry to a rep id, using the customer/context as input.
-
.least_busy_rep_by_role(target_date, role_id, excluded_rep_ids, assignment_matrix = nil) ⇒ Object
Queries database to find out the least busy rep.
-
.queue_select_options ⇒ Object
Builds a list of possible queue values, variable role based values and individuals.
-
.queue_value_expanded(q) ⇒ Object
Translates a queue value to a friendly name.
- .ransackable_attributes(_auth_object = nil) ⇒ Object
- .ransackable_scopes(_auth_object = nil) ⇒ Object
- .rep_id_for_backup(rep_id) ⇒ Object
- .role_select_options ⇒ Object
-
.select_options ⇒ Object
Provides a list of assignment queues to select from.
-
.valid_values ⇒ Object
Returns a list of valid values for the queue type selection.
Instance Method Summary collapse
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #creator, #should_not_save_version, #stamp_record, #updater
Methods inherited from ApplicationRecord
ransackable_associations, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#lbr_method ⇒ Object
Returns the value of attribute lbr_method.
49 50 51 |
# File 'app/models/assignment_queue.rb', line 49 def lbr_method @lbr_method end |
Class Method Details
.containing_entry_named ⇒ ActiveRecord::Relation<AssignmentQueue>
A relation of AssignmentQueues that are containing entry named. Active Record Scope
32 33 34 35 36 37 38 39 |
# File 'app/models/assignment_queue.rb', line 32 scope :containing_entry_named, ->(val) { return all if val.blank? matching = .select { |label, _| label.downcase.include?(val.to_s.downcase) } .map(&:last) matching.any? ? where("queue && ARRAY[?]::varchar[]", matching) : none } |
.employee_select_options ⇒ Object
Builds a list of possible employees to use in activity assignment queues
91 92 93 |
# File 'app/models/assignment_queue.rb', line 91 def Employee..map { |o| [o[0], "Employee|#{o[1]}"] } end |
.grouped_queue_select_options ⇒ Object
Returns a grouped list of queue options suitable for an options for select grouped
71 72 73 74 75 76 77 78 |
# File 'app/models/assignment_queue.rb', line 71 def { 'Customer Roles' => VARIABLE_OPTIONS, 'Support Case Roles' => TICKET_VARIABLE_OPTIONS, 'Least Busy by Role' => , 'Employees' => } end |
.interpolate_with_customer(q, c, current_user_id = nil, target_date = nil, excluded_rep_ids = [], assignment_matrix = nil, resource = nil) ⇒ Integer?
When c (the customer) is nil — e.g. an Activity is created
against a Contact whose customer association is unset — the cache
key is built without dereferencing c and customer-dependent entries
return nil (semantics: "this entry can't yield a rep") instead of
raising. Customer-independent entries continue to resolve normally.
This mirrors the existing nil-guard on the resource arg.
Resolves a queue entry to a rep id, using the customer/context as input.
Result is memoized per CurrentScope (request- or job-scoped) keyed on
all arguments, so a given queue traversal computes each entry once.
Logic Details
Queue entries fall into two contracts:
- Customer-dependent:
primary_sales_rep,primary_sales_rep_backup,
secondary_sales_rep,local_sales_rep,service_rep. These read the
rep id off the customer record. - Customer-independent:
current_user,Employee|<id>,LBR|<role>,
ticket_assigned_rep. These resolve fromcurrent_user_id, the entry
itself, anassignment_matrixlookup, orresource.
160 161 162 163 164 165 166 167 168 |
# File 'app/models/assignment_queue.rb', line 160 def interpolate_with_customer(q, c, current_user_id = nil, target_date = nil, excluded_rep_ids = [], assignment_matrix = nil, resource = nil) target_date ||= Date.current cache_key = [:interpolate_with_customer, q, c && [c.class.name, c.id], current_user_id, target_date, excluded_rep_ids, assignment_matrix, resource && [resource.class.name, resource.id]] fetch_cached(*cache_key) do compute_interpolate_with_customer(q, c, current_user_id, target_date, excluded_rep_ids, assignment_matrix, resource) end end |
.least_busy_rep_by_role(target_date, role_id, excluded_rep_ids, assignment_matrix = nil) ⇒ Object
Queries database to find out the least busy rep
171 172 173 174 175 |
# File 'app/models/assignment_queue.rb', line 171 def least_busy_rep_by_role(target_date, role_id, excluded_rep_ids, assignment_matrix = nil) fetch_cached(:least_busy_rep_by_role, target_date, role_id, excluded_rep_ids, assignment_matrix) do compute_least_busy_rep_by_role(target_date, role_id, excluded_rep_ids, assignment_matrix) end end |
.queue_select_options ⇒ Object
Builds a list of possible queue values, variable role based values and individuals
86 87 88 |
# File 'app/models/assignment_queue.rb', line 86 def [] + VARIABLE_OPTIONS + TICKET_VARIABLE_OPTIONS + + end |
.queue_value_expanded(q) ⇒ Object
Translates a queue value to a friendly name
100 101 102 103 104 105 106 107 108 |
# File 'app/models/assignment_queue.rb', line 100 def (q) match = .find { |e| e[1] == q } if match match[0] else logger.error " !!! queue_value_expanded: Could not determine the value of q -> #{q}" raise "Value of q missing in table #{q}" end end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
45 46 47 |
# File 'app/models/assignment_queue.rb', line 45 def self.ransackable_attributes(_auth_object = nil) %w[id queue created_at updated_at] end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
41 42 43 |
# File 'app/models/assignment_queue.rb', line 41 def self.ransackable_scopes(_auth_object = nil) %i[containing_entry_named] end |
.rep_id_for_backup(rep_id) ⇒ Object
110 111 112 113 114 115 116 |
# File 'app/models/assignment_queue.rb', line 110 def rep_id_for_backup(rep_id) return nil unless rep_id fetch_cached(:rep_id_for_backup, rep_id) do EmployeeRecord.where(party_id: rep_id).pick(:backup_rep_id) end end |
.role_select_options ⇒ Object
95 96 97 |
# File 'app/models/assignment_queue.rb', line 95 def Role..map { |r| [r[0], "LBR|#{r[1]}"] } end |
.select_options ⇒ Object
Provides a list of assignment queues to select from
66 67 68 |
# File 'app/models/assignment_queue.rb', line 66 def all.to_a.reject { |aq| aq.name.nil? }.sort_by(&:name).map { |aq| ["#{aq.name} [#{aq.id}]", aq.id] } end |
.valid_values ⇒ Object
Returns a list of valid values for the queue type selection
81 82 83 |
# File 'app/models/assignment_queue.rb', line 81 def valid_values .pluck(1) end |
Instance Method Details
#activity_type_assignment_queues ⇒ ActiveRecord::Relation<ActivityTypeAssignmentQueue>
23 |
# File 'app/models/assignment_queue.rb', line 23 has_many :activity_type_assignment_queues, inverse_of: :assignment_queue |
#activity_types ⇒ ActiveRecord::Relation<ActivityType>
24 |
# File 'app/models/assignment_queue.rb', line 24 has_many :activity_types, through: :activity_type_assignment_queues |
#name ⇒ Object
253 254 255 256 257 |
# File 'app/models/assignment_queue.rb', line 253 def name queue.map { |e| self.class.(e) }.join(' -> ') rescue StandardError nil end |