diff --git a/app/controllers/process_plates_controller.rb b/app/controllers/process_plates_controller.rb index 811faa30..70b49c3e 100644 --- a/app/controllers/process_plates_controller.rb +++ b/app/controllers/process_plates_controller.rb @@ -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) diff --git a/app/views/bed_layouts/_default.html.haml b/app/views/bed_layouts/_default.html.haml index 908eff70..2a58c653 100644 --- a/app/views/bed_layouts/_default.html.haml +++ b/app/views/bed_layouts/_default.html.haml @@ -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'); \ No newline at end of file + $('#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; + } \ No newline at end of file