diff --git a/.gitignore b/.gitignore index 28d62e2..e6aff51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .DS_Store -/help + diff --git a/help/LabelTemplates b/help/LabelTemplates index 7605d4e..2004b9b 100644 --- a/help/LabelTemplates +++ b/help/LabelTemplates @@ -14,7 +14,7 @@ } //label template for tubes -//check label_type_id +//check label_type_id (mine is 9) {"data": {"attributes": @@ -35,6 +35,29 @@ } } +//label template for tubes with ean13 barcode +//check label_type_id + +{"data": + {"attributes": + {"name":"multiple_labels_walk_up_tube_ean13", + "label_type_id": 5, + "labels_attributes":[ + {"name": "main_label", + "bitmaps_attributes": [ + {"x_origin":"0100", "y_origin":"0030", "field_name":"middle_line", "horizontal_magnification":"05", "vertical_magnification":"05", "font":"H", "space_adjustment":"02", "rotational_angles":"11"}, + {"x_origin":"0240", "y_origin":"0200", "field_name":"round_label", "horizontal_magnification":"05", "vertical_magnification":"1", "font":"G", "space_adjustment":"00", "rotational_angles":"00"} + ], + "barcodes_attributes" : [ + {"x_origin":"0020", "y_origin":"0300", "field_name":"barcode", "barcode_type":"5", "one_module_width":"02", "height":"0070", "rotational_angle":null, "one_cell_width":null, "type_of_check_digit":"2", "bar_height":null, "no_of_columns":null} + ] + } + ] + } + } +} + + //label_type for plates {"data" => @@ -50,7 +73,7 @@ } //label template plate -//check label_type_id +//check label_type_id (mine is 8) {"data": {"attributes": @@ -70,6 +93,50 @@ } } +//label template plate with ean13 barcode +//check label_type_id + +{"data": + {"attributes": + {"name":"multiple_labels_walk_up_plate_ean13", + "label_type_id": 1, + "labels_attributes":[ + {"name": "main_label", + "bitmaps_attributes" : [ + {"x_origin":"0030", "y_origin":"0050", "field_name":"middle_line", "horizontal_magnification":"05", "vertical_magnification":"1", "font":"G", "space_adjustment":"00", "rotational_angles":"00"} + ], + "barcodes_attributes" : [ + {"x_origin":"0300", "y_origin":"0000", "field_name":"barcode", "barcode_type":"5", "one_module_width":"02", "height":"0070", "rotational_angle":null, "one_cell_width":null, "type_of_check_digit":"2", "bar_height":null, "no_of_columns":null} + ] + } + ] + } + } +} + +//label template plate with ean13 12-digit barcode (UPC-A) +//check label_type_id + +{"data": + {"attributes": + {"name":"multiple_labels_walk_up_plate_ean13", + "label_type_id": 1, + "labels_attributes":[ + {"name": "main_label", + "bitmaps_attributes" : [ + {"x_origin":"0030", "y_origin":"0050", "field_name":"middle_line", "horizontal_magnification":"05", "vertical_magnification":"1", "font":"G", "space_adjustment":"00", "rotational_angles":"00"} + ], + "barcodes_attributes" : [ + {"x_origin":"0300", "y_origin":"0000", "field_name":"barcode", "barcode_type":"K", "one_module_width":"02", "height":"0070", "rotational_angle":null, "one_cell_width":null, "type_of_check_digit":"2", "bar_height":null, "no_of_columns":null} + ] + } + ] + } + } +} + + + //label template plate - suitable for small labels //check label_type_id @@ -89,4 +156,25 @@ ] } } +} + +//label template plate - suitable for small labels - ean13 barcode +//check label_type_id + +{"data": + {"attributes": + {"name":"multiple_labels_walk_up_plate_small_ean13", + "label_type_id": 1, + "labels_attributes":[ + {"name": "main_label", + "bitmaps_attributes" : [ + {"x_origin":"0160", "y_origin":"0050", "field_name":"middle_line", "horizontal_magnification":"05", "vertical_magnification":"1", "font":"G", "space_adjustment":"00", "rotational_angles":"00"} + ], + "barcodes_attributes" : [ + {"x_origin":"0400", "y_origin":"0010", "field_name":"barcode", "barcode_type":"5", "one_module_width":"02", "height":"0070", "rotational_angle":null, "one_cell_width":null, "type_of_check_digit":"2", "bar_height":null, "no_of_columns":null} + ] + } + ] + } + } } \ No newline at end of file diff --git a/help/nginx.conf b/help/nginx.conf index 8eff6e4..54560e8 100644 --- a/help/nginx.conf +++ b/help/nginx.conf @@ -38,7 +38,7 @@ http { server_name localhost; location / { - root ../../../../webapps/label_printer; + root ../../../../webapps/label_printer/public; index index.html; } diff --git a/public/index.html b/public/index.html index 1afcdd3..da97336 100644 --- a/public/index.html +++ b/public/index.html @@ -20,15 +20,26 @@

Label printer

- - + + + +
+
+ +
- - + + +
+
+ +
@@ -36,15 +47,19 @@

Label printer

- + +
+
+ +
- - + +
- - + +
diff --git a/public/javascripts/Helpers.js b/public/javascripts/Helpers.js index 2919002..a188af4 100644 --- a/public/javascripts/Helpers.js +++ b/public/javascripts/Helpers.js @@ -7,7 +7,7 @@ var toObject = function(array){ } var baseUrl = function(){ - return '/pmb' + return '/pmb/' } var refreshResult = function(){ diff --git a/public/javascripts/PrepareForm.js b/public/javascripts/PrepareForm.js index e537ba6..d9849a0 100644 --- a/public/javascripts/PrepareForm.js +++ b/public/javascripts/PrepareForm.js @@ -1,3 +1,7 @@ +var tubeLabelBarcodeMaxlength = 2; +var plateLabelBarcodeMaxlength = 17; +var smallPlateLabelBarcodeMaxlength = 13; + var addPrinters = function(data){ var printers_names = new Array; @@ -19,21 +23,72 @@ var getPrinters = function(){ }) }; -var removeFromAndTo = function(){ - if($(this).val().length ==0){ - $("label[for='from']").show(); - $('#from').show(); - $("label[for='to']").show(); - $('#to').show(); +var hideWalkUpInputs = function(){ + $("label[for='from']").hide(); + $('#from').hide().val(''); + $("label[for='to']").hide(); + $('#to').hide().val(''); +} + +var showWalkUpInputs = function(){ + $("label[for='from']").show(); + $('#from').show(); + $("label[for='to']").show(); + $('#to').show(); +} + +var hideBarcodeInput = function(){ + $("label[for='barcode']").hide(); + $('#barcode').hide().val(''); +} + +var showBarcodeInput = function(){ + $("label[for='barcode']").show(); + $('#barcode').show(); +} + +var formSetup = function(){ + $("#labels_options").val('with_barcode') + hideWalkUpInputs() + $("#labware_type").val('plate') + $('#barcode').attr('maxlength', plateLabelBarcodeMaxlength); + getPrinters() +} + +var changeFormBasedOnLabwareType = function () { + $('#small').prop('checked', false); + $('#ean13').prop('checked', false); + if ($('#labware_type').val() == 'tube') { + $("label[for='size']").prop('hidden', true) + $('#small').prop('hidden', true) + $('#barcode').attr('maxlength', tubeLabelBarcodeMaxlength) } else { - $("label[for='from']").hide(); - $('#from').hide().val(''); - $("label[for='to']").hide(); - $('#to').hide().val(''); - }; + $('#barcode').attr('maxlength', plateLabelBarcodeMaxlength) + } +} + +var changeBarcodeLengthIfLabelSizeHasChanged = function() { + if (this.checked) { + $('#barcode').attr('maxlength', smallPlateLabelBarcodeMaxlength) + } else { + changeFormBasedOnLabwareType(); + } } -var disableCheckboxIfTube = function () { - $("label[for='size']").prop('hidden', this.value == 'tube'); - $('#cbox').prop('hidden', this.value == 'tube').prop('checked', false); - } \ No newline at end of file +var changeBarcodeLengthIfBarcodeTypeChanged = function() { + if (this.checked) { + $('#barcode').attr('maxlength', '13') + } else { + changeFormBasedOnLabwareType(); + } +} + +var removeIrrelevantInputs = function () { + if (this.value =='with_barcode') { + showBarcodeInput() + hideWalkUpInputs() + } else { + hideBarcodeInput() + showWalkUpInputs() + } +} \ No newline at end of file diff --git a/public/javascripts/PrintJob.js b/public/javascripts/PrintJob.js index 27a0bbc..51b3345 100644 --- a/public/javascripts/PrintJob.js +++ b/public/javascripts/PrintJob.js @@ -2,11 +2,14 @@ PrintJob = function(data){ this.from = data['from']; this.to = data['to']; + this.number_of_copies = data['number_of_copies']; this.text = data['text']; - this.type = data['type']; + this.labware_type = data['labware_type']; this.printer_name = data['printer_name']; this.barcode = data['barcode']; this.size = (typeof data['size'] === 'undefined') ? '' : ('_' + data['size']); + //ean13 on my local for regular plates now is UPC-A (12 digits) + this.ean13 = (typeof data['ean13'] === 'undefined') ? '' : ('_' + data['ean13']); }; PrintJob.prototype.attributes = function(label_template_id){ @@ -17,13 +20,15 @@ PrintJob.prototype.labels = function(){ var result = new Array(); for (i = this.from; i <= this.to; i++) { label = this.label(String(i)); - result.push(label) + for (j = 1; j <= this.number_of_copies; j++) { + result.push(label) + } } return {"body" : result} }; PrintJob.prototype.label = function(number){ - switch (this.type) { + switch (this.labware_type) { case 'plate': return this.labelPlate(number); break; @@ -59,7 +64,7 @@ PrintJob.prototype.execute=function(){ } PrintJob.prototype.labelTemplateUrl=function(){ - var label_template_name = 'multiple_labels_walk_up_' + this.type + this.size + var label_template_name = 'multiple_labels_walk_up_' + this.labware_type + this.size + this.ean13 var label_template_url = baseUrl()+'label_templates?filter[name]=' + label_template_name return label_template_url }; diff --git a/public/javascripts/main.js b/public/javascripts/main.js index ea1e0a9..37b9d3f 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -1,11 +1,12 @@ $(document).ready(function() { - getPrinters() + formSetup() - $('#barcode').keyup(removeFromAndTo) - - $('#type').change(disableCheckboxIfTube); + $('#labels_options').change(removeIrrelevantInputs); + $('#labware_type').change(changeFormBasedOnLabwareType); + $('#small').change(changeBarcodeLengthIfLabelSizeHasChanged); + $('#ean13').change(changeBarcodeLengthIfBarcodeTypeChanged); $('form').submit(function(event) { refreshResult(); diff --git a/test/spec/PrepareFormSpec.js b/test/spec/PrepareFormSpec.js index 0a6976d..fe9edf8 100644 --- a/test/spec/PrepareFormSpec.js +++ b/test/spec/PrepareFormSpec.js @@ -67,21 +67,38 @@ describe("PrepareForm", function() { }); }); - it("should hide from and to if barcode is set", function(){ + it("should hide barcode if walk_up option was chosen", function(){ + loadFixtures( 'AppFixture.html'); + formSetup() + + expect($("#from")).toBeHidden(); + expect($("#to")).toBeHidden(); + expect($("#barcode")).toBeVisible(); + + var labels_options = $('#labels_options'); + labels_options.change(removeIrrelevantInputs) + labels_options.val('walk_up').change() expect($("#from")).toBeVisible(); expect($("#to")).toBeVisible(); + expect($("#barcode")).toBeHidden(); + }); - var barcode = $('#barcode'); - barcode.val('12345') - barcode.keyup(removeFromAndTo) - var event = jQuery.Event("keyup"); - barcode.trigger(event); + it("should hide small size option if tube was chosen", function(){ + loadFixtures( 'AppFixture.html'); + formSetup() + expect($("#small")).toBeVisible(); + expect($("#barcode").attr('maxlength')).toEqual('17'); + + var labware_type = $('#labware_type'); + labware_type.change(changeFormBasedOnLabwareType) + labware_type.val('tube').change() + + expect($("#small")).toBeHidden(); + expect($("#barcode").attr('maxlength')).toEqual('2'); - expect($("#from")).toBeHidden(); - expect($("#to")).toBeHidden(); }); }); \ No newline at end of file diff --git a/test/spec/PrintJobSpec.js b/test/spec/PrintJobSpec.js index 211b4b0..d5c8b2c 100755 --- a/test/spec/PrintJobSpec.js +++ b/test/spec/PrintJobSpec.js @@ -3,12 +3,12 @@ describe("PrintJob", function() { var label, labels, result, attributes; beforeEach(function() { - data = {'from': '1', 'to': '3', 'text': 'some_text', 'type': 'plate', 'printer_name': 'test', 'barcode': ''} + data = {'from': '1', 'to': '3', 'text': 'some_text', 'labware_type': 'plate', 'printer_name': 'test', 'barcode': '', 'number_of_copies': '1'} printJob = new PrintJob(data); }); it("should have attributes", function() { - expect(printJob.type).toEqual('plate'); + expect(printJob.labware_type).toEqual('plate'); expect(printJob.from).toEqual('1'); expect(printJob.to).toEqual('3'); expect(printJob.text).toEqual('some_text'); @@ -17,7 +17,7 @@ describe("PrintJob", function() { }); it("should have the right size attribute for small label", function(){ - data = {'from': '1', 'to': '3', 'text': 'some_text', 'type': 'plate', 'printer_name': 'test', 'barcode': '', 'size': 'small'} + data = {'from': '1', 'to': '3', 'text': 'some_text', 'labware_type': 'plate', 'printer_name': 'test', 'barcode': '', 'size': 'small', 'number_of_copies': '1'} printJob = new PrintJob(data); expect(printJob.size).toEqual('_small'); }); @@ -28,7 +28,7 @@ describe("PrintJob", function() { }); it("should create the right label for tube", function(){ - printJob.type = 'tube' + printJob.labware_type = 'tube' label = printJob.label(1); expect(label).toEqual({"main_label": {"middle_line": 'some_text 1', "round_label" : '1', 'barcode': ''}}); }); @@ -44,6 +44,19 @@ describe("PrintJob", function() { expect(labels).toEqual(result); }); + it("should create the right number of copies of each label", function(){ + data = {'from': '', 'to': '', 'text': 'some_text', 'labware_type': 'plate', 'printer_name': 'test', 'barcode': '123', 'number_of_copies': '3'} + printJob = new PrintJob(data); + labels = printJob.labels(); + result = {'body': + [{ 'main_label': { 'middle_line': 'some_text ', 'barcode': '123' }}, + { 'main_label': { 'middle_line': 'some_text ', 'barcode': '123' }}, + { 'main_label': { 'middle_line': 'some_text ', 'barcode': '123' }} + ] + } + expect(labels).toEqual(result); + }); + it("should create the right attributes", function(){ attributes = printJob.attributes(5); result = {"data": diff --git a/test/spec/javascripts/fixtures/AppFixture.html b/test/spec/javascripts/fixtures/AppFixture.html index d18ee32..52a3138 100644 --- a/test/spec/javascripts/fixtures/AppFixture.html +++ b/test/spec/javascripts/fixtures/AppFixture.html @@ -1,25 +1,36 @@
- - + + + +
+
+ +
- - + + +
+
+ +
- +
- - + +
- - + +
\ No newline at end of file