Class: SetDescriptorsTask
- Inherits:
-
Task
- Object
- ActiveRecord::Base
- ApplicationRecord
- Task
- SetDescriptorsTask
- Defined in:
- app/models/set_descriptors_task.rb
Overview
The SetDescriptorsTask presents a series of configured descriptors to the user, and lets them specify values for them. These values are the record in lab events created for each Request.
The per_item attribute, specifies whether the user is presented with a separate set of descriptors for each request, or if they are shared across the Batch. In either case, the user can deselect individual requests from a table at the top of the screen, to only apply their attributes to a subset of requests.
Instance Method Summary collapse
- #can_process?(batch) ⇒ Boolean
-
#descriptors_for(request) ⇒ Array<Descriptor>
Returns an array of Descriptor objects for the task, populated with the values for the most recent matching LabEvent on the Request.
-
#descriptors_with_values(values) ⇒ Array<Descriptor>
Returns an array of Descriptor objects for the task, populated with the values from the provided hash.
- #do_task(workflows_controller, params, user) ⇒ Object
- #partial ⇒ Object
-
#per_item_for(requests) ⇒ Object
Returns true if we should collect descriptors per request.
- #render_task(workflows_controller, params, user) ⇒ Object
Methods inherited from Task
#can_link_directly?, #included_for_do_task, #included_for_render_task
Methods inherited from ApplicationRecord
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
Instance Method Details
#can_process?(batch) ⇒ Boolean
15 16 17 |
# File 'app/models/set_descriptors_task.rb', line 15 def can_process?(batch) batch.released? ? [true, 'Edit'] : [true, nil] end |
#descriptors_for(request) ⇒ Array<Descriptor>
We can’t just use LabEvent#descriptors as it doesn’t return type information
Returns an array of Descriptor objects for the task, populated with the values for the most recent matching LabEvent on the Request
46 47 48 |
# File 'app/models/set_descriptors_task.rb', line 46 def descriptors_for(request) descriptors_with_values(descriptor_hash_for(request)) end |
#descriptors_with_values(values) ⇒ Array<Descriptor>
Returns an array of Descriptor objects for the task, populated with the values from the provided hash
58 59 60 61 62 63 64 |
# File 'app/models/set_descriptors_task.rb', line 58 def descriptors_with_values(values) descriptors.map do |descriptor| descriptor.dup.tap do |valued_descriptor| valued_descriptor.value = values.fetch(descriptor.name, descriptor.value) end end end |
#do_task(workflows_controller, params, user) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/models/set_descriptors_task.rb', line 28 def do_task(workflows_controller, params, user) Tasks::SetDescriptorsHandler::Handler.new( controller: workflows_controller, params: params, task: self, user: user ).perform end |
#partial ⇒ Object
11 12 13 |
# File 'app/models/set_descriptors_task.rb', line 11 def partial 'set_descriptors' end |
#per_item_for(requests) ⇒ Object
Returns true if we should collect descriptors per request. Always true if #per_item is true, otherwise true if requests have different values
69 70 71 |
# File 'app/models/set_descriptors_task.rb', line 69 def per_item_for(requests) per_item || requests.map { |request| descriptor_hash_for(request) }.uniq.many? end |
#render_task(workflows_controller, params, user) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/models/set_descriptors_task.rb', line 19 def render_task(workflows_controller, params, user) Tasks::SetDescriptorsHandler::Handler.new( controller: workflows_controller, params: params, task: self, user: user ).render end |