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 =
[['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 =
[['Assigned Rep', 'ticket_assigned_rep']].freeze
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
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) ⇒ Object
Based on a queue entry and a customer determines the appropriate resource id to return q is the queue entry type c is the customer current_user_id is the logged in customer target_date is when the task is due time_sensitive is true when the activity MUST be assigned to someone working on that day.
-
.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 Models::EventPublishable
Instance Attribute Details
#lbr_method ⇒ Object
Returns the value of attribute lbr_method.
47 48 49 |
# File 'app/models/assignment_queue.rb', line 47 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
31 32 33 34 35 36 37 |
# File 'app/models/assignment_queue.rb', line 31 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
87 88 89 |
# File 'app/models/assignment_queue.rb', line 87 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
67 68 69 70 71 72 73 74 |
# File 'app/models/assignment_queue.rb', line 67 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) ⇒ Object
Based on a queue entry and a customer determines the appropriate resource id to return
q is the queue entry type
c is the customer
current_user_id is the logged in customer
target_date is when the task is due
time_sensitive is true when the activity MUST be assigned to someone working on that day.
excluded_rep_ids a list of rep to not include in possible return values.
121 122 123 124 125 126 127 128 129 |
# File 'app/models/assignment_queue.rb', line 121 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.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
132 133 134 135 136 |
# File 'app/models/assignment_queue.rb', line 132 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
82 83 84 |
# File 'app/models/assignment_queue.rb', line 82 def [] + VARIABLE_OPTIONS + TICKET_VARIABLE_OPTIONS + + end |
.queue_value_expanded(q) ⇒ Object
Translates a queue value to a friendly name
96 97 98 99 100 101 102 103 104 |
# File 'app/models/assignment_queue.rb', line 96 def (q) match = .detect { |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
43 44 45 |
# File 'app/models/assignment_queue.rb', line 43 def self.ransackable_attributes(_auth_object = nil) %w[id queue created_at updated_at] end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
39 40 41 |
# File 'app/models/assignment_queue.rb', line 39 def self.ransackable_scopes(_auth_object = nil) %i[containing_entry_named] end |
.rep_id_for_backup(rep_id) ⇒ Object
106 107 108 109 110 111 112 |
# File 'app/models/assignment_queue.rb', line 106 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
91 92 93 |
# File 'app/models/assignment_queue.rb', line 91 def Role..map { |r| [r[0], "LBR|#{r[1]}"] } end |
.select_options ⇒ Object
Provides a list of assignment queues to select from
62 63 64 |
# File 'app/models/assignment_queue.rb', line 62 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
77 78 79 |
# File 'app/models/assignment_queue.rb', line 77 def valid_values .map { |e| e[1] } end |
Instance Method Details
#activity_type_assignment_queues ⇒ ActiveRecord::Relation<ActivityTypeAssignmentQueue>
22 |
# File 'app/models/assignment_queue.rb', line 22 has_many :activity_type_assignment_queues, inverse_of: :assignment_queue |
#activity_types ⇒ ActiveRecord::Relation<ActivityType>
23 |
# File 'app/models/assignment_queue.rb', line 23 has_many :activity_types, through: :activity_type_assignment_queues |
#name ⇒ Object
210 211 212 213 214 |
# File 'app/models/assignment_queue.rb', line 210 def name queue.map { |e| self.class.(e) }.join(' -> ') rescue StandardError nil end |