Card Assignment for Mobile
{#if state === "done"}
✅ Done
Assigned Card {cardCode} to {runnerinfo.firstname}
{runnerinfo.lastname} [#{runnerinfo.id}]
{:else if state === "assigning"}
Assigning Card {cardCode} ⌛
Please wait a moment while we assign the card...
{:else if state === "error_runner"}
Runner not found...
{:else if state === "error_card"}
Card not found...
{:else}
{#if runnerinfo.id === 0}
Scan Runner
Selfservice QR/ Registration Barcode
{:else}
{runnerinfo.firstname}
{runnerinfo.lastname}
ID: #{runnerinfo.id}
created_via: {runnerinfo.created_via}
{runnerinfo.group.name}
{/if}
{/if}
{#if state === "scan_card"}
Scan Card
Code 128 Barcode
{/if}
{#if state.includes("scan_")}
{#if scannerActive}
{
if (scannerActive) {
scannerActive = false;
console.log({ type: "DETECT", code: e.detail.decodedText });
if (runnerinfo.id === 0) {
new Audio("/beep.mp3").play();
if (
e.detail.decodedText.includes(
"https://portal.lauf-fuer-kaya.de/profile/"
)
) {
const runnerID = JSON.parse(
atob(
e.detail.decodedText
.replace("https://portal.lauf-fuer-kaya.de/profile/", "")
.split(".")[1]
)
).id;
RunnerService.runnerControllerGetOne(runnerID)
.then((runner) => {
runnerinfo = runner;
})
.catch((e) => {
console.error(e);
state = "error_runner";
// resetAll();
});
} else {
const runnerID = parseInt(e.detail.decodedText);
RunnerService.runnerControllerGetOne(runnerID)
.then((runner) => {
runnerinfo = runner;
})
.catch((e) => {
console.error(e);
state = "error_runner";
// resetAll();
});
}
} else {
if (`${e.detail.decodedText}`.length > 10) {
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";
})
.catch(() => {
state = "error_card";
scannerActive = false;
});
} else {
scannerActive = true;
}
})
.catch(() => {
scannerActive = true;
});
}
}
}
}}
width={320}
height={320}
class="w-full max-w-sm bg-neutral-300 rounded-lg overflow-hidden"
/>
{/if}
{#if runnerinfo.id !== 0 && state !== "scan_card"}
{/if}
{#if state === "scan_card" || runnerinfo.id !== 0}
{/if}
{/if}