Module: Tasks::AssignTagsHandler

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

Overview

Handles the behaviour of AssignTagsTask and included in WorkflowsController A Task used in library creation pipelines Applies the selected tags to the library tubes. Also appears to create and pool into a MultiplexedLibraryTube

Instance Method Summary collapse

Instance Method Details

#do_assign_tags_task(_task, params) ⇒ Object

rubocop:todo Metrics/MethodLength


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
50
51
# File 'app/models/tasks/assign_tags_handler.rb', line 13

def do_assign_tags_task(_task, params) # rubocop:todo Metrics/AbcSize
  if params[:mx_library_name].blank?
    flash[:warning] = 'Multiplexed library needs a name'
    redirect_to action: 'stage', batch_id: @batch.id, workflow_id: @workflow.id, id: (@stage - 1).to_s
    return false
  end
  if MultiplexedLibraryTube.exists?(name: params[:mx_library_name])
    flash[:warning] = 'Name already in use.'
    redirect_to action: 'stage', batch_id: @batch.id, workflow_id: @workflow.id, id: (@stage - 1).to_s
    return false
  end

  @tag_group = TagGroup.find(params[:tag_group])

  ActiveRecord::Base.transaction do
    multiplexed_library =
      Tube::Purpose.standard_mx_tube.create!(name: params[:mx_library_name], barcode: AssetBarcode.new_barcode)
    @batch.requests.each do |request|
      tag_id = params[:tag][request.id.to_s] or next
      tag = @tag_group.tags.find(tag_id)
      tag.tag!(request.target_asset)

      AssetLink.create_edge(request.target_asset.labware, multiplexed_library)

      request
        .next_requests
        .select(&:pending?)
        .each { |sequencing_request| sequencing_request.update!(asset: multiplexed_library) }

      TransferRequest.create!(
        asset: request.target_asset,
        target_asset: multiplexed_library.receptacle,
        state: 'passed'
      )
    end
  end

  true
end

#render_assign_tags_task(_task, params) ⇒ Object


5
6
7
8
9
10
# File 'app/models/tasks/assign_tags_handler.rb', line 5

def render_assign_tags_task(_task, params)
  @tag_group = TagGroup.find(params[:tag_group])
  @requests = @batch.requests
  @tags = @tag_group.tags.sorted
  @rits = @batch.pipeline.request_information_types
end