diff --git a/public/scanner/sw.js b/public/scanner/sw.js new file mode 100644 index 0000000..597e346 --- /dev/null +++ b/public/scanner/sw.js @@ -0,0 +1,27 @@ +const CACHE_NAME = 'scanner-v1'; +const ASSETS = [ + '/scanner', + 'https://unpkg.com/html5-qrcode@2.3.8/html5-qrcode.min.js', +]; + +self.addEventListener('install', (e) => { + e.waitUntil(caches.open(CACHE_NAME).then(c => c.addAll(ASSETS))); + self.skipWaiting(); +}); + +self.addEventListener('activate', (e) => { + e.waitUntil( + caches.keys().then(keys => Promise.all( + keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)) + )) + ); + self.clients.claim(); +}); + +self.addEventListener('fetch', (e) => { + if (e.request.method !== 'GET') return; + if (e.request.url.includes('/api/')) return; + e.respondWith( + caches.match(e.request).then(cached => cached || fetch(e.request)) + ); +}); diff --git a/src/Controller/ScannerController.php b/src/Controller/ScannerController.php new file mode 100644 index 0000000..f6819c9 --- /dev/null +++ b/src/Controller/ScannerController.php @@ -0,0 +1,42 @@ +render('scanner/index.html.twig'); + } + + #[Route('/scanner/manifest.json', name: 'app_scanner_manifest', methods: ['GET'])] + public function manifest(): Response + { + $manifest = [ + 'name' => 'E-Ticket Scanner', + 'short_name' => 'Scanner', + 'description' => 'Application de scan de billets pour organisateurs', + 'start_url' => '/scanner', + 'scope' => '/scanner', + 'display' => 'standalone', + 'orientation' => 'portrait', + 'theme_color' => '#111827', + 'background_color' => '#111827', + 'lang' => 'fr', + 'icons' => [ + ['src' => '/logo.png', 'sizes' => '512x512', 'type' => 'image/png'], + ], + ]; + + return new Response( + json_encode($manifest, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), + 200, + ['Content-Type' => 'application/manifest+json'], + ); + } +} diff --git a/templates/scanner/index.html.twig b/templates/scanner/index.html.twig new file mode 100644 index 0000000..87c504d --- /dev/null +++ b/templates/scanner/index.html.twig @@ -0,0 +1,400 @@ + + + + + + E-Ticket Scanner + + + + + + + + + + + + +
+
+

E-Ticket Scanner

+
+
+ +

Connectez-vous avec votre compte organisateur

+
+
+
+ + +
+
+ + +
+ +
+
+
+ + +
+
+

Evenements

+ +
+
+
+ +
+
+
+ + +
+
+

Scanner

+ +
+
+ +
+
+
+ Scans effectues : 0 +
+
+
+ + + + diff --git a/tests/Controller/ScannerControllerTest.php b/tests/Controller/ScannerControllerTest.php new file mode 100644 index 0000000..330697f --- /dev/null +++ b/tests/Controller/ScannerControllerTest.php @@ -0,0 +1,40 @@ +request('GET', '/scanner'); + + self::assertResponseIsSuccessful(); + self::assertSelectorTextContains('title', 'E-Ticket Scanner'); + } + + public function testScannerManifestReturnsJson(): void + { + $client = static::createClient(); + $client->request('GET', '/scanner/manifest.json'); + + self::assertResponseIsSuccessful(); + self::assertResponseHeaderSame('Content-Type', 'application/manifest+json'); + + $data = json_decode($client->getResponse()->getContent(), true); + self::assertSame('E-Ticket Scanner', $data['name']); + self::assertSame('standalone', $data['display']); + self::assertSame('/scanner', $data['start_url']); + } + + public function testScannerPageIsAccessibleWithoutAuth(): void + { + $client = static::createClient(); + $client->request('GET', '/scanner'); + + self::assertResponseIsSuccessful(); + self::assertResponseStatusCodeSame(200); + } +}