From b7861f5fdb9186fd646f00b969ba3840d3b1a54b Mon Sep 17 00:00:00 2001 From: ajugo Date: Fri, 23 Sep 2022 12:34:43 +0200 Subject: [PATCH] Add zebra javascript print library [SCI-7245] (#4455) --- app/assets/javascripts/application.js.erb | 5 ++++ app/controllers/repository_rows_controller.rb | 2 +- app/models/label_printer.rb | 8 +----- config/application.rb | 2 +- config/initializers/assets.rb | 2 ++ .../javascripts/BrowserPrint-3.0.216.min.js | 16 ++++++++++++ .../BrowserPrint-Zebra-1.0.216.min.js | 26 +++++++++++++++++++ 7 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 vendor/assets/javascripts/BrowserPrint-3.0.216.min.js create mode 100644 vendor/assets/javascripts/BrowserPrint-Zebra-1.0.216.min.js diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index e4c23ae74..e5a89c76c 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -57,6 +57,11 @@ //= require sidebar //= require turbolinks +<% if Rails.configuration.x.zebra_print_enabled %> + //= require 'BrowserPrint-3.0.216.min' + //= require 'BrowserPrint-Zebra-1.0.216.min' +<% end %> + // Initialize links for submitting forms. This is useful for submitting // forms with clicking on links outside form in cases when other than // GET method is used. diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index c5866014b..3dde46e6b 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -108,7 +108,7 @@ class RepositoryRowsController < ApplicationController def print_modal @repository_rows = @repository.repository_rows.where(id: params[:rows]) - @printers = LabelPrinter.available_printers + @printers = LabelPrinter.all @label_templates = LabelTemplate.where(team_id: current_team).order(:name) respond_to do |format| format.json do diff --git a/app/models/label_printer.rb b/app/models/label_printer.rb index aa32d1780..0de3a17d9 100644 --- a/app/models/label_printer.rb +++ b/app/models/label_printer.rb @@ -11,7 +11,7 @@ class LabelPrinter < ApplicationRecord } ).freeze - enum type_of: { fluics: 0, zebra: 1 } + enum type_of: { fluics: 0 } enum language_type: { zpl: 0 } enum status: { ready: 0, busy: 1, out_of_labels: 2, unreachable: 3, error: 4 } @@ -19,12 +19,6 @@ class LabelPrinter < ApplicationRecord validates :type_of, presence: true validates :language_type, presence: true - def self.available_printers - printers = all - printers = printers.where.not(type_of: :zebra) unless Rails.configuration.x.zebra_print_enabled - printers - end - def display_name "#{name} • #{description}" end diff --git a/config/application.rb b/config/application.rb index 38948c7e7..dcbbdaa1c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -57,7 +57,7 @@ module Scinote config.x.webhooks_enabled = ENV['ENABLE_WEBHOOKS'] == 'true' - config.x.zebra_print_enabled = false + config.x.zebra_print_enabled = ENV['SCINOTE_ZEBRA_PRINT_ENABLED'] == 'true' # Logging config.log_formatter = proc do |severity, datetime, progname, msg| diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 00d995c5d..d8d6553fd 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -93,6 +93,8 @@ Rails.application.config.assets.precompile += %w(reports/reports_datatable.js) Rails.application.config.assets.precompile += %w(reports/save_pdf_to_inventory.js) Rails.application.config.assets.precompile += %w(reports/content.js) Rails.application.config.assets.precompile += %w(label_templates/label_templates_datatable.js) +Rails.application.config.assets.precompile += %w(BrowserPrint-3.0.216.min.js) +Rails.application.config.assets.precompile += %w(BrowserPrint-Zebra-1.0.216.min.js) # Libraries needed for Handsontable formulas Rails.application.config.assets.precompile += %w(jquery.js) diff --git a/vendor/assets/javascripts/BrowserPrint-3.0.216.min.js b/vendor/assets/javascripts/BrowserPrint-3.0.216.min.js new file mode 100644 index 000000000..063a6a5cd --- /dev/null +++ b/vendor/assets/javascripts/BrowserPrint-3.0.216.min.js @@ -0,0 +1,16 @@ +var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.checkStringArgs=function(b,h,c){if(null==b)throw new TypeError("The 'this' value for String.prototype."+c+" must not be null or undefined");if(h instanceof RegExp)throw new TypeError("First argument to String.prototype."+c+" must not be a regular expression");return b+""};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1; +$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(b,h,c){b!=Array.prototype&&b!=Object.prototype&&(b[h]=c.value)};$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this); +$jscomp.polyfill=function(b,h,c,e){if(h){c=$jscomp.global;b=b.split(".");for(e=0;e=p}},"es6","es3"); +var BrowserPrint=function(){function b(a,b){var d=new XMLHttpRequest;"withCredentials"in d?d.open(a,b,!0):"undefined"!=typeof XDomainRequest?(d=new XDomainRequest,d.open(a,b)):d=null;return d}function h(a,b,d){void 0===b&&(b=e.defaultSuccessCallback);void 0===d&&(d=e.defaultErrorCallback);return c(a,b,d)}function c(a,b,d){a.onreadystatechange=function(){a.readyState===XMLHttpRequest.DONE&&200===a.status?""===a.responseType?b(a.responseText):b(a.response):a.readyState===XMLHttpRequest.DONE&&(d?d(a.response): +console.log("error occurred with no errorCallback set."))};return a}var e={},k={},p=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);navigator.userAgent.indexOf("Trident/7.0");var l="http://127.0.0.1:9100/";p&&"https:"===location.protocol&&(l="https://127.0.0.1:9101/");e.Device=function(a){var m=this;this.name=a.name;this.deviceType=a.deviceType;this.connection=a.connection;this.uid=a.uid;this.version=2;this.provider=a.provider;this.manufacturer=a.manufacturer;this.readRetries="bluetooth"=== +this.connection?1:0;this.sendErrorCallback=function(d){};this.sendFinishedCallback=function(d){};this.readErrorCallback=function(d){};this.readFinishedCallback=function(d){};this.send=function(d,a,f){var g=b("POST",l+"write");g&&(void 0!==m&&(void 0===a&&(a=m.sendFinishedCallback),void 0===f&&(f=m.sendErrorCallback)),c(g,a,f),g.send(JSON.stringify({device:{name:this.name,uid:this.uid,connection:this.connection,deviceType:this.deviceType,version:this.version,provider:this.provider,manufacturer:this.manufacturer}, +data:d})))};this.sendUrl=function(d,a,f,e){var g=b("POST",l+"write");g&&(c(m,g,a,f),d={device:{name:this.name,uid:this.uid,connection:this.connection,deviceType:this.deviceType,version:this.version,provider:this.provider,manufacturer:this.manufacturer},url:d},null!=e&&void 0!=e&&(d.options=e),g.send(JSON.stringify(d)))};this.sendFile=function(d,a,f){if("string"===typeof d)e.loadFileFromUrl(d,function(d){m.sendFile(d,a,f)},f);else{var g=b("POST",l+"write");if(g){g.responseType="text";h(g,a,f);var c= +new FormData,n={};n.device=m;c.append("json",JSON.stringify(n));c.append("blob",d);g.send(c)}}};this.convertAndSendFile=function(d,a,b,c){c||(c={});c.action||(c.action="print");e.convert(d,this,c,a,b)};this.read=function(d,a){var f=b("POST",l+"read");f&&(void 0!==m&&(void 0===d&&(d=m.readFinishedCallback),void 0===a&&(a=m.readErrorCallback)),c(f,d,a),f.send(JSON.stringify({device:{name:this.name,uid:this.uid,connection:this.connection,deviceType:this.deviceType,version:this.version,provider:this.provider, +manufacturer:this.manufacturer}})))};this.readUntilStringReceived=function(d,a,b,e,c){c||(c="");void 0===e&&(e=this.readRetries);a=function(a,b,e,f,g){return function(c){if(c&&0!==c.length)f=0;else if(0>=f){b(g);return}c=g+c;""!==d&&-1