diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html index d0ce1d37cd9628917936501f521e86865e7e3dc4..c8b5fc355378f67167d90a8dcb67d8b0b3c8c8ba 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html @@ -88,6 +88,7 @@ <script type="text/javascript" src="./lib/bwip-js/lib/symdesc.js"></script> <script type="text/javascript" src="./lib/bwip-js/lib/canvas-toblob.js"></script> <script type="text/javascript" src="./lib/jspdf/js/jspdf.min.js"></script> + <script type="text/javascript" src="./lib/zxing-js/js/zxing-js-min.js"></script> <script type="text/javascript" src="./lib/react/react.production.min.js"></script> <script type="text/javascript" src="./lib/react/react-dom.production.min.js"></script> diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js index decc2afa9afa7630faf9249b1f5598e4bdbd5e26..d2f49b10bb86a0b33d4e01b6605ec90799a11f4d 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js @@ -1139,6 +1139,9 @@ function MainController(profile) { this._showBlancPage = function() { var content = this._getBackwardsCompatibleMainContainer(); content.append("Welcome to openBIS ELN-LIMS."); + this.currentView = { + content : content + } } this._showDrawingBoard = function() { diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js index 8edb7e0404ec80281c46eb595d9d43713bc3a912..eab26fc06bbf90637283ec1793dbfecca740630c 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/BarcodeUtil.js @@ -30,6 +30,73 @@ var BarcodeUtil = new function() { } } + var codeReader = null; + + this.readBarcodeFromCamera = function() { + if(codeReader != null) { + codeReader.reset(); + codeReader = null; + } + + // Steals the main controller to show the video feed and a cancel button + mainController.changeView("showBlancPage"); + var content = mainController.currentView.content; + content.empty(); + var $video = $("<video>", { id : "video", width : "100%", height : "100%" }); + content.append($("<h1>").text("Camera:")); + content.append(FormUtil.getButtonWithIcon("glyphicon-minus-sign", function() { + if(codeReader != null) { + codeReader.reset(); + codeReader = null; + } + }, "Cancel Barcode Reading")); + content.append($video); + + // Starts the camera reading code + codeReader = new ZXing.BrowserMultiFormatReader(); + codeReader.listVideoInputDevices().then((videoInputDevices) => { + const sourceSelect = document.getElementById('sourceSelect'); + selectedDeviceId = videoInputDevices[0].deviceId; + codeReader.decodeFromVideoDevice(selectedDeviceId, 'video', (result, err) => { + if(result && result.text) { + codeReader.reset(); + BarcodeUtil.readSample(result.text); + } + if (err && !(err instanceof ZXing.NotFoundException)) { + Util.showError("Failed to read barcode"); + } + }); + }); + } + + this.readBarcodeFromFile = function() { + var $input = $("<input>", { type : "file", accept : "image/*" }); + $input.click(); + $input.change(function(event) { +// const hints = new Map(); +// const formats = [ZXing.BarcodeFormat.QR_CODE /*, ...*/]; +// hints.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, formats); +// const codeReader = new ZXing.BrowserMultiFormatReader(hints); + const codeReader = new ZXing.BrowserMultiFormatReader(); + const fileReader = new FileReader(); + fileReader.readAsArrayBuffer(event.target.files[0]); + fileReader.onloadend = (evt) => { + if (evt.target.readyState === FileReader.DONE) { + var img = null; + img = Images.decodeArrayBuffer(evt.target.result, function(event) { + img.videoWidth = 0; // Bugfix so ZXing decodes the image instead throwing an exception + var result = codeReader.decode(img); + if(result && result.text) { + BarcodeUtil.readSample(result.text); + } else { + Util.showError("Failed to read barcode"); + } + }); + } + } + }) + }; + this.readSample = function(barcodeReaderInput) { barcodeReader = barcodeReaderInput; readSample(); diff --git a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js index 6a680ed09e01fe66a019fd9d7be4669c533d6634..5b9446efdadbef8e80baa7fdfc2d33878a17de95 100644 --- a/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js +++ b/ui-eln-lims/src/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js @@ -151,32 +151,8 @@ function SideMenuWidgetView(sideMenuWidgetController, sideMenuWidgetModel) { var barcodeReaderBtn = FormUtil.getButtonWithIcon( "glyphicon-barcode", - function () { - var $input = $("<input>", { type : "file", accept : "image/*" }); - $input.click(); - $input.change(function(event) { -// const hints = new Map(); -// const formats = [ZXing.BarcodeFormat.QR_CODE /*, ...*/]; -// hints.set(ZXing.DecodeHintType.POSSIBLE_FORMATS, formats); -// const codeReader = new ZXing.BrowserMultiFormatReader(hints); - const codeReader = new ZXing.BrowserMultiFormatReader(); - const fileReader = new FileReader(); - fileReader.readAsArrayBuffer(event.target.files[0]); - fileReader.onloadend = (evt) => { - if (evt.target.readyState === FileReader.DONE) { - var img = null; - img = Images.decodeArrayBuffer(evt.target.result, function(event) { - img.videoWidth = 0; // Bugfix so ZXing decodes the image instead throwing an exception - var result = codeReader.decode(img); - if(result && result.text) { - BarcodeUtil.readSample(result.text); - } else { - Util.showError("Failed to read barcode"); - } - }); - } - } - }) + function() { + BarcodeUtil.readBarcodeFromCamera(); }, null, null,