diff --git a/changelog/52_UNRELEASED_2019-xx-xx.md b/changelog/52_UNRELEASED_2019-xx-xx.md index 7d3b2402..66281ef2 100644 --- a/changelog/52_UNRELEASED_2019-xx-xx.md +++ b/changelog/52_UNRELEASED_2019-xx-xx.md @@ -80,7 +80,8 @@ - Danish (demo available at https://da.demo.grocy.info) - Dutch (demo available at https://nl.demo.grocy.info) - Internal change for how the localizations for the demo instances are handled - - Also for the pre-release demo now all currently supported languages are available + - For the pre-release demo now all currently supported languages are available (was already the case for the stable demo) + - Additionally all language files which reached the completion limit of 80 % will now be automatically pulled from Transifex 10 minutes past every hour (to have a kind of instant preview of changed tranlsations) - The URLs have changed, I'll try to keep all existing URLs redirecting properly for a long time - If you want to link to the demo, please only use https://demo.grocy.info (stable demo) or https://demo-prerelease.grocy.info (current master branch demo) diff --git a/controllers/SystemController.php b/controllers/SystemController.php index 85361cfb..36b5dbf3 100644 --- a/controllers/SystemController.php +++ b/controllers/SystemController.php @@ -96,4 +96,9 @@ class SystemController extends BaseController 'changelog' => $this->ApplicationService->GetChangelog() ]); } + + public function BarcodeScannerTesting(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'barcodescannertesting'); + } } diff --git a/localization/strings.pot b/localization/strings.pot index b5d5d9e9..0312ff98 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1498,3 +1498,21 @@ msgstr "" msgid "Per stock quantity unit" msgstr "" + +msgid "Barcode scanner testing" +msgstr "" + +msgid "Expected barcode" +msgstr "" + +msgid "Scan field" +msgstr "" + +msgid "Scanned codes" +msgstr "" + +msgid "Hit" +msgstr "" + +msgid "Miss" +msgstr "" diff --git a/public/viewjs/barcodescannertesting.js b/public/viewjs/barcodescannertesting.js new file mode 100644 index 00000000..9f04f83c --- /dev/null +++ b/public/viewjs/barcodescannertesting.js @@ -0,0 +1,95 @@ +Grocy.BarCodeScannerTestingHitCount = 0; +Grocy.BarCodeScannerTestingMissCount = 0; + +$("#scanned_barcode").on("blur", function (e) +{ + OnBarcodeScanned($("#scanned_barcode").val()); +}); + +$("#scanned_barcode").keydown(function(event) +{ + if (event.keyCode === 13) //Enter + { + event.preventDefault(); + OnBarcodeScanned($("#scanned_barcode").val()); + } +}); + +$("#expected_barcode").on("keyup", function(e) +{ + if ($("#expected_barcode").val().length > 1) + { + $("#scanned_barcode").removeAttr("disabled"); + $("#barcodescanner-start-button").removeAttr("disabled"); + $("#barcodescanner-start-button").removeClass("disabled"); + } + else + { + $("#scanned_barcode").attr("disabled", ""); + $("#barcodescanner-start-button").attr("disabled", ""); + $("#barcodescanner-start-button").addClass("disabled"); + } +}); + +$("#expected_barcode").focus(); +setTimeout(function() +{ + $("#barcodescanner-start-button").attr("disabled", ""); + $("#barcodescanner-start-button").addClass("disabled"); +}, 200); + +if (GetUriParam("barcode") !== undefined) +{ + $("#expected_barcode").val(GetUriParam("barcode")); + setTimeout(function () + { + $("#expected_barcode").keyup(); + $("#scanned_barcode").focus(); + }, 200); +} + +function OnBarcodeScanned(barcode) +{ + if (barcode.length === 0) + { + return; + } + + var bgClass = ""; + if (barcode != $("#expected_barcode").val()) + { + Grocy.BarCodeScannerTestingMissCount++; + bgClass = "bg-danger"; + + $("#miss-count").fadeOut(200, function () + { + $(this).text(Grocy.BarCodeScannerTestingMissCount).fadeIn(200); + }); + } + else + { + Grocy.BarCodeScannerTestingHitCount++; + bgClass = "bg-success"; + + $("#hit-count").fadeOut(200, function () + { + $(this).text(Grocy.BarCodeScannerTestingHitCount).fadeIn(200); + }); + } + + $("#scanned_codes").prepend(""); + setTimeout(function() + { + $("#scanned_barcode").val(""); + + if (!$(":focus").is($("#expected_barcode"))) + { + $("#scanned_barcode").focus(); + } + }, 200); +} + +$(document).on("Grocy.BarcodeScanned", function(e, barcode) +{ + OnBarcodeScanned(barcode); +}); diff --git a/public/viewjs/components/barcodescanner.js b/public/viewjs/components/barcodescanner.js index afbb4645..c40596ab 100644 --- a/public/viewjs/components/barcodescanner.js +++ b/public/viewjs/components/barcodescanner.js @@ -150,5 +150,5 @@ $(document).on("click", "#barcodescanner-start-button", function(e) setTimeout(function() { - $(".barcodescanner-input:visible").after(''); + $(".barcodescanner-input:visible").after(''); }, 50); diff --git a/routes.php b/routes.php index 104430e0..c16dba1b 100644 --- a/routes.php +++ b/routes.php @@ -10,6 +10,7 @@ $app->group('', function() // System routes $this->get('/', '\Grocy\Controllers\SystemController:Root')->setName('root'); $this->get('/about', '\Grocy\Controllers\SystemController:About'); + $this->get('/barcodescannertesting', '\Grocy\Controllers\SystemController:BarcodeScannerTesting'); // Login routes $this->get('/login', 'LoginControllerInstance:LoginPage')->setName('login'); diff --git a/views/barcodescannertesting.blade.php b/views/barcodescannertesting.blade.php new file mode 100644 index 00000000..1725bea3 --- /dev/null +++ b/views/barcodescannertesting.blade.php @@ -0,0 +1,44 @@ +@extends('layout.default') + +@section('title', $__t('Barcode scanner testing')) + +@section('viewJsName', 'barcodescannertesting') + +@push('pageScripts') + +@endpush + +@section('content') +