Class: RobotVerificationsController

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

Overview

rubocop:todo Style/Documentation

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Method Summary collapse

Methods inherited from ApplicationController

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

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Method Details

#barcode_hashObject


57
58
59
# File 'app/controllers/robot_verifications_controller.rb', line 57

def barcode_hash
  params.require(:barcodes)
end

#downloadObject

Step 3: Receives the submission form and checks if it is valid. In the event it is valid

provides a link to download the gwl/csv driver file for the robot. Otherwise
redirects the user back to step 1 with an error message.

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/robot_verifications_controller.rb', line 35

def download
  @robot = Robot.find(params[:robot_id])
  @robot_verification = @robot.verification_behaviour

  if @robot_verification.valid_submission?(params)
    @robot_verification.record_plate_types(params[:plate_types])
    @batch = Batch.find(params[:batch_id])
    @batch.robot_verified!(params[:user_id])
    @destination_plate_id = Plate.find_from_barcode(params[:destination_plate_barcodes].keys.first).human_barcode
    @pick_number = params[:pick_number]
  else
    flash[:error] = "Error: #{@robot_verification.errors.join('; ')}"
    redirect_to action: :index
  end
end

#find_barcodesObject


51
52
53
54
55
# File 'app/controllers/robot_verifications_controller.rb', line 51

def find_barcodes
  @robot = Robot.find_from_barcode(barcode_hash[:robot_barcode])
  @batch = Batch.find_from_barcode(barcode_hash[:batch_barcode])
  @user = User.find_with_barcode_or_swipecard_code(barcode_hash[:user_barcode])
end

#indexObject

Step 1: Renders a form asking for user barcode, batch barcode, robot barcode and destination plate barcode


5
6
# File 'app/controllers/robot_verifications_controller.rb', line 5

def index
end

#submissionObject

Step 2: Renders the bed verification form, in which the user is expected to scan in all beds and plates

This is generated based on the information provided in step 1.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/robot_verifications_controller.rb', line 10

def submission
  errors = []

  if @robot.nil?
    errors << "Could not find robot #{barcode_hash[:robot_barcode]}"
  else
    @robot_verification = @robot.verification_behaviour
    @robot_verification.validate_barcode_params(barcode_hash) { |message| errors.push(message) }
  end

  if errors.empty?
    @pick_number = Batch.extract_pick_number(barcode_hash[:batch_barcode])
    @dest_plates, @source_plates, @ctrl_plates = @robot.pick_number_to_expected_layout(
      @batch,
      barcode_hash[:destination_plate_barcode]
    )[@pick_number]
  else
    flash[:error] = errors
    redirect_to action: :index
  end
end