Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ def qcables
def create
raise 'You have not supplied a labware barcode' if params[:plate_barcode].blank?

result = find_labware(params[:plate_barcode])

respond_to do |format|
format.html { redirect_to result }
format.json { redirect_to result }
format.html { redirect_to find_labware(params[:plate_barcode]) }
format.json { render json: find_labware_for_pooling(params[:plate_barcode]) }
end
rescue StandardError => e
handle_create_error(e)
Expand All @@ -52,6 +50,40 @@ def find_labware(barcode)
.tap { |labware| raise "Sorry, could not find labware with the barcode '#{barcode}'." if labware.nil? }
end

def find_labware_for_pooling(barcode)
labware = find_labware(barcode)

case labware.type
when 'tubes'
tube =
Sequencescape::Api::V2::Tube.includes('receptacle.aliquots').find(uuid: labware.uuid).first
raise "Sorry, could not find labware with the barcode '#{barcode}'." if tube.nil?

{ 'tube' => {
'barcode' => tube.human_barcode,
'uuid' => tube.uuid,
'state' => tube.state,
'tags' => (tube.aliquots || []).map(&:tag_pair)
}
}
when 'plates'
plate =
Sequencescape::Api::V2::Plate.includes('wells.aliquots').find(uuid: labware.uuid).first
raise "Sorry, could not find labware with the barcode '#{barcode}'." if plate.nil?

{
'plate' => {
'barcode' => plate.human_barcode,
'uuid' => plate.uuid,
'state' => plate.state,
'tags' => plate.wells_in_columns.flat_map { |w| w.aliquots.map(&:tag_pair) }
}
}
else
raise "Sorry, labware type '#{labware.type}' is not supported for pooling."
end
end

def find_qcable(barcode)
includes = [:labware, { lot: [{ lot_type: :target_purpose }, :template] }].freeze

Expand Down
5 changes: 5 additions & 0 deletions app/frontend/entrypoints/pages/pooled_tubes.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ $('.labware-box').each(function () {
},
checkLabware: function (data, status, scanned_barcode) {
let response = data[this.dataset.labwareType]
if (response === undefined) {
this.badLabware()
SCAPE.message(`Scanned labware is not a ${this.dataset.labwareType} as expected.`, 'invalid')
return
}
if (SOURCE_STATES.indexOf(response.state) === -1) {
this.badLabware()
const msg = `Scanned ${this.dataset.labwareType}s are currently in a '${response.state}' state when they should be in one of: ${SOURCE_STATES.join(', ')}.`
Expand Down
9 changes: 6 additions & 3 deletions spec/controllers/searches_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@
expect(response).to redirect_to('/labware/ABC123')
end

it 'returns a JSON response with the labware location' do
it 'returns a JSON response with the labware data' do
labware_json = { 'tube' => { 'barcode' => 'DN123K', 'uuid' => 'some-uuid', 'state' => 'passed', 'tags' => [] } }
allow(controller).to receive(:find_labware_for_pooling).with(barcode).and_return(labware_json)

post :create, params: { plate_barcode: barcode }, format: :json
expect(response).to have_http_status(:found)
expect(response).to redirect_to('/labware/ABC123')
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to eq(labware_json)
end
end

Expand Down
Loading