Class: SetDescriptorsTask

Inherits:
Task show all
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

Methods inherited from Task

#can_link_directly?, #find_batch, #find_batch_requests, #included_for_do_task, #included_for_render_task

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Instance Method Details

#can_process?(batch) ⇒ Boolean

Returns:

  • (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>

Note:

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

Parameters:

  • request (Request)

    The request to find the values for

Returns:

  • (Array<Descriptor>)

    Array of descriptors with appropriate values


38
39
40
# File 'app/models/set_descriptors_task.rb', line 38

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

Parameters:

  • values (Hash<String:String>)

    Hash of key-value pairs

Returns:

  • (Array<Descriptor>)

    Array of descriptors with appropriate values


50
51
52
53
54
55
56
# File 'app/models/set_descriptors_task.rb', line 50

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


24
25
26
27
# File 'app/models/set_descriptors_task.rb', line 24

def do_task(workflows_controller, params, user)
  Tasks::SetDescriptorsHandler::Handler.new(controller: workflows_controller, params: params, task: self, user: user)
    .perform
end

#partialObject


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


61
62
63
# File 'app/models/set_descriptors_task.rb', line 61

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
# 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