=priority: load heats

This commit is contained in:
Miki 2023-12-13 15:30:13 +01:00
parent 95d3b8ae4a
commit 50a1d74e65
10 changed files with 75 additions and 18 deletions

View file

@ -8,6 +8,7 @@ func (w *Webapp) initApi() {
http_api := w.Engine.Group("/api") http_api := w.Engine.Group("/api")
http_api.GET("/priority", w.GetPriority) http_api.GET("/priority", w.GetPriority)
http_api.GET("/load", w.LoadHeats)
http_api.POST("/priority", w.SetPriority) http_api.POST("/priority", w.SetPriority)
http_api.POST("/start", w.StartTimer) http_api.POST("/start", w.StartTimer)

Binary file not shown.

View file

@ -1,6 +1,8 @@
package main package main
import ( import (
"encoding/json"
"fmt"
"log" "log"
"net/http" "net/http"
"time" "time"
@ -35,6 +37,27 @@ func (w *Webapp) StartTimer(c *gin.Context) {
c.JSON(http.StatusOK, w.Stream.Duration) c.JSON(http.StatusOK, w.Stream.Duration)
} }
func (w *Webapp) LoadHeats(c *gin.Context) {
records, err := w.DB.ReadAll("Heat")
if err != nil {
fmt.Printf("read error: %+v", err)
}
heats := make([]Heat, 0)
for _, record := range records {
var heat Heat
err = json.Unmarshal([]byte(record), &heat)
if err != nil {
fmt.Printf("decode error: %+v", err)
}
heats = append(heats, heat)
}
c.JSON(http.StatusOK, heats)
log.Printf("heats: %+v", heats)
}
func (w *Webapp) GetPriority(c *gin.Context) { func (w *Webapp) GetPriority(c *gin.Context) {
log.Printf("send priority %s", w.Stream.StatusPriority) log.Printf("send priority %s", w.Stream.StatusPriority)

View file

@ -1 +1 @@
{"version":"1702469015168"} {"version":"1702477632110"}

Binary file not shown.

Binary file not shown.

View file

@ -5,17 +5,17 @@
<link rel="icon" href="/favicon.png" /> <link rel="icon" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="modulepreload" href="/_app/immutable/entry/start.8c98c732.js"> <link rel="modulepreload" href="/_app/immutable/entry/start.f2f23bb5.js">
<link rel="modulepreload" href="/_app/immutable/chunks/scheduler.d1a939e8.js"> <link rel="modulepreload" href="/_app/immutable/chunks/scheduler.d1a939e8.js">
<link rel="modulepreload" href="/_app/immutable/chunks/singletons.505cc11c.js"> <link rel="modulepreload" href="/_app/immutable/chunks/singletons.f3cb4e26.js">
<link rel="modulepreload" href="/_app/immutable/entry/app.fd492588.js"> <link rel="modulepreload" href="/_app/immutable/entry/app.c3a1467b.js">
<link rel="modulepreload" href="/_app/immutable/chunks/index.c2132433.js"> <link rel="modulepreload" href="/_app/immutable/chunks/index.994dd985.js">
</head> </head>
<body data-sveltekit-preload-data="hover"> <body data-sveltekit-preload-data="hover">
<div style="display: contents"> <div style="display: contents">
<script> <script>
{ {
__sveltekit_r51frl = { __sveltekit_1cx8eia = {
base: "", base: "",
env: {} env: {}
}; };
@ -23,8 +23,8 @@
const element = document.currentScript.parentElement; const element = document.currentScript.parentElement;
Promise.all([ Promise.all([
import("/_app/immutable/entry/start.8c98c732.js"), import("/_app/immutable/entry/start.f2f23bb5.js"),
import("/_app/immutable/entry/app.fd492588.js") import("/_app/immutable/entry/app.c3a1467b.js")
]).then(([kit, app]) => { ]).then(([kit, app]) => {
kit.start(app, element); kit.start(app, element);
}); });

Binary file not shown.

Binary file not shown.

View file

@ -9,13 +9,15 @@
console.log('Not dev mode'); console.log('Not dev mode');
} }
let surfers = [ let heat_number;
{ name: 'Kanoa Igarashi', color: 'red', score: '4.50', priority: '3' }, let heats = [];
{ name: 'Griffin Colapinto', color: 'white', score: '5.60', priority: 'P' }, $: surfers = [];
{ name: 'Jack Robinson', color: 'blue', score: '6.10', priority: '5' }, // { name: 'Kanoa Igarashi', color: 'red', score: '4.50', priority: '3' },
{ name: 'Gabriel Medina', color: 'green', score: '4.30', priority: '2' }, // { name: 'Griffin Colapinto', color: 'white', score: '5.60', priority: 'P' },
{ name: 'Italo Ferreira', color: 'black', score: '6.50', priority: '4' } // { 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; let width;
// $: activeUrl = $page.url.pathname; // $: activeUrl = $page.url.pathname;
@ -40,8 +42,14 @@
surfers[i].priority = Msg.priority[i]; surfers[i].priority = Msg.priority[i];
} }
} else if (Msg.mode === 'time') { } else if (Msg.mode === 'time') {
console.log(`duration: ${Msg.duration}`); // console.log(`duration: ${Msg.duration}`);
min, sec = Msg.duration.split(":"); 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') { } else if (Msg.mode === 'stop') {
console.log(`stop duration: ${Msg.duration}`); console.log(`stop duration: ${Msg.duration}`);
end = true; end = true;
@ -67,7 +75,7 @@
const res = await fetch(`/api/start`, { const res = await fetch(`/api/start`, {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
duration: "0m10s", duration: min+"m",
mode: 'time' mode: 'time'
}), }),
headers: { headers: {
@ -79,6 +87,24 @@
end = false; end = false;
} }
async function loadHeats() {
const res = await fetch(`/api/load`);
const data = await res.json();
for (let i in data) {
heats[i] = data[i];
console.log(`${i} retval: ${JSON.stringify(data[i])}`);
}
}
function setHeat(id) {
console.log(`setHeat: ${id}`);
if (id === 99) {
return;
}
min = heats[id].timer;
surfers = heats[id].surfers;
}
async function click(id) { async function click(id) {
console.log(surfers[id]); console.log(surfers[id]);
if (surfers[id].priority === 'P') { if (surfers[id].priority === 'P') {
@ -144,6 +170,13 @@
<svelte:window bind:innerWidth={width} /> <svelte:window bind:innerWidth={width} />
<div class="header"> <div class="header">
<button class="button" on:click={() => loadHeats()} disabled={start}>Load</button>
<select name="heats" id="heats" bind:value={heat_number} on:change={() => setHeat(heat_number)}>
<option value=99>Select</option>
{#each heats as heat, id}
<option value={id}>{heat.name} {heat.category} {heat.number}</option>
{/each}
</select>
{#if !end} {#if !end}
<div class="timer">{pad2(min)}:{pad2(sec)}</div> <div class="timer">{pad2(min)}:{pad2(sec)}</div>
{:else} {:else}