+ import { RunnerCardService, RunnerService } from "@odit/lfk-client-js";
import QrCodeScanner from "./QrCodeScanner.svelte";
let state = "scan_runner";
- let runnerID = undefined;
- let cardInfo = "";
+ let runnerinfo = { id: 0, firstname: "", lastname: "" };
+ let cardCode = "";
+ $: scannerActive = state.includes("scan");
Card Assignment for Mobile
- {#if state === "done"}
-
Assigned Card {cardInfo} ✅
-
(not really, needs to be implemented)
- {:else}
+
+ {#if state.includes("scan_")}
{#if state === "scan_runner"}
Scan Runner (Selfservice QR)
{/if}
{#if state === "scan_card"}
Runner Scanned
-
{runnerID}
+
{runnerinfo.firstname} {runnerinfo.lastname} [#{runnerinfo.id}]
Scan Card (Code 128 Barcode)
{/if}
{
console.log({ type: "DETECT", code: e.detail.decodedText });
if (state === "scan_runner") {
@@ -29,13 +33,18 @@
"https://portal.lauf-fuer-kaya.de/profile/"
)
) {
- runnerID = JSON.parse(
+ const runnerID = JSON.parse(
atob(
e.detail.decodedText
.replace("https://portal.lauf-fuer-kaya.de/profile/", "")
.split(".")[1]
)
).id;
+ new Audio("/beep.mp3").play();
+ RunnerService.runnerControllerGetOne(runnerID).then((runner) => {
+ console.log(runner);
+ runnerinfo = runner;
+ });
state = "scan_card";
}
}
@@ -45,8 +54,25 @@
"https://portal.lauf-fuer-kaya.de/profile/"
)
) {
- cardInfo = e.detail.decodedText;
- state = "done";
+ cardCode = e.detail.decodedText;
+ new Audio("/beep.mp3").play();
+ state = "assigning";
+ RunnerCardService.runnerCardControllerGetAll().then((cards) => {
+ console.log(cards);
+ const card = cards.find((c) => c.code === cardCode);
+ if (card) {
+ console.log("card found", card);
+ RunnerCardService.runnerCardControllerPut(card.id, {
+ enabled: true,
+ id: card.id,
+ runner: runnerinfo.id,
+ }).then(() => {
+ state = "done";
+ });
+ } else {
+ state = "error_card_404";
+ }
+ });
}
}
}}
@@ -58,8 +84,8 @@
{/if}
+ {:else}
+
+ {#if state === "assigning"}
+ Assigning Card {cardCode} ⌛
+ Please wait a moment while we assign the card...
+ {/if}
+ {#if state === "done"}
+
+ Assigned Card {cardCode} to {runnerinfo.firstname}
+ {runnerinfo.lastname} [#{runnerinfo.id}] ✅
+
+
+ {/if}
+
{/if}
diff --git a/src/components/general/QrCodeScanner.svelte b/src/components/general/QrCodeScanner.svelte
index a0ca28e9..0bdc726b 100644
--- a/src/components/general/QrCodeScanner.svelte
+++ b/src/components/general/QrCodeScanner.svelte
@@ -14,12 +14,16 @@
const dispatch = createEventDispatcher();
function onScanSuccess(decodedText, decodedResult) {
- dispatch("detect", { decodedText });
+ if (!paused) {
+ dispatch("detect", { decodedText });
+ }
}
// usually better to ignore and keep scanning
function onScanFailure(message) {
- dispatch("error", { message });
+ if (!paused) {
+ dispatch("error", { message });
+ }
}
let scanner;