From 2f96a4609dbaba68d172d7ab4c53a6def82058a8 Mon Sep 17 00:00:00 2001 From: Katy Taylor Date: Mon, 22 Jun 2020 15:58:11 +0100 Subject: [PATCH 1/3] add a limit of 20 barcodes scanned - had to refactor logic a bit as well to avoid rubocop complexity issue --- app/controllers/process_plates_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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) From cdbae3b57681e98b53ca1dd18426a1b4c349a2ce Mon Sep 17 00:00:00 2001 From: Katy Taylor Date: Fri, 26 Jun 2020 13:52:24 +0100 Subject: [PATCH 2/3] Add a live count - number of barcodes scanned - goes red when over limit - also (20 max.) in brackets to show the limit --- app/views/bed_layouts/_default.html.haml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 From ff2589bf9d7468b6e37cb204e72afa82391133fd Mon Sep 17 00:00:00 2001 From: Katy Taylor Date: Tue, 30 Jun 2020 10:54:56 +0100 Subject: [PATCH 3/3] Change receiving plates limit to 15, as 20 is timing out - Make the receiving plates limit into a constant, so it's easier to change in future --- app/controllers/process_plates_controller.rb | 2 +- app/models/process_plate.rb | 1 + app/views/bed_layouts/_default.html.haml | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/process_plates_controller.rb b/app/controllers/process_plates_controller.rb index 70b49c3e..8ca1d01c 100644 --- a/app/controllers/process_plates_controller.rb +++ b/app/controllers/process_plates_controller.rb @@ -35,7 +35,7 @@ def create 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 + raise "Please scan #{ProcessPlate::RECEIVE_PLATES_MAX} barcodes or fewer" if barcodes.count > ProcessPlate::RECEIVE_PLATES_MAX responses = call_external_services(barcodes) @results = generate_results(barcodes, responses) diff --git a/app/models/process_plate.rb b/app/models/process_plate.rb index 9cbdc39e..8b676236 100644 --- a/app/models/process_plate.rb +++ b/app/models/process_plate.rb @@ -3,6 +3,7 @@ class ProcessPlate < ApplicationRecord include ProcessPlateValidation BARCODE_REGEX = /\S+/.freeze + RECEIVE_PLATES_MAX = 15 # @return [Sequencescape::Client::Api] An API object for interacting with the V1 API attr_writer :api diff --git a/app/views/bed_layouts/_default.html.haml b/app/views/bed_layouts/_default.html.haml index 2a58c653..495b7ba9 100644 --- a/app/views/bed_layouts/_default.html.haml +++ b/app/views/bed_layouts/_default.html.haml @@ -1,4 +1,4 @@ -%label{ :for => "source_plates" } Source plates (20 max.) +%label{ :for => "source_plates" }= "Source plates (#{ProcessPlate::RECEIVE_PLATES_MAX} max.)" = text_area_tag "source_plates", '', :rows => 5,:cols => 17 .live_results#barcodes_scanned 0 barcodes @@ -9,7 +9,7 @@ function recalcNumBarcodes(){ const num_barcodes = find_number_barcodes($('#source_plates').val()); - const colour = num_barcodes > 20 ? 'red' : 'black'; + const colour = num_barcodes > #{ProcessPlate::RECEIVE_PLATES_MAX} ? 'red' : 'black'; $('#barcodes_scanned').text(num_barcodes + ' barcodes').css('color', colour); }