Skip to content
Open
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
19 changes: 9 additions & 10 deletions app/assets/javascripts/qc.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/barcode_labels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/lots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/barcode_sheet/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/barcode_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module BarcodeExtensions
def human_barcode
"#{barcode.prefix}#{barcode.number}"
end
alias human_readable human_barcode
end
35 changes: 32 additions & 3 deletions app/models/presenter/lot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
''
Comment on lines +49 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: could this be on one line?

end

##
Expand Down Expand Up @@ -89,8 +93,6 @@ def number_pending
pending_qcable_uuids.count
end

private

def state_index(state)
%w(
created
Expand All @@ -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
Comment on lines +138 to +141
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: I see this is old code, but I think the intent could be better indicated using symbolize_keys?

Suggest something like:

lb = qcable.labware_barcode&.symbolize_keys
return unless lb

lb[:human_barcode].to_s

end
end
47 changes: 45 additions & 2 deletions app/models/presenter/qc_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: possibly use symbolize_keys here too


"#{prefix}#{number}"
end

private

def own_purpose_config
Expand Down
48 changes: 44 additions & 4 deletions app/models/presenter/qcable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: possibly use symbolize_keys here too

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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: possibly use symbolize_keys here too

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: possibly use symbolize_keys here too


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
4 changes: 2 additions & 2 deletions app/views/lots/_child_row.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tr id='<%= state %>_plate_<%= child.index %>'>
<td class='plate_index'><%= child.index %></td>
<td class='plate_barcode'><%= child.barcode %></td>
<td><input type='checkbox' id='selected[<%= child.id %>]' name='numbers[<%= child.number %>]' value='<%= child.number %>'/></td>
<td class='plate_barcode'><%= child.human_readable %></td>
<td><input type='checkbox' id='selected[<%= child.id %>]' name='barcodes[<%= child.human_readable %>]' value='<%= child.human_readable %>'/></td>
</tr>
1 change: 0 additions & 1 deletion app/views/lots/_children.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</div>

<input type='hidden' name="study" value="<%= "#{lot.lot_number}:#{lot.template_name}" %>" />
<input type='hidden' name="prefix" value="<%= lot.prefix %>"/>

<div class="form-group">
<label for="barcode_printer" class="col-sm-5 control-label">Barcode Printer</label>
Expand Down
1 change: 0 additions & 1 deletion app/views/qc_assets/_asset_template.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<%= form_tag({controller: 'barcode_labels',action: :create},{class: 'barcode-printing-form'}) do %>
<input type='hidden' class="prefix-field" name="prefix" value="DN" />
<div class="form-group">
<label for="barcode_printer" class="col-sm-5 control-label">Barcode Printer</label>
<div class="input-group col-sm-6">
Expand Down
2 changes: 1 addition & 1 deletion app/views/qc_decisions/_qc_plates.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<% presenter.each_plate_in('qc_in_progress') do |plate| -%>
<div class="form-group">
<label for="decisions[<%= plate.uuid %>]" class="col-sm-5 control-label"><%= plate.barcode %></label>
<label for="decisions[<%= plate.uuid %>]" class="col-sm-5 control-label"><%= plate.human_readable %></label>
<div class="input-group col-sm-6">
<select class="form-control" id="decisions[<%= plate.uuid %>]" name="decisions[<%= plate.uuid %>]">
<option value="" >No decision</option>
Expand Down
6 changes: 2 additions & 4 deletions test/controllers/barcode_labels_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ class BarcodeLabelsControllerTest < ActionController::TestCase
setup do
mock_api
@params = {
prefix: 'ABC',
study: 'Study1',
numbers: { '123' => '123', '456' => '456' },
barcodes: { 'ABC123' => 'ABC123', 'ABC456' => 'ABC456' },
# Test printer name
barcode_printer: 'baac0dea-0000-0000-0000-000000000000'
}
Expand Down Expand Up @@ -68,8 +67,7 @@ class BarcodeLabelsControllerTest < ActionController::TestCase
controller.send(:generate_labels)
labels = controller.instance_variable_get(:@labels)
assert_equal 2, labels.size
assert_equal 'ABC', labels.first.instance_variable_get(:@prefix)
assert_equal '123', labels.first.instance_variable_get(:@number)
assert_equal 'ABC123', labels.first.instance_variable_get(:@human_readable)
assert_equal 'Study1', labels.first.instance_variable_get(:@legacy_study)
end
end
Loading