diff --git a/app/controllers/barcode_labels_controller.rb b/app/controllers/barcode_labels_controller.rb index db67e62..62e098f 100644 --- a/app/controllers/barcode_labels_controller.rb +++ b/app/controllers/barcode_labels_controller.rb @@ -1,41 +1,40 @@ +require './lib/pmb_wrapper' + class BarcodeLabelsController < ApplicationController before_filter :initialize_printer_and_barcode_service + # Handles printing a single label + def individual + if print([params[:label]]) + redirect_to(params[:redirect_to], :notice => "Barcode printed to #{@printer.name}") + else + redirect_to(params[:redirect_to], :error => "Barcode failed to print to #{@printer.name}") + end + end + + # Handles printing multiple labels + def multiple + if print(params[:labels].values) + redirect_to(params[:redirect_to], :notice => "#{params[:labels].size} barcodes printed to #{@printer.try(:name)}") + else + redirect_to(params[:redirect_to], :error => "Barcodes failed to print to #{@printer.name}") + end + end + + private + def initialize_printer_and_barcode_service raise StandardError, "No printer specified!" if params[:printer].blank? - @printer = api.barcode_printer.find(params[:printer]) - @service = Sanger::Barcode::Printing::Service.new(@printer.service.url) @copies = params[:number].to_i end - private :initialize_printer_and_barcode_service - - # Creates a label - def create_label(details) - Sanger::Barcode::Printing::Label.new(details) - end - private :create_label # Does the actual printing of the labels passed def print(labels) - @service.print_labels(Array(labels)*@copies, @printer.name, @printer.type.layout) - end - private :print - - # Handles printing a single label - def individual - print(create_label(params[:label])) - redirect_to(params[:redirect_to], :notice => "Barcode printed to #{@printer.name}") - end - - before_filter :convert_labels_to_array, :only => :multiple - def convert_labels_to_array - params[:labels] = params.fetch(:labels, []).map { |_, v| v } - end - private :convert_labels_to_array - - # Handles printing multiple labels - def multiple - print(params[:labels].map(&method(:create_label))) - redirect_to(params[:redirect_to], :notice => "#{params[:labels].size} barcodes printed to #{@printer.try(:name)}") + PmbWrapper.new( + IlluminaCPipeline::Application.config.pmb_url, + @printer.name, + @printer.type.layout, + labels*@copies + ).print_label end end diff --git a/app/models/illumina_c/final_plate.rb b/app/models/illumina_c/final_plate.rb index d1648ce..3eb2175 100644 --- a/app/models/illumina_c/final_plate.rb +++ b/app/models/illumina_c/final_plate.rb @@ -61,4 +61,10 @@ def tubes_and_sources end end + attribute_group :barcode do + attribute_accessor :prefix, :number # The pieces that make up a barcode + attribute_accessor :ean13 # The EAN13 barcode number + attribute_accessor :machine # Barcode suitable for code39 + attribute_accessor :type # Frustratingly obtuse indicator of label type (1 = plate, 2= tube) + end end diff --git a/app/models/illumina_c/multiplexed_library_tube.rb b/app/models/illumina_c/multiplexed_library_tube.rb index 2281519..ad19f0e 100644 --- a/app/models/illumina_c/multiplexed_library_tube.rb +++ b/app/models/illumina_c/multiplexed_library_tube.rb @@ -7,4 +7,10 @@ def location 'A1' end + attribute_group :barcode do + attribute_accessor :prefix, :number # The pieces that make up a barcode + attribute_accessor :ean13 # The EAN13 barcode number + attribute_accessor :machine # Barcode suitable for code39 + attribute_accessor :type # Frustratingly obtuse indicator of label type (1 = plate, 2= tube) + end end diff --git a/app/models/illumina_c/plate.rb b/app/models/illumina_c/plate.rb index ff3f9a2..44f2248 100644 --- a/app/models/illumina_c/plate.rb +++ b/app/models/illumina_c/plate.rb @@ -13,6 +13,13 @@ def coerce 'ILC Lib Chromium' ] + attribute_group :barcode do + attribute_accessor :prefix, :number # The pieces that make up a barcode + attribute_accessor :ean13 # The EAN13 barcode number + attribute_accessor :machine # Barcode suitable for code39 + attribute_accessor :type # Frustratingly obtuse indicator of label type (1 = plate, 2= tube) + end + def is_a_final_pooling_plate? FINAL_POOLING_PLATE_PURPOSES.include?(plate_purpose.name) end diff --git a/app/models/illumina_c/stock_library_tube.rb b/app/models/illumina_c/stock_library_tube.rb index 5fb85ee..3e04ae6 100644 --- a/app/models/illumina_c/stock_library_tube.rb +++ b/app/models/illumina_c/stock_library_tube.rb @@ -4,4 +4,10 @@ def can_be_passed? ["pending", "started"].include? state end + attribute_group :barcode do + attribute_accessor :prefix, :number # The pieces that make up a barcode + attribute_accessor :ean13 # The EAN13 barcode number + attribute_accessor :machine # Barcode suitable for code39 + attribute_accessor :type # Frustratingly obtuse indicator of label type (1 = plate, 2= tube) + end end diff --git a/app/views/labware/_individual_barcode_printing_form.html.erb b/app/views/labware/_individual_barcode_printing_form.html.erb index 09580ce..9c728ca 100644 --- a/app/views/labware/_individual_barcode_printing_form.html.erb +++ b/app/views/labware/_individual_barcode_printing_form.html.erb @@ -7,7 +7,10 @@ <% end %> <%= f.hidden_field :prefix %> <%= f.hidden_field :number %> - <%= f.hidden_field :study, :value => text %> + <%= f.hidden_field :machine %> + <%= f.hidden_field :ean13 %> + <%= f.hidden_field :stock_barcode, :value => stock_barcode %> + <%= f.hidden_field :text, :value => text %>