=stop timer
=displayV
This commit is contained in:
parent
5829f22163
commit
b5195ed4a3
13 changed files with 126 additions and 37 deletions
|
@ -9,43 +9,58 @@
|
|||
console.log('Not dev mode');
|
||||
}
|
||||
|
||||
|
||||
|
||||
let surfers = [
|
||||
{ name: 'Kanoa Igarashi', color: 'red', score: '4.50', priority: '3' },
|
||||
{ name: 'Griffin Colapinto', color: 'white', score: '5.60', priority: 'P' },
|
||||
{ name: 'Jack Robinson', color: 'blue', score: '6.10', priority: '5' },
|
||||
{ name: 'Gabriel Medina', color: 'green', score: '4.30', priority: '2' },
|
||||
{ name: 'Italo Ferreira', color: 'black', score: '6.50', priority: '4' }
|
||||
// { name: 'Kanoa Igarashi', color: 'red', score: '4.50', priority: '3' },
|
||||
// { name: 'Griffin Colapinto', color: 'white', score: '5.60', priority: 'P' },
|
||||
// { name: 'Jack Robinson', color: 'blue', score: '6.10', priority: '5' },
|
||||
// { name: 'Gabriel Medina', color: 'green', score: '4.30', priority: '2' },
|
||||
// { name: 'Italo Ferreira', color: 'black', score: '6.50', priority: '4' }
|
||||
];
|
||||
|
||||
let width;
|
||||
// $: activeUrl = $page.url.pathname;
|
||||
|
||||
let event = 'Semifinal';
|
||||
let category = 'U16 man';
|
||||
let heat = 'Heat 1';
|
||||
let heat = {};
|
||||
|
||||
const pad2 = (number) => `00${number}`.slice(-2);
|
||||
|
||||
$: min = 10;
|
||||
$: sec = 25;
|
||||
$: min = 0;
|
||||
$: sec = 0;
|
||||
|
||||
let end = false;
|
||||
|
||||
function updateRemainingTime() {
|
||||
if ((min === 0) & (sec === 0)) {
|
||||
clearInterval(timer);
|
||||
end = true;
|
||||
} else if (sec === 0) {
|
||||
min -= 1;
|
||||
sec = 59;
|
||||
} else {
|
||||
sec -= 1;
|
||||
loadRunning();
|
||||
|
||||
async function loadRunning() {
|
||||
const res = await fetch(`/api/runningheat`);
|
||||
const data = await res.json();
|
||||
heat = data;
|
||||
console.log(`retval: ${JSON.stringify(heat)}`);
|
||||
|
||||
if (heat != null) {
|
||||
console.log(`heat: ${JSON.stringify(heat)}`);
|
||||
min = heat.timer;
|
||||
surfers = heat.surfers;
|
||||
}
|
||||
}
|
||||
|
||||
updateRemainingTime();
|
||||
// function updateRemainingTime() {
|
||||
// if ((min === 0) & (sec === 0)) {
|
||||
// clearInterval(timer);
|
||||
// end = true;
|
||||
// } else if (sec === 0) {
|
||||
// min -= 1;
|
||||
// sec = 59;
|
||||
// } else {
|
||||
// sec -= 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
const timer = setInterval(updateRemainingTime, 1000);
|
||||
// updateRemainingTime();
|
||||
|
||||
// const timer = setInterval(updateRemainingTime, 1000);
|
||||
|
||||
function Subscribe() {
|
||||
const sse = new EventSource(`/api/sse`);
|
||||
|
@ -58,7 +73,20 @@
|
|||
for (let i in surfers) {
|
||||
surfers[i].priority = Msg.priority[i];
|
||||
}
|
||||
}
|
||||
} else if (Msg.mode === 'time') {
|
||||
// console.log(`duration: ${Msg.duration}`);
|
||||
let min_sec = Msg.duration.split(":");
|
||||
min = min_sec[0];
|
||||
sec = min_sec[1];
|
||||
// console.log(`min & sec = ${min} & ${sec}`);
|
||||
if (!start) {
|
||||
start = true;
|
||||
}
|
||||
} else if (Msg.mode === 'stop') {
|
||||
console.log(`stop duration: ${Msg.duration}`);
|
||||
end = true;
|
||||
start = false;
|
||||
}
|
||||
};
|
||||
return () => {
|
||||
sse.close();
|
||||
|
@ -66,6 +94,7 @@
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
onMount(() => {
|
||||
if (!dev) {
|
||||
const unsub = Subscribe();
|
||||
|
|
|
@ -71,10 +71,13 @@
|
|||
} else {
|
||||
console.log(`pressed: [${id}] ${surfers[id].priority}`);
|
||||
}
|
||||
const res = await fetch(`/api/stopheat`);
|
||||
const data = await res.json();
|
||||
console.log(`stop: ${JSON.stringify(data)}`);
|
||||
}
|
||||
|
||||
async function startHeat() {
|
||||
const res = await fetch(`/api/start`, {
|
||||
const res = await fetch(`/api/startheat`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
duration: min+"m",
|
||||
|
|
|
@ -2,6 +2,16 @@
|
|||
import { onMount } from 'svelte';
|
||||
import Logo from "$lib/img/topscorer_logo_web.png"
|
||||
|
||||
let colors = [
|
||||
"black",
|
||||
"blue",
|
||||
"red",
|
||||
"green",
|
||||
"yellow",
|
||||
"pink",
|
||||
"white",
|
||||
];
|
||||
|
||||
let rounds = [
|
||||
"Qualifying",
|
||||
"Opening",
|
||||
|
@ -220,8 +230,9 @@
|
|||
<hr>
|
||||
|
||||
<button class="plus" on:click={() => {addSurfers();}}>+</button>
|
||||
<button class="plus" on:click={() => {removeSurfers();}}>-</button>
|
||||
<span class="surfers">{surfers}</span>
|
||||
<button class="plus" on:click={() => {removeSurfers();}}>-</button>
|
||||
|
||||
|
||||
{#each Array(surfers) as _, surfer}
|
||||
<div class="surfer">
|
||||
|
@ -229,13 +240,16 @@
|
|||
<input bind:value={surfer_list[surfer].name} on:change={capitalize(surfer_list[surfer], "name")} id="name{surfer}" type="text">
|
||||
<label class="label" for="color{surfer}">Color</label>
|
||||
<select name="color" id="color{surfer}" bind:value={surfer_list[surfer].color} style="background-color: {surfer_list[surfer].color};">
|
||||
{#each colors as color}
|
||||
<option value={color} style="background-color: {color};">{color}</option>
|
||||
{/each}
|
||||
<!-- <option value="red" style="background-color: red;">Select color</option> -->
|
||||
<option value="red" style="background-color: red;">Red</option>
|
||||
<!-- <option value="red" style="background-color: red;">Red</option>
|
||||
<option value="blue" style="background-color: blue;">Blue</option>
|
||||
<option value="green" style="background-color: green;">Green</option>
|
||||
<option value="yellow" style="background-color: yellow;">Yellow</option>
|
||||
<option value="orange" style="background-color: orange;">Orange</option>
|
||||
<option value="violet" style="background-color: violet;">Violet</option>
|
||||
<option value="violet" style="background-color: violet;">Violet</option> -->
|
||||
</select>
|
||||
<!-- <input bind:value={surfer_list[surfer].color} type="color" id="color{surfer}"> -->
|
||||
</div>
|
||||
|
@ -243,7 +257,7 @@
|
|||
|
||||
</div>
|
||||
|
||||
<button class="plus" on:click={() => {save();}}>SET</button>
|
||||
<button class="plus" on:click={() => {save();}}>SAVE</button>
|
||||
<button class="plus" on:click={() => {resetHeat();}}>RESET</button>
|
||||
<hr>
|
||||
{#each heats as h, id}
|
||||
|
@ -340,6 +354,10 @@
|
|||
|
||||
}
|
||||
|
||||
.surfer select {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.plus {
|
||||
border-radius: 8px;
|
||||
margin-left: 0.2rem;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue