mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Allow to directly specify the scanned string via an input query parameter
This commit is contained in:
parent
4f82a0f026
commit
49ae906029
3 changed files with 54 additions and 3 deletions
|
@ -49,6 +49,7 @@ use InvalidArgumentException;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
#[Route(path: '/scan')]
|
#[Route(path: '/scan')]
|
||||||
|
@ -59,16 +60,18 @@ class ScanController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: '/', name: 'scan_dialog')]
|
#[Route(path: '/', name: 'scan_dialog')]
|
||||||
public function dialog(Request $request): Response
|
public function dialog(Request $request, #[MapQueryParameter] ?string $input = null): Response
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('@tools.label_scanner');
|
$this->denyAccessUnlessGranted('@tools.label_scanner');
|
||||||
|
|
||||||
$form = $this->createForm(ScanDialogType::class);
|
$form = $this->createForm(ScanDialogType::class);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($input === null && $form->isSubmitted() && $form->isValid()) {
|
||||||
$input = $form['input']->getData();
|
$input = $form['input']->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($input !== null) {
|
||||||
try {
|
try {
|
||||||
[$type, $id] = $this->barcodeNormalizer->normalizeBarcodeContent($input);
|
[$type, $id] = $this->barcodeNormalizer->normalizeBarcodeContent($input);
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,6 @@ class ApplicationAvailabilityFunctionalTest extends WebTestCase
|
||||||
|
|
||||||
//Scan test
|
//Scan test
|
||||||
yield ['/scan']; //Interactive scan dialog
|
yield ['/scan']; //Interactive scan dialog
|
||||||
yield ['/scan/part/1']; //Scan a part
|
|
||||||
|
|
||||||
//Tools
|
//Tools
|
||||||
yield ['/tools/reel_calc'];
|
yield ['/tools/reel_calc'];
|
||||||
|
|
49
tests/Controller/ScanControllerTest.php
Normal file
49
tests/Controller/ScanControllerTest.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Tests\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
class ScanControllerTest extends WebTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
private ?KernelBrowser $client = null;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->client = static::createClient();
|
||||||
|
$this->client->disableReboot();
|
||||||
|
$this->client->catchExceptions(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRedirectOnInputParameter(): void
|
||||||
|
{
|
||||||
|
$this->client->request('GET', '/en/scan/?input=0000001');
|
||||||
|
$this->assertResponseRedirects('/en/part/1');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanQRCode(): void
|
||||||
|
{
|
||||||
|
$this->client->request('GET', '/scan/part/1');
|
||||||
|
$this->assertResponseRedirects('/en/part/1');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue