=stop timer
=displayV
This commit is contained in:
parent
5829f22163
commit
b5195ed4a3
13 changed files with 126 additions and 37 deletions
|
@ -14,9 +14,11 @@ func (w *Webapp) initApi() {
|
|||
http_api.GET("/sse", HeadersMiddleware(), stream.serveHTTP(), stream.retvalSSE())
|
||||
|
||||
http_api.POST("/startheat", w.StartHeatTimer)
|
||||
http_api.GET("/stopheat", w.StopHeatTimer)
|
||||
http_api.POST("/saveheat", w.SaveHeat)
|
||||
http_api.POST("/deleteheat", w.DeleteHeat)
|
||||
http_api.GET("/loadheats", w.LoadHeats)
|
||||
http_api.GET("/runningheat", w.LoadRunning)
|
||||
|
||||
// // Surfers
|
||||
// http_api.GET("/surfers", w.GetSurfers)
|
||||
|
|
BIN
backend/backend
BIN
backend/backend
Binary file not shown.
|
@ -7,12 +7,15 @@ import (
|
|||
scribble "github.com/nanobox-io/golang-scribble"
|
||||
)
|
||||
|
||||
func InitDb(dbAddress string) *scribble.Driver {
|
||||
type DB struct {
|
||||
Db *scribble.Driver
|
||||
}
|
||||
|
||||
func InitDb(dbAddress string) *DB {
|
||||
var err error
|
||||
var db *scribble.Driver
|
||||
var db *DB
|
||||
|
||||
db, err = scribble.New("", nil)
|
||||
db.Db, err = scribble.New("", nil)
|
||||
if err != nil {
|
||||
fmt.Println("Error", err)
|
||||
}
|
||||
|
@ -21,3 +24,21 @@ func InitDb(dbAddress string) *scribble.Driver {
|
|||
|
||||
return db
|
||||
}
|
||||
|
||||
func (db *DB) Write(table string, key string, value interface{}) error {
|
||||
err := db.Db.Write(table, key, value)
|
||||
if err != nil {
|
||||
fmt.Println("Error", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) Read(table string, key string, value interface{}) error {
|
||||
err := db.Db.Read(table, key, value)
|
||||
if err != nil {
|
||||
fmt.Println("Error", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -88,6 +88,8 @@ func (w *Webapp) LoadRunning(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusNoContent, "")
|
||||
}
|
||||
|
||||
func (w *Webapp) LoadHeats(c *gin.Context) {
|
||||
|
@ -130,6 +132,20 @@ func (w *Webapp) StartHeatTimer(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, w.Stream.Duration)
|
||||
}
|
||||
|
||||
func (w *Webapp) StopHeatTimer(c *gin.Context) {
|
||||
if !w.Stream.Start {
|
||||
c.JSON(http.StatusOK, w.Stream.Duration)
|
||||
return
|
||||
}
|
||||
|
||||
stopHeat(w.DB, *w.Stream.Heat)
|
||||
w.Stream.Start = false
|
||||
w.Stream.Duration = 0
|
||||
|
||||
log.Printf("start timer %s", w.Stream.Duration)
|
||||
c.JSON(http.StatusOK, w.Stream.Duration)
|
||||
}
|
||||
|
||||
func loadHeats(db *scribble.Driver) []Heat {
|
||||
records, err := db.ReadAll("Heat")
|
||||
if err != nil {
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":"1702569208144"}
|
||||
{"version":"1702630864271"}
|
Binary file not shown.
Binary file not shown.
|
@ -5,17 +5,17 @@
|
|||
<link rel="icon" href="/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<link rel="modulepreload" href="/_app/immutable/entry/start.13280560.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/entry/start.fa0c32bd.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/chunks/scheduler.d1a939e8.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/chunks/singletons.500d5dae.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/entry/app.cb972752.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/chunks/singletons.8b54c836.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/entry/app.a9ea6d0c.js">
|
||||
<link rel="modulepreload" href="/_app/immutable/chunks/index.994dd985.js">
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">
|
||||
<script>
|
||||
{
|
||||
__sveltekit_i2508g = {
|
||||
__sveltekit_1u6fqm2 = {
|
||||
base: "",
|
||||
env: {}
|
||||
};
|
||||
|
@ -23,8 +23,8 @@
|
|||
const element = document.currentScript.parentElement;
|
||||
|
||||
Promise.all([
|
||||
import("/_app/immutable/entry/start.13280560.js"),
|
||||
import("/_app/immutable/entry/app.cb972752.js")
|
||||
import("/_app/immutable/entry/start.fa0c32bd.js"),
|
||||
import("/_app/immutable/entry/app.a9ea6d0c.js")
|
||||
]).then(([kit, app]) => {
|
||||
kit.start(app, element);
|
||||
});
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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
Reference in a new issue