Class: PlatePicksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plate_picks_controller.rb

Overview

Provides an interactive interface for quickly organizing plates into their associated picks.

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Method Details

#batchesObject

rubocop:enable Metrics/MethodLength



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/plate_picks_controller.rb', line 46

def batches # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  batch = Batch.find(params[:id])

  # Either we're not a cherrypick batch, or we haven't been processed

  return render json: { errors: 'Batch has no pick information' }, status: 409 unless batch.pick_information?

  robot = batch.robot_id ? Robot.find(batch.robot_id) : Robot.with_verification_behaviour.first

  # Extract the plates in advance in a single query. This optimizes performance
  plate_information =
    batch
      .input_labware
      .includes(:batches_as_source, :barcodes)
      .where(batches: { pipeline_id: CherrypickPipeline.all, state: CherrypickPipeline::PICKED_STATES })
      .index_by(&:machine_barcode)
      .transform_values do |plate|
        {
          id: plate.id,
          barcode: plate.machine_barcode,
          batches: plate.batches_as_source.ids.sort.map(&:to_s),
          control: plate.pick_as_control?
        }
      end

  picks = robot.all_picks(batch)

  render json: PlatePicks::BatchesJson.new(batch.id, picks, plate_information).to_json
rescue ActiveRecord::RecordNotFound
  render json: { errors: 'Could not find batch in Sequencescape' }, status: 404
end

#platesObject

rubocop:todo Metrics/MethodLength



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
# File 'app/controllers/plate_picks_controller.rb', line 11

def plates # rubocop:todo Metrics/AbcSize
  plate = Plate.find_by_barcode(params[:barcode])
  if plate.present?
    # Control plates are associated with a LOT of batches, and it doesn't really
    # make sense to load the entire list. We handle this in two ways:
    # 1. Don't waste time looking up the batches, and return an empty array
    # 2. Flag the plate as a control to allow us to apply appropriate styling.
    batches =
      if plate.pick_as_control?
        []
      else
        plate
          .batches_as_source
          .for_pipeline(CherrypickPipeline.all)
          .where(state: CherrypickPipeline::PICKED_STATES)
          .ids
          .sort
          .map(&:to_s)
      end

    render json: {
             plate: {
               id: plate.id,
               barcode: plate.machine_barcode,
               batches: batches,
               control: plate.pick_as_control?
             }
           }
  else
    render json: { errors: 'Could not find plate in Sequencescape' }, status: 404
  end
end

#showObject

Renders the plate_pick vue app



6
7
8
# File 'app/controllers/plate_picks_controller.rb', line 6

def show
  render :show
end