This commit is contained in:
Miki 2023-12-06 11:00:38 +01:00
parent 555e7b85ea
commit 34ecc9f036
17 changed files with 70 additions and 57 deletions

View file

@ -14,6 +14,8 @@ func (w *Webapp) initApi() {
// SSE
http_api.GET("/sse", HeadersMiddleware(), stream.serveHTTP(), stream.retvalSSE())
http_api.POST("/setup", w.SetupHeat)
// // Surfers
// http_api.GET("/surfers", w.GetSurfers)
// http_api.POST("/updatesurfer", w.UpdateSurfer)

Binary file not shown.

37
backend/setup.go Normal file
View file

@ -0,0 +1,37 @@
package main
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
type Surfer struct {
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Color string `json:"color"`
}
type Heat struct {
Name string `json:"name"`
Category string `json:"category"`
Number string `json:"number"`
Surfers []Surfer `json:"surfers"`
}
func (w *Webapp) SetupHeat(c *gin.Context) {
var heat Heat
err := c.ShouldBind(&heat)
if err != nil {
log.Printf("req error: %+v", err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
log.Printf("heat: %+v", heat)
c.JSON(http.StatusOK, gin.H{"status": "added"})
}

View file

@ -193,8 +193,8 @@ func (stream *PriorityStream) timer() {
// Send current time to clients message channel
stream.Message <- msg
time.Sleep(time.Second * 1)
stream.Duration = stream.Duration - time.Second
time.Sleep(time.Second * 1)
} else {
timer.Stop()
}

View file

@ -1 +1 @@
{"version":"1701790559207"}
{"version":"1701850898620"}

Binary file not shown.

Binary file not shown.

View file

@ -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.f64c2857.js">
<link rel="modulepreload" href="/_app/immutable/entry/start.c0ca3cdb.js">
<link rel="modulepreload" href="/_app/immutable/chunks/scheduler.9172086d.js">
<link rel="modulepreload" href="/_app/immutable/chunks/singletons.2ba34c86.js">
<link rel="modulepreload" href="/_app/immutable/entry/app.f55ac43b.js">
<link rel="modulepreload" href="/_app/immutable/chunks/singletons.ff897aac.js">
<link rel="modulepreload" href="/_app/immutable/entry/app.5c5fafd1.js">
<link rel="modulepreload" href="/_app/immutable/chunks/index.c679962e.js">
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">
<script>
{
__sveltekit_uz78hc = {
__sveltekit_1gp1asy = {
base: "",
env: {}
};
@ -23,8 +23,8 @@
const element = document.currentScript.parentElement;
Promise.all([
import("/_app/immutable/entry/start.f64c2857.js"),
import("/_app/immutable/entry/app.f55ac43b.js")
import("/_app/immutable/entry/start.c0ca3cdb.js"),
import("/_app/immutable/entry/app.5c5fafd1.js")
]).then(([kit, app]) => {
kit.start(app, element);
});

Binary file not shown.

Binary file not shown.

View file

@ -1,11 +1,11 @@
package main
type Surfer struct {
Dbid string `json:"dbid"`
Id string `json:"id"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}
// type Surfer struct {
// Dbid string `json:"dbid"`
// Id string `json:"id"`
// Firstname string `json:"firstname"`
// Lastname string `json:"lastname"`
// }
///////////// Surfers

View file

@ -1,14 +1,14 @@
package main
type User struct {
Dbid string `json:"dbid"`
Id string `json:"id"`
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
Group string `json:"group"`
Enabled bool `json:"enabled"`
}
// type User struct {
// Dbid string `json:"dbid"`
// Id string `json:"id"`
// Username string `json:"username"`
// Password string `json:"password"`
// Email string `json:"email"`
// Group string `json:"group"`
// Enabled bool `json:"enabled"`
// }
///////////////// Users

View file

@ -14,7 +14,7 @@ type Webapp struct {
DB *scribble.Driver
}
const _MaxLen = 8
// const _MaxLen = 8
func InitHttp(d *scribble.Driver) *Webapp {
@ -29,11 +29,11 @@ func InitHttp(d *scribble.Driver) *Webapp {
wapp.initApi()
// wapp.initAuth()
displayH := router.Group("/display_h")
displayH.Static("/", "./static/display_h")
displayH := router.Group("/displayh")
displayH.Static("/", "./static/displayh")
displayV := router.Group("/display_v")
displayV.Static("/", "./static/display_v")
displayV := router.Group("/displayv")
displayV.Static("/", "./static/displayv")
priority := router.Group("/priority")
priority.Static("/", "./static/priority")
@ -41,6 +41,9 @@ func InitHttp(d *scribble.Driver) *Webapp {
mobile := router.Group("/mobile")
mobile.Static("/", "./static/mobile")
setup := router.Group("/setup")
setup.Static("/", "./static/setup")
sapp := router.Group("/_app")
sapp.Static("/", "./static/_app")

View file

@ -28,22 +28,6 @@
let end = false;
let start = false;
// function updateRemainingTime() {
// if ((min === 0) & (sec === 0)) {
// clearInterval(timer);
// end = true;
// } else if (sec === 0) {
// min -= 1;
// sec = 59;
// } else {
// sec -= 1;
// }
// }
// updateRemainingTime();
// const timer = setInterval(updateRemainingTime, 1000);
function Subscribe() {
const sse = new EventSource(`/api/sse`);
console.log('subscribe');
@ -76,19 +60,6 @@
console.log('pressed P');
} else {
console.log(`pressed: [${id}] ${surfers[id].priority}`);
// let oldps = parseInt(surfers[id].priority);
// for (let i in surfers) {
// if (i != id) {
// console.log(`pos: [${i}] ${surfers[i].priority} ${surfers[i].priority < oldpos}`);
// if (surfers[i].priority != 'P' && surfers[i].priority < oldpos) {
// let pos = parseInt(surfers[i].priority);
// if ()
// }
// } else {
// surfers[i] = 'P';
// console.log(`first: [${i}] ${surfers[i].priority}`);
// }
// }
}
}

View file