Add scan barcode button to home page

master
Skylar Ittner 4 years ago
parent 5b9601659b
commit 2605105867

47
package-lock.json generated

@ -231,6 +231,11 @@
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"interpret": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz",
"integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA=="
},
"is-obj": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
@ -305,6 +310,32 @@
"resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz",
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A="
},
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw=="
},
"phonegap-plugin-barcodescanner": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/phonegap-plugin-barcodescanner/-/phonegap-plugin-barcodescanner-8.1.0.tgz",
"integrity": "sha512-WQCDCoH9EQ9WEn2bce+B95jbNJduilAn2Vtske8KfcYAeGu7bdFqRD7zGCLCQao62VwoEwlX0cUvbQ/am12Jwg==",
"requires": {
"nopt": "^4.0.1",
"shelljs": "^0.8.3"
},
"dependencies": {
"shelljs": {
"version": "0.8.4",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz",
"integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==",
"requires": {
"glob": "^7.0.0",
"interpret": "^1.0.0",
"rechoir": "^0.6.2"
}
}
}
},
"plist": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/plist/-/plist-3.0.1.tgz",
@ -328,6 +359,22 @@
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc="
},
"rechoir": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
"integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
"requires": {
"resolve": "^1.1.6"
}
},
"resolve": {
"version": "1.17.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz",
"integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==",
"requires": {
"path-parse": "^1.0.6"
}
},
"sax": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.1.4.tgz",

@ -19,7 +19,8 @@
"author": "Netsyms Technologies",
"license": "MPL-2.0",
"dependencies": {
"cordova-android": "^8.1.0"
"cordova-android": "^8.1.0",
"phonegap-plugin-barcodescanner": "^8.1.0"
},
"cordova": {
"plugins": {
@ -28,8 +29,11 @@
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-headercolor": {}
"cordova-plugin-headercolor": {},
"phonegap-plugin-barcodescanner": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
}
}
},
"devDependencies": {}
}
}

@ -85,4 +85,9 @@ cd material-design-icons
find . -maxdepth 1 -not -name '.' -not -name 'LICENSE' -not -name 'iconfont' -exec rm -rf {} \;
cd $DIR
cd @zxing/library
rm -rf {esm,esm5}
rm -f umd/index.min.js.map
cd $DIR
echo "Cleanup finished"

@ -9,4 +9,12 @@
$("#machinesearchbar").submit(function (evt) {
evt.preventDefault();
openMachineInfo($("#machinesearchbar input[type=search]").val());
});
});
function scanBarcodeOpenMachine() {
scanBarcode(function (code) {
openMachineInfo(code);
}, function (error) {
app.dialog.alert(error, "Error");
});
}

@ -27,8 +27,61 @@ var openSystemBrowser = function (url) {
window.open(url);
}
var scanBarcode = function (success, error) {
app.dialog.alert("You can't scan barcodes with this device.", "Sorry!");
}
var scanningBarcode = false;
function setupHTML5BarcodeScanner() {
$("body").append('<script src="node_modules/@zxing/library/umd/index.min.js"></script>');
scanBarcode = function (success, error) {
scanningBarcode = true;
$("#web-barcode-ui").removeClass("hidden");
// Stolen from https://zxing-js.github.io/library/examples/multi-camera/
const codeReader = new ZXing.BrowserMultiFormatReader();
console.log("Info", 'ZXing code reader initialized');
codeReader.getVideoInputDevices()
.then((videoInputDevices) => {
if (videoInputDevices.length == 0) {
codeReader.reset();
$("#web-barcode-ui").addClass("hidden");
error("A camera is required to scan barcodes.");
return;
}
selectedDeviceId = videoInputDevices[0].deviceId;
codeReader.decodeFromInputVideoDeviceContinuously(selectedDeviceId, 'barcode-viewer', (result, err) => {
scanningBarcode = false;
if (result) {
codeReader.reset();
$("#web-barcode-ui").addClass("hidden");
success(result.text);
return;
}
if (err && !(err instanceof ZXing.NotFoundException)) {
console.error(err);
codeReader.reset();
$("#web-barcode-ui").addClass("hidden");
error(err);
return;
}
});
})
.catch((err) => {
scanningBarcode = false;
console.error(err);
});
$("#web-barcode-ui").on("click", function () {
codeReader.reset();
scanningBarcode = false;
$("#web-barcode-ui").addClass("hidden");
});
};
}
var getLocation = function (success, error) {
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function (position) {
@ -103,6 +156,36 @@ function initCordova() {
window.open(url, '_system', '');
}
if (typeof device != "undefined" && device.platform != "browser") {
scanBarcode = function (success, error) {
scanningBarcode = true;
cordova.plugins.barcodeScanner.scan(
function (result) {
scanningBarcode = false;
if (!result.cancelled) {
success(result.text);
}
},
function (err) {
scanningBarcode = false;
if (typeof error == "function") {
error(err);
}
},
{
showTorchButton: true,
showFlipCameraButton: true,
prompt: "Scan barcode",
resultDisplayDuration: 0,
disableSuccessBeep: true,
formats: "QR_CODE,DATA_MATRIX,CODE_39,CODE_93,CODE_128,CODABAR,PDF_417,AZTEC,MAXICODE"
}
);
};
} else {
setupHTML5BarcodeScanner();
}
// Handle geo: urls
$("#app").on("click", ".geolink", function (evt) {
window.open($(this).attr("href"), "_system");
@ -145,6 +228,8 @@ function initNW() {
require('nw.gui').Shell.openExternal(url);
}
setupHTML5BarcodeScanner();
// Handle geo: urls
$("#app").on("click", ".geolink", function (evt) {
require('nw.gui').Shell.openExternal($(this).attr("href"));
@ -163,6 +248,8 @@ function initBrowser() {
window.open(url);
}
setupHTML5BarcodeScanner();
$("#app").on("click", ".geolink", function (evt) {
window.open($(this).attr("href"), "_blank");
evt.preventDefault();

@ -9,6 +9,21 @@
"resolved": "https://npm.fontawesome.com/@fortawesome/fontawesome-pro/-/5.13.0/fontawesome-pro-5.13.0.tgz",
"integrity": "sha1-/eMu1NmTPEybYLinSnnGfrpY2YQ="
},
"@sinonjs/text-encoding": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz",
"integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==",
"optional": true
},
"@zxing/library": {
"version": "0.17.0",
"resolved": "https://registry.npmjs.org/@zxing/library/-/library-0.17.0.tgz",
"integrity": "sha512-P7T2k0y2mhtLyXDoHI4IzwD2KDId/CCi9PMy56Xvr2MCj+gO8RfAy0loOX9TF9eWmhi5LzbSxcz4Xkvi1Bs0/Q==",
"requires": {
"@sinonjs/text-encoding": "0.7.1",
"ts-custom-error": "^3.0.0"
}
},
"dom7": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/dom7/-/dom7-2.1.5.tgz",
@ -57,6 +72,11 @@
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/template7/-/template7-1.4.2.tgz",
"integrity": "sha512-eoKnScBMDk7lyj7+iCzKbxGiSLLlQk0DNvmclyJuMCUKxy9JrFuAB+GD5iplF4WiQPtMdI06CHHks3avL22JXA=="
},
"ts-custom-error": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/ts-custom-error/-/ts-custom-error-3.1.1.tgz",
"integrity": "sha512-f/syoy+pTE4z82qaiRuthEeZtCGNKzlfs0Zc8jpQFcz/CYMaFSwFSdfFt1sSFnPlDLOEm7RCROdIxZ44N8UlwA=="
}
}
}

@ -5,6 +5,7 @@
"license": "MPL-2.0",
"dependencies": {
"@fortawesome/fontawesome-pro": "^5.13.0",
"@zxing/library": "^0.17.0",
"framework7": "^5.5.1",
"framework7-icons": "^3.0.0",
"jquery": "^3.4.1",

@ -12,6 +12,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
<div class="navbar-inner">
<div class="title">MachineManager</div>
<div class="right">
<a class="link" href="#" onclick="scanBarcodeOpenMachine()">
<i class="fas fa-barcode-read"></i>
</a>
<a class="link" href="/settings">
<i class="material-icons if-md">settings</i>
<i class="fas fa-cog if-not-md"></i>

Loading…
Cancel
Save