Basic functionality

This commit is contained in:
Henri Burau
2024-06-05 18:01:08 +02:00
parent 17f878f088
commit 72dce76e2b
41 changed files with 1568 additions and 176 deletions

View File

@ -3,17 +3,50 @@ package capture
import "gitea.henriburau.de/haw-lan/cod4watcher/models"
import "gitea.henriburau.de/haw-lan/cod4watcher/views/layouts"
import "gitea.henriburau.de/haw-lan/cod4watcher/views/components"
import "fmt"
import "net/url"
templ Capture(capture *models.Capture) {
templ Capture(capture *models.Capture, table models.ResultTable) {
@layouts.Base() {
<div class="flex flex-col">
<div class="block font-bold text-lg">
{ capture.Name }
<div class="flex">
<div>
<div class="block font-bold text-lg">
{ capture.Name }
</div>
@components.ServerAddress(capture.Host, capture.Port)
<div
class="my-3 w-60"
hx-get={ fmt.Sprintf("/server/status?host=%s&port=%s", url.QueryEscape(capture.Host), url.QueryEscape(capture.Port)) }
hx-trigger="load, every 20s"
>
Loading Server status...
</div>
</div>
<div class="flex w-full justify-around items-center gap-5">
if len(table.Rows) >= 1 {
@Medal("1. Platz", table.Rows[0].Name, "text-yellow-600")
}
if len(table.Rows) >= 2 {
@Medal("2. Platz", table.Rows[1].Name, "text-gray-500")
}
if len(table.Rows) >= 3 {
@Medal("3. Platz", table.Rows[2].Name, "text-amber-700")
}
</div>
</div>
<div class="block">
{ capture.Host }:{ capture.Port }
<div hx-get={ fmt.Sprintf("/captures/%d/table", capture.ID) } hx-trigger="every 10s">
@components.CaptureTable(table)
</div>
@components.CaptureTable(*capture.MapScores.BuildTable())
</div>
}
}
templ Medal(placement, name, color string) {
<div class="flex flex-col gap-2">
<i class={ "fa-solid", "fa-medal","text-3xl", color }></i>
<span>
{ placement } { name }
</span>
</div>
}

View File

@ -1,50 +1,53 @@
package capture
import "gitea.henriburau.de/haw-lan/cod4watcher/views/layouts"
import "gitea.henriburau.de/haw-lan/cod4watcher/views/components"
import (
"gitea.henriburau.de/haw-lan/cod4watcher/views/layouts"
"gitea.henriburau.de/haw-lan/cod4watcher/views/components"
)
type CaptureFormValues struct {
Host string
Port string
Name string
Active bool
ValidateServer bool
}
templ CaptureForm(formValues CaptureFormValues, errors map[string]string) {
@layouts.Base() {
<div class="w-full mx-auto max-w-96 p-4 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
<form class="space-y-6" action="/new/capture" method="post">
<h5 class="text-xl font-medium text-gray-900 dark:text-white">Create new capture</h5>
<div>
<label for="name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Name</label>
@components.Input(components.InputProps{
Name: "name",
Value: formValues.Name,
Error: errors["name"],
Placeholder: "Name for the capture",
})
</div>
<div>
<label for="host" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Host</label>
@components.Input(components.InputProps{
Name: "host",
Value: formValues.Host,
Error: errors["host"],
Placeholder: "Host-Address of the capture",
})
</div>
<div>
<label for="port" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Port</label>
@components.Input(components.InputProps{
Name: "port",
Value: formValues.Port,
Error: errors["port"],
Placeholder: "Port for the capture",
})
</div>
<button type="submit" method="post" class="w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
Create capture
</button>
</form>
</div>
@components.Form(components.FormProps{
Title: "Create new capture",
Action: "/new/capture",
Method: "post",
SubmitText: "Create capture",
}) {
<div>
<label for="name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Name</label>
@components.Input(components.InputProps{
Name: "name",
Value: formValues.Name,
Error: errors["name"],
Placeholder: "Name for the capture",
})
</div>
<div>
<label for="host" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Host</label>
@components.Input(components.InputProps{
Name: "host",
Value: formValues.Host,
Error: errors["host"],
Placeholder: "Host-Address of the capture",
})
</div>
<div>
<label for="port" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Port</label>
@components.Input(components.InputProps{
Name: "port",
Value: formValues.Port,
Error: errors["port"],
Placeholder: "Port for the capture",
})
</div>
}
}
}

View File

@ -10,13 +10,17 @@ import "context"
import "io"
import "bytes"
import "gitea.henriburau.de/haw-lan/cod4watcher/views/layouts"
import "gitea.henriburau.de/haw-lan/cod4watcher/views/components"
import (
"gitea.henriburau.de/haw-lan/cod4watcher/views/components"
"gitea.henriburau.de/haw-lan/cod4watcher/views/layouts"
)
type CaptureFormValues struct {
Host string
Port string
Name string
Host string
Port string
Name string
Active bool
ValidateServer bool
}
func CaptureForm(formValues CaptureFormValues, errors map[string]string) templ.Component {
@ -38,46 +42,66 @@ func CaptureForm(formValues CaptureFormValues, errors map[string]string) templ.C
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"w-full mx-auto max-w-96 p-4 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700\"><form class=\"space-y-6\" action=\"/new/capture\" method=\"post\"><h5 class=\"text-xl font-medium text-gray-900 dark:text-white\">Create new capture</h5><div><label for=\"name\" class=\"block mb-2 text-sm font-medium text-gray-900 dark:text-white\">Name</label>")
if templ_7745c5c3_Err != nil {
templ_7745c5c3_Var3 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div><label for=\"name\" class=\"block mb-2 text-sm font-medium text-gray-900 dark:text-white\">Name</label>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.Input(components.InputProps{
Name: "name",
Value: formValues.Name,
Error: errors["name"],
Placeholder: "Name for the capture",
}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div><label for=\"host\" class=\"block mb-2 text-sm font-medium text-gray-900 dark:text-white\">Host</label>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.Input(components.InputProps{
Name: "host",
Value: formValues.Host,
Error: errors["host"],
Placeholder: "Host-Address of the capture",
}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div><label for=\"port\" class=\"block mb-2 text-sm font-medium text-gray-900 dark:text-white\">Port</label>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.Input(components.InputProps{
Name: "port",
Value: formValues.Port,
Error: errors["port"],
Placeholder: "Port for the capture",
}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer)
}
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.Input(components.InputProps{
Name: "name",
Value: formValues.Name,
Error: errors["name"],
Placeholder: "Name for the capture",
}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div><label for=\"host\" class=\"block mb-2 text-sm font-medium text-gray-900 dark:text-white\">Host</label>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.Input(components.InputProps{
Name: "host",
Value: formValues.Host,
Error: errors["host"],
Placeholder: "Host-Address of the capture",
}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div><label for=\"port\" class=\"block mb-2 text-sm font-medium text-gray-900 dark:text-white\">Port</label>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.Input(components.InputProps{
Name: "port",
Value: formValues.Port,
Error: errors["port"],
Placeholder: "Port for the capture",
}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><button type=\"submit\" method=\"post\" class=\"w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800\">Create capture</button></form></div>")
})
templ_7745c5c3_Err = components.Form(components.FormProps{
Title: "Create new capture",
Action: "/new/capture",
Method: "post",
SubmitText: "Create capture",
}).Render(templ.WithChildren(ctx, templ_7745c5c3_Var3), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}

View File

@ -13,8 +13,10 @@ import "bytes"
import "gitea.henriburau.de/haw-lan/cod4watcher/models"
import "gitea.henriburau.de/haw-lan/cod4watcher/views/layouts"
import "gitea.henriburau.de/haw-lan/cod4watcher/views/components"
import "fmt"
import "net/url"
func Capture(capture *models.Capture) templ.Component {
func Capture(capture *models.Capture, table models.ResultTable) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
@ -33,54 +35,84 @@ func Capture(capture *models.Capture) templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"flex flex-col\"><div class=\"block font-bold text-lg\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"flex flex-col\"><div class=\"flex\"><div><div class=\"block font-bold text-lg\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(capture.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 11, Col: 18}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 15, Col: 20}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div class=\"block\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.ServerAddress(capture.Host, capture.Port).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"my-3 w-60\" hx-get=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(capture.Host)
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/server/status?host=%s&port=%s", url.QueryEscape(capture.Host), url.QueryEscape(capture.Port)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 14, Col: 18}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 20, Col: 122}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(":")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-trigger=\"load, every 20s\">Loading Server status...</div></div><div class=\"flex w-full justify-around items-center gap-5\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(table.Rows) >= 1 {
templ_7745c5c3_Err = Medal("1. Platz", table.Rows[0].Name, "text-yellow-600").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if len(table.Rows) >= 2 {
templ_7745c5c3_Err = Medal("2. Platz", table.Rows[1].Name, "text-gray-500").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if len(table.Rows) >= 3 {
templ_7745c5c3_Err = Medal("3. Platz", table.Rows[2].Name, "text-amber-700").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div><div hx-get=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(capture.Port)
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/captures/%d/table", capture.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 14, Col: 35}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 38, Col: 62}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-trigger=\"every 10s\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = components.CaptureTable(*capture.MapScores.BuildTable()).Render(ctx, templ_7745c5c3_Buffer)
templ_7745c5c3_Err = components.CaptureTable(table).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -99,3 +131,75 @@ func Capture(capture *models.Capture) templ.Component {
return templ_7745c5c3_Err
})
}
func Medal(placement, name, color string) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var6 := templ.GetChildren(ctx)
if templ_7745c5c3_Var6 == nil {
templ_7745c5c3_Var6 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"flex flex-col gap-2\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 = []any{"fa-solid", "fa-medal", "text-3xl", color}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var7...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<i class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var7).String())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 1, Col: 0}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></i> <span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(placement)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 49, Col: 14}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 49, Col: 23}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
})
}