diff --git a/app/assets/javascripts/qc.js.erb b/app/assets/javascripts/qc.js.erb index b547f39e..f58edbbc 100644 --- a/app/assets/javascripts/qc.js.erb +++ b/app/assets/javascripts/qc.js.erb @@ -106,25 +106,25 @@ }, setTitle: function(title) {this.element.find('.panel-heading h2').text(title);}, humanBarcode: function() { - return this.asset.barcode.prefix+this.asset.barcode.number + return this.asset.barcode.human_readable }, setBarcode: function() { this.element.find('.asset-ean13').val(this.asset.barcode.ean13); }, setBarcodeForm: function() { - var study, number; + var study, barcode; if (this.asset.handle.with==='plate_conversion') { return true; }; if (this.asset.handle.with==='qa_plate_conversion') { return true; }; study = document.createElement('input') study.type = 'hidden' study.value = this.asset.purpose; study.name = 'study' - number = document.createElement('input') - number.value = this.asset.barcode.number; - number.name = 'numbers['+this.asset.barcode.number+']'; - number.type = 'hidden'; - this.element.find('.barcode-printing-form').append(study).append(number); - new BarcodePrinter(this.element.find('.barcode-printing-form'),this.asset.handle.printer,this.asset.barcode.prefix); + barcode = document.createElement('input') + barcode.value = this.asset.barcode.human_readable; + barcode.name = 'barcodes['+this.asset.barcode.human_readable+']'; + barcode.type = 'hidden'; + this.element.find('.barcode-printing-form').append(study).append(barcode); + new BarcodePrinter(this.element.find('.barcode-printing-form'),this.asset.handle.printer); }, setPurpose: function(purpose) { this.element.find('.purpose').text(purpose); @@ -328,13 +328,12 @@ /* Ideally this would go elsewhere, but then I'd either pollute the global namespace, or need to add dependency management */ - BarcodePrinter = function(form,type,prefix) { + BarcodePrinter = function(form,type) { this.form = $(form); this.form.on('submit',this.formSubmit()) this.type = type||this.type; this.form.find(this.remove()).hide(); this.form.find(this.show()).show(); - this.form.find('.prefix-field').val([prefix]); this.form.find('select').val($(this.show()).val()); } BarcodePrinter.prototype = { diff --git a/app/controllers/barcode_labels_controller.rb b/app/controllers/barcode_labels_controller.rb index c5028607..3a093a00 100644 --- a/app/controllers/barcode_labels_controller.rb +++ b/app/controllers/barcode_labels_controller.rb @@ -27,11 +27,10 @@ def create private def generate_labels - permitted_params = params.permit(:prefix, :study, numbers: {}) - @labels = (permitted_params[:numbers] || {}).to_h.map do |_, number| + permitted_params = params.permit(:study, barcodes: {}) + @labels = (permitted_params[:barcodes] || {}).to_h.map do |_, human_readable| BarcodeSheet::Label.new( - prefix: permitted_params[:prefix], - number:, + human_readable:, study: permitted_params[:study] ) end diff --git a/app/controllers/lots_controller.rb b/app/controllers/lots_controller.rb index a69e6ad1..3df9ff93 100644 --- a/app/controllers/lots_controller.rb +++ b/app/controllers/lots_controller.rb @@ -102,8 +102,10 @@ def search private def find_lot - @lot = api.lot.find(params[:id]) - rescue Sequencescape::Api::ResourceNotFound + @lot = Sequencescape::Api::V2::Lot.includes(:lot_type, :qcables).where(uuid: params[:id]).first + + return if @lot.present? + @message = "Could not find lot with uuid: #{params[:id]}" render 'pages/error', status: :not_found end diff --git a/app/models/barcode_sheet/label.rb b/app/models/barcode_sheet/label.rb index 04c5b2a4..81941e1c 100644 --- a/app/models/barcode_sheet/label.rb +++ b/app/models/barcode_sheet/label.rb @@ -73,7 +73,7 @@ def plate_double private def code39_barcode - @barcode || SBCF::SangerBarcode.new(prefix: @prefix, number: @number).human_barcode + @barcode || human_readable end def lot_template diff --git a/app/models/concerns/barcode_extensions.rb b/app/models/concerns/barcode_extensions.rb index 529c1fc8..ad5df7ed 100644 --- a/app/models/concerns/barcode_extensions.rb +++ b/app/models/concerns/barcode_extensions.rb @@ -4,4 +4,5 @@ module BarcodeExtensions def human_barcode "#{barcode.prefix}#{barcode.number}" end + alias human_readable human_barcode end diff --git a/app/models/presenter/lot.rb b/app/models/presenter/lot.rb index 77c122e2..2fa901b3 100644 --- a/app/models/presenter/lot.rb +++ b/app/models/presenter/lot.rb @@ -44,7 +44,11 @@ def printer_type def prefix return '' if @lot.qcables.empty? - @lot.qcables.first.barcode.prefix + qcable = @lot.qcables.first + + labware_prefix(qcable) || + barcode_prefix(qcable) || + '' end ## @@ -89,8 +93,6 @@ def number_pending pending_qcable_uuids.count end - private - def state_index(state) %w( created @@ -111,4 +113,31 @@ def sorted_qcables def state_counts @counts ||= sorted_qcables.map { |state, qcables| [state, qcables.count] } end + + private + + def labware_prefix(qcable) + return unless qcable.respond_to?(:labware_barcode) + + human = human_barcode(qcable) + return unless human + + human[/\A([A-Za-z]+)/, 1] + end + + def barcode_prefix(qcable) + return unless qcable.respond_to?(:barcode) + + barcode = qcable.barcode + return unless barcode.respond_to?(:prefix) + + barcode.prefix + end + + def human_barcode(qcable) + lb = qcable.labware_barcode + return unless lb + + (lb['human_barcode'] || lb[:human_barcode])&.to_s + end end diff --git a/app/models/presenter/qc_asset.rb b/app/models/presenter/qc_asset.rb index 30ba552e..2f7cb517 100644 --- a/app/models/presenter/qc_asset.rb +++ b/app/models/presenter/qc_asset.rb @@ -31,8 +31,7 @@ def child_type def barcode { 'ean13' => @asset.barcode.ean13, - 'prefix' => @asset.barcode.prefix, - 'number' => @asset.barcode.number + 'human_readable' => human_readable } end @@ -61,6 +60,50 @@ def output } } end + def human_readable + direct_human_readable || + direct_human_barcode || + barcode_fallback || + '' + end + + def direct_human_readable + return unless @asset.respond_to?(:human_readable) + + @asset.human_readable + end + + def direct_human_barcode + return unless @asset.respond_to?(:human_barcode) + + @asset.human_barcode + end + + def barcode_fallback + return unless @asset.respond_to?(:barcode) + + barcode = @asset.barcode + + object_barcode(barcode) || + hash_barcode(barcode) + end + + def object_barcode(barcode) + return unless barcode.respond_to?(:prefix) && barcode.respond_to?(:number) + + "#{barcode.prefix}#{barcode.number}" + end + + def hash_barcode(barcode) + return unless barcode.is_a?(Hash) + + prefix = barcode['prefix'] || barcode[:prefix] + number = barcode['number'] || barcode[:number] + return unless prefix || number + + "#{prefix}#{number}" + end + private def own_purpose_config diff --git a/app/models/presenter/qcable.rb b/app/models/presenter/qcable.rb index 38ff1f2a..1438e7d9 100644 --- a/app/models/presenter/qcable.rb +++ b/app/models/presenter/qcable.rb @@ -18,15 +18,55 @@ def index @qcable.stamp_index ? @qcable.stamp_index + 1 : '-' end + def human_readable + labware_human_barcode || + barcode_machine || + barcode_prefix_number || + '' + end + def barcode - "#{@qcable.barcode.prefix}#{@qcable.barcode.number}" + human_readable end - def number - @qcable.barcode.number.to_s + private + + def labware_human_barcode + return unless @qcable.respond_to?(:labware_barcode) + + lb = @qcable.labware_barcode + return unless lb.is_a?(Hash) + + (lb['human_barcode'] || lb[:human_barcode])&.to_s end - delegate :uuid, to: :@qcable + def barcode_machine + return unless @qcable.respond_to?(:barcode) + + bc = @qcable.barcode + + if bc.is_a?(Hash) + machine = bc['machine'] || bc[:machine] + machine&.to_s + elsif bc.respond_to?(:machine) + bc.machine&.to_s + end + end + + def barcode_prefix_number + return unless @qcable.respond_to?(:barcode) + + bc = @qcable.barcode + if bc.is_a?(Hash) + prefix = bc['prefix'] || bc[:prefix] + number = bc['number'] || bc[:number] + "#{prefix}#{number}" + elsif bc.respond_to?(:prefix) && bc.respond_to?(:number) + "#{bc.prefix}#{bc.number}" + end + end + + delegate :uuid, to: :@qcable alias id uuid end diff --git a/app/views/lots/_child_row.erb b/app/views/lots/_child_row.erb index 526327d1..6cb93233 100644 --- a/app/views/lots/_child_row.erb +++ b/app/views/lots/_child_row.erb @@ -1,5 +1,5 @@