Skip to content

Commit

Permalink
Merge pull request #182 from sanger/GPL-547-times-out-when-scanning
Browse files Browse the repository at this point in the history
Gpl 547 times out when scanning
  • Loading branch information
KatyTaylor authored Jun 29, 2020
2 parents cebad1a + cdbae3b commit aee0fb6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/controllers/process_plates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ def create
)
raise format_errors(bed_layout_verification) unless bed_layout_verification.validate_and_create_audits?(params)

back_to_new_with_message('Success') && return unless receive_plates_process?(params)
unless receive_plates_process?(params)
back_to_new_with_message('Success')
return
end

# here on is relevant to 'receiving plates' only
# the param is called 'source_plates' but we could be working with tube racks or plates etc.
barcodes = sanitize_barcodes(params[:source_plates])
raise 'No barcodes were provided' if barcodes.empty?
# 20 barcodes takes about 2 mins as of 2020-06-22. This limit is to prevent the request timing out.
raise 'Please scan 20 barcodes or fewer' if barcodes.count > 20

responses = call_external_services(barcodes)
@results = generate_results(barcodes, responses)
Expand Down
21 changes: 18 additions & 3 deletions app/views/bed_layouts/_default.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
%label{ :for => "source_plates" } Source plates
%label{ :for => "source_plates" } Source plates (20 max.)
= text_area_tag "source_plates", '', :rows => 5,:cols => 17
.live_results#barcodes_scanned 0 barcodes

:javascript
$('#source_plates').focus();
$('#source_plates').trigger('change');
$('#source_plates').focus();
$('#source_plates').trigger('change');
$('#source_plates').keyup(recalcNumBarcodes);

function recalcNumBarcodes(){
const num_barcodes = find_number_barcodes($('#source_plates').val());
const colour = num_barcodes > 20 ? 'red' : 'black';

$('#barcodes_scanned').text(num_barcodes + ' barcodes').css('color', colour);
}

function find_number_barcodes(text){
const barcodes_list_no_blanks = text.split(/\s+/).filter(barcode => Boolean(barcode));
const barcodes_list_unique = [...new Set(barcodes_list_no_blanks)];
return barcodes_list_unique.length;
}

0 comments on commit aee0fb6

Please sign in to comment.