🚧 Some progress with ClassQuizController
This commit is contained in:
Generated
+917
-840
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
let color_map = {
|
||||
r: 'red',
|
||||
g: 'green',
|
||||
y: 'yellow',
|
||||
b: 'blue'
|
||||
};
|
||||
export let code: string;
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-2 mx-auto">
|
||||
{#each code as c}
|
||||
<div class="flex flex-col">
|
||||
<p class="text-center">{c}</p>
|
||||
<span
|
||||
style="background-color: {color_map[
|
||||
c.toLowerCase()
|
||||
]}; width: 2rem; height: {c.toLowerCase() == c ? '2' : '4'}rem"
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -149,12 +149,7 @@
|
||||
/>
|
||||
</div>
|
||||
<div class="flex justify-center w-full my-auto">
|
||||
<label
|
||||
for="cqc-toggle"
|
||||
class="inline-flex relative items-center cursor-pointer"
|
||||
class:pointer-events-none={!captcha_enabled}
|
||||
class:opacity-50={!captcha_enabled}
|
||||
>
|
||||
<label for="cqc-toggle" class="inline-flex relative items-center cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={cqcs_enabled}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import AudioPlayer from '$lib/play/audio_player.svelte';
|
||||
import ControllerCodeDisplay from '$lib/components/controller/code.svelte';
|
||||
import { getLocalization } from '$lib/i18n';
|
||||
|
||||
export let game_pin: string;
|
||||
@@ -30,12 +31,6 @@
|
||||
}
|
||||
players = players;
|
||||
};
|
||||
const color_map = {
|
||||
r: 'red',
|
||||
g: 'green',
|
||||
y: 'yellow',
|
||||
b: 'blue'
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="w-full h-full">
|
||||
@@ -55,18 +50,7 @@
|
||||
<div class="m-auto">
|
||||
<div class="flex-col flex justify-center">
|
||||
<p class="mx-auto">Join by entering the following code</p>
|
||||
<div class="flex flex-row gap-2 mx-auto">
|
||||
{#each cqc_code as c}
|
||||
<div class="flex flex-col">
|
||||
<p class="text-center">{c}</p>
|
||||
<span
|
||||
style="background-color: {color_map[
|
||||
c.toLowerCase()
|
||||
]}; width: 2rem; height: {c.toLowerCase() == c ? '2' : '4'}rem"
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<ControllerCodeDisplay code={cqc_code} />
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import BrownButton from '$lib/components/buttons/brown.svelte';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
console.log(data.controllers);
|
||||
const controllers: [] = data.controllers;
|
||||
</script>
|
||||
|
||||
<div class="w-full h-full">
|
||||
{#if controllers.length === 0}
|
||||
<div class="w-full h-full flex">
|
||||
<div class="m-auto">
|
||||
<BrownButton>Add new controller</BrownButton>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="p-2">
|
||||
<table class="w-full">
|
||||
<tr class="border-b-2 dark:border-gray-500 text-left border-gray-300">
|
||||
<th class="border-r dark:border-gray-500 p-1 mx-auto border-gray-300">Name</th>
|
||||
<th class="border-r dark:border-gray-500 p-1 mx-auto border-gray-300"
|
||||
>Player name</th
|
||||
>
|
||||
<th class="border-r dark:border-gray-500 p-1 mx-auto border-gray-300"
|
||||
>First seen</th
|
||||
>
|
||||
<th class="border-r dark:border-gray-500 p-1 mx-auto border-gray-300"
|
||||
>Last seen</th
|
||||
>
|
||||
<th class="mx-auto p-1">Version</th>
|
||||
</tr>
|
||||
{#each data.controllers as controller}
|
||||
<tr class="text-left">
|
||||
<td class="border-r dark:border-gray-500 p-1 border-gray-300"
|
||||
><a
|
||||
href="/account/controllers/{controller.id}"
|
||||
class="underline text-lg">{controller.name}</a
|
||||
></td
|
||||
>
|
||||
<td class="border-r dark:border-gray-500 p-1 border-gray-300"
|
||||
>{controller.player_name}</td
|
||||
>
|
||||
<td class="border-r dark:border-gray-500 p-1 border-gray-300"
|
||||
>{controller.first_seen
|
||||
? new Date(controller.first_seen).toLocaleString()
|
||||
: 'Never'}</td
|
||||
>
|
||||
<td class="border-r dark:border-gray-500 p-1 border-gray-300"
|
||||
>{controller.last_seen
|
||||
? new Date(controller.last_seen).toLocaleString()
|
||||
: 'Never'}</td
|
||||
>
|
||||
<td class="mx-auto p-1">{controller.os_version ?? 'Unknown'}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load = (async ({ fetch }) => {
|
||||
const resp = await fetch('/api/v1/box-controller/web/list');
|
||||
// const resp = await fetch("https://localhost/api/v1/box-controller/web/list")
|
||||
const controllers = await resp.json();
|
||||
return {
|
||||
controllers
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
@@ -0,0 +1,133 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
export let data: PageData;
|
||||
let input_data = {
|
||||
player_name: data.username,
|
||||
name: ''
|
||||
};
|
||||
|
||||
let isValid = false;
|
||||
let isSubmitting = false;
|
||||
|
||||
$: isValid = input_data.name.length !== 0 && input_data.player_name.length !== 0;
|
||||
|
||||
const submit = async () => {
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
const res = await fetch('/api/v1/box-controller/web/setup', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(input_data)
|
||||
});
|
||||
if (res.ok) {
|
||||
const json = await res.json();
|
||||
goto(`/account/controllers/add/wait?id=${json.id}&code=${json.code}`);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class="flex items-center justify-center h-full px-4">
|
||||
<div>
|
||||
<div
|
||||
class="w-full max-w-sm mx-auto overflow-hidden bg-white rounded-lg shadow-md dark:bg-gray-800"
|
||||
>
|
||||
<div class="px-6 py-4">
|
||||
<h2 class="text-3xl font-bold text-center text-gray-700 dark:text-white">
|
||||
ClassQuiz
|
||||
</h2>
|
||||
|
||||
<h3 class="mt-1 text-xl font-medium text-center text-gray-600 dark:text-gray-200">
|
||||
Add a controller
|
||||
</h3>
|
||||
|
||||
<form on:submit|preventDefault={submit}>
|
||||
<div class="w-full mt-4">
|
||||
<div class="dark:bg-gray-800 bg-white p-4 rounded-lg">
|
||||
<div class="relative bg-inherit w-full">
|
||||
<input
|
||||
id="player_name"
|
||||
name="player_name"
|
||||
type="text"
|
||||
class="w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600"
|
||||
class:ring-red-700={input_data.player_name.length === 0}
|
||||
class:ring-green-600={input_data.player_name.length !== 0}
|
||||
bind:value={input_data.player_name}
|
||||
/>
|
||||
<label
|
||||
for="player_name"
|
||||
class="absolute cursor-text left-0 -top-3 text-sm text-gray-700 dark:text-white bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all"
|
||||
>
|
||||
Player name
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dark:bg-gray-800 bg-white p-4 rounded-lg">
|
||||
<div class="relative bg-inherit w-full">
|
||||
<input
|
||||
id="name"
|
||||
name="name"
|
||||
type="text"
|
||||
class="w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600"
|
||||
placeholder="Name"
|
||||
class:ring-red-700={input_data.name.length === 0}
|
||||
class:ring-green-600={input_data.name.length !== 0}
|
||||
bind:value={input_data.name}
|
||||
/>
|
||||
<label
|
||||
for="name"
|
||||
class="absolute cursor-text left-0 -top-3 text-sm text-gray-700 dark:text-white bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all"
|
||||
>
|
||||
Name
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-center mt-4">
|
||||
<button
|
||||
class="px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded hover:bg-gray-600 focus:outline-none"
|
||||
disabled={!isValid || isSubmitting}
|
||||
class:cursor-not-allowed={!isValid || isSubmitting}
|
||||
class:opacity-50={!isValid || isSubmitting}
|
||||
type="submit"
|
||||
>
|
||||
{#if isSubmitting}
|
||||
<svg class="h-4 w-4 animate-spin" viewBox="3 3 18 18">
|
||||
<path
|
||||
class="fill-blue-800"
|
||||
d="M12 5C8.13401 5 5 8.13401 5 12C5 15.866 8.13401 19 12 19C15.866 19 19 15.866 19 12C19 8.13401 15.866 5 12 5ZM3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12Z"
|
||||
/>
|
||||
<path
|
||||
class="fill-blue-100"
|
||||
d="M16.9497 7.05015C14.2161 4.31648 9.78392 4.31648 7.05025 7.05015C6.65973 7.44067 6.02656 7.44067 5.63604 7.05015C5.24551 6.65962 5.24551 6.02646 5.63604 5.63593C9.15076 2.12121 14.8492 2.12121 18.364 5.63593C18.7545 6.02646 18.7545 6.65962 18.364 7.05015C17.9734 7.44067 17.3403 7.44067 16.9497 7.05015Z"
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
Add
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="flex items-center justify-center py-4 text-center bg-gray-50 dark:bg-gray-700"
|
||||
>
|
||||
<span class="text-sm text-gray-600 dark:text-gray-200"
|
||||
>Don't know what this is?
|
||||
</span>
|
||||
|
||||
<a
|
||||
href="/account/login"
|
||||
class="mx-2 text-sm font-bold text-blue-500 dark:text-blue-400 hover:underline"
|
||||
>Read more here.</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import type { PageLoad } from './$types';
|
||||
|
||||
export const load = (async ({ fetch }) => {
|
||||
const resp = await fetch('/api/v1/users/me');
|
||||
const json = await resp.json();
|
||||
return {
|
||||
username: json.username
|
||||
};
|
||||
}) satisfies PageLoad;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load = (async ({ url }) => {
|
||||
const code = url.searchParams.get('code');
|
||||
const id = url.searchParams.get('id');
|
||||
if (!id || !code) {
|
||||
throw error(404, JSON.stringify({ detail: 'id and/or code are/is missing' }));
|
||||
}
|
||||
return {
|
||||
id,
|
||||
code
|
||||
};
|
||||
}) satisfies PageServerLoad;
|
||||
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import CodeDisplay from '$lib/components/controller/code.svelte';
|
||||
import Spinner from '$lib/Spinner.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
export let data: PageData;
|
||||
let controller_seen = false;
|
||||
let check_tick = 0;
|
||||
let interval;
|
||||
|
||||
const check_if_controller_was_seen = async () => {
|
||||
const res = await fetch(`/api/v1/box-controller/web/controller?id=${data.id}`);
|
||||
const json = await res.json();
|
||||
controller_seen = Boolean(json.first_seen);
|
||||
if (controller_seen) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
await check_if_controller_was_seen();
|
||||
interval = setInterval(async () => {
|
||||
check_tick += 1;
|
||||
if (check_tick === 5) {
|
||||
await check_if_controller_was_seen();
|
||||
check_tick = 0;
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="w-full h-full flex">
|
||||
<div class="m-auto flex flex-col">
|
||||
<div class="block">
|
||||
<CodeDisplay code={data.code} />
|
||||
</div>
|
||||
{#if controller_seen}
|
||||
<div class="mt-10">
|
||||
<p class="text-center">Controller set up successfully!</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="mt-10 flex-col flex gap-2 justify-center">
|
||||
<p>Checking if controller has been connected in {5 - check_tick} seconds.</p>
|
||||
<Spinner my_20={false} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user