Module: Tasks::SetCharacterisationDescriptorsHandler

Included in:
WorkflowsController
Defined in:
app/models/tasks/set_characterisation_descriptors_handler.rb

Instance Method Summary collapse

Instance Method Details

#do_set_characterisation_descriptors_task(_task, params) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/tasks/set_characterisation_descriptors_handler.rb', line 2

def do_set_characterisation_descriptors_task(_task, params)
  @count = 0
  if params[:values].nil?
    @values = {}
  else
    @values = params[:values]
  end

  # Perform the necessary updates if we've passed batch creation
  updated = 0

  @batch.requests.each do |request|
    event = LabEvent.new(batch_id: @batch.id, description: @task.name)

    if params[:requests].present? && params[:requests][(request.id).to_s].present? && params[:requests][(request.id).to_s][:descriptors].present?
      # Descriptors: create description for event

      event.descriptors = params[:requests][(request.id).to_s][:descriptors]
      event.descriptor_fields = ordered_fields(params[:requests][(request.id).to_s][:fields])

    end

    event.save!
    current_user.lab_events << event
    request.lab_events << event

    unless request.asset.try(:resource)
      EventSender.send_request_update(request.id, 'update', "Passed: #{@task.name}")
    end

    if request.has_passed(@batch, @task) || request.failed?
      updated += 1
    end
  end

  # Did all the requests get updated?
  if updated == @batch.requests.count
    eventify_batch @batch, @task
    return true
  else
    # Some requests have yet to pass this task
    # Construct a URL that contains a nested hash of values to display as defaults for the next request
    @params = { batch_id: @batch.id, workflow_id: @workflow.id, values: @values }
    redirect_to url_for(flatten_hash(@params))
  end

  false
end

#render_set_characterisation_descriptors_task(_task, params) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/tasks/set_characterisation_descriptors_handler.rb', line 51

def render_set_characterisation_descriptors_task(_task, params)
  @batch = Batch.includes(:requests, :pipeline, :lab_events).find(params[:batch_id])
  @rits = @batch.pipeline.request_information_types
  @requests = @batch.ordered_requests

  @workflow = Workflow.includes(:tasks).find(params[:workflow_id])
  @task = @workflow.tasks[params[:id].to_i]
  @stage = params[:id].to_i
  @count = 0
  if params[:values].nil?
    @values = {}
  else
    @values = params[:values]
  end
end