diff --git a/main.go b/main.go index 012e80b..f69ee38 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,8 @@ func main() { r.Get("/captures/{captureID}/stop", routes.Make(server.HandleCaptureStop)) r.Post("/new/capture", routes.Make(server.HandleCaptureCreate)) r.Get("/new/capture", routes.Make(server.HandleCaptureForm)) + + r.Post("/captures/{captureID}/mapscore/{mapscoreID}/counted/{counted}", routes.Make(server.HandleUpdateMapScoreCounted)) }) router.Post("/signin", routes.Make(server.HandleSignin)) router.Get("/", routes.Make(server.HandleHome)) diff --git a/models/capture.go b/models/capture.go index 7c9bdb9..c425c81 100644 --- a/models/capture.go +++ b/models/capture.go @@ -25,6 +25,7 @@ type MapScore struct { CaptureID int64 `bun:"capture_id"` StartTime time.Time `bun:",notnull"` Map string `bun:",notnull"` + Counted bool `bun:",notnull"` ScoreList []Score `bun:"rel:has-many,join:id=mapscore_id"` } @@ -60,8 +61,15 @@ func (msl MapScoreList) BuildTable() *ResultTable { rt.Header = append(rt.Header, make([]ResultTableHeader, len(msl))...) - for mapIndex, mapScore := range msl { - reversedIndex := len(msl) - 1 - mapIndex + filteredMapScores := []MapScore{} + for _, ms := range msl { + if ms.Counted { + filteredMapScores = append(filteredMapScores, ms) + } + } + + for mapIndex, mapScore := range filteredMapScores { + reversedIndex := len(filteredMapScores) - 1 - mapIndex rt.Header[reversedIndex+2] = ResultTableHeader{ Title: mapScore.Map, @@ -73,7 +81,7 @@ func (msl MapScoreList) BuildTable() *ResultTable { rt.Rows = append(rt.Rows, ResultTableRow{ Name: score.Name, Total: 0, - Individual: make([]int, len(msl)), + Individual: make([]int, len(filteredMapScores)), }) userMapRows[score.Name] = len(rt.Rows) - 1 diff --git a/models/persistence.go b/models/persistence.go index 4acfa46..95c70d2 100644 --- a/models/persistence.go +++ b/models/persistence.go @@ -18,6 +18,7 @@ type Persistence interface { DeleteCapture(context.Context, int64) error GetRecentMapScore(context.Context, int64) (*MapScore, error) + SetMapScoreConted(context.Context, int64, bool) error CreateMapScore(context.Context, *MapScore) error CreateOrUpdateScores(context.Context, []Score) error @@ -105,6 +106,14 @@ func (s *SQLitePersistence) GetRecentMapScore(ctx context.Context, captureid int return &scores[0], nil } +func (s *SQLitePersistence) SetMapScoreConted(ctx context.Context, mapscoreid int64, counted bool) error { + mapscore := MapScore{ + ID: mapscoreid, + } + _, err := s.db.NewUpdate().Model(&mapscore).WherePK().Set("counted = ?", counted).Exec(ctx) + return err +} + func (s *SQLitePersistence) CreateMapScore(ctx context.Context, mapscore *MapScore) error { _, err := s.db.NewInsert().Model(mapscore).Exec(ctx) diff --git a/routes/capture.go b/routes/capture.go index 8366365..d1408c8 100644 --- a/routes/capture.go +++ b/routes/capture.go @@ -7,7 +7,6 @@ import ( "gitea.henriburau.de/haw-lan/cod4watcher/models" "gitea.henriburau.de/haw-lan/cod4watcher/views/capture" - "gitea.henriburau.de/haw-lan/cod4watcher/views/components" "github.com/go-chi/chi" ) @@ -38,7 +37,7 @@ func (s *Server) HandleCaptureTable(w http.ResponseWriter, r *http.Request) erro return err } - return Render(w, r, components.CaptureTable(*foundCapture.MapScores.BuildTable())) + return Render(w, r, capture.TableWithLeaderboard(*foundCapture.MapScores.BuildTable())) } func (s *Server) HandleCaptureStart(w http.ResponseWriter, r *http.Request) error { @@ -87,7 +86,7 @@ func (s *Server) HandleCaptureDelete(w http.ResponseWriter, r *http.Request) err } func (s *Server) HandleCaptureForm(w http.ResponseWriter, r *http.Request) error { - return Render(w, r, capture.CaptureForm(capture.CaptureFormValues{}, map[string]string{})) + return Render(w, r, capture.CaptureForm(capture.CaptureFormValues{Port: "28960"}, map[string]string{})) } func (s *Server) HandleCaptureCreate(w http.ResponseWriter, r *http.Request) error { @@ -145,3 +144,35 @@ func parseCaptureFormAndValidate(r *http.Request) (capture.CaptureFormValues, ma return formValues, errors } + +func (s *Server) HandleUpdateMapScoreCounted(w http.ResponseWriter, r *http.Request) error { + captureString := chi.URLParam(r, "captureID") + captureID, err := strconv.ParseInt(captureString, 10, 64) + if err != nil { + return err + } + + mapscoreIDString := chi.URLParam(r, "mapscoreID") + mapscoreID, err := strconv.ParseInt(mapscoreIDString, 10, 64) + if err != nil { + return err + } + + countedString := chi.URLParam(r, "counted") + counted, err := strconv.ParseBool(countedString) + if err != nil { + return err + } + + err = s.cs.SetMapScoreConted(r.Context(), mapscoreID, counted) + if err != nil { + return err + } + + updatedCapture, err := s.cs.GetCaptureById(r.Context(), captureID) + if err != nil { + return err + } + + return Render(w, r, capture.MapSelectTable(updatedCapture)) +} diff --git a/routes/cod4server.go b/routes/cod4server.go index 841c3b1..d970490 100644 --- a/routes/cod4server.go +++ b/routes/cod4server.go @@ -9,9 +9,8 @@ import ( func (s *Server) HandleServerStatus(w http.ResponseWriter, r *http.Request) error { status, err := s.c4s.GetServerStatus(r.URL.Query().Get("host"), r.URL.Query().Get("port")) if err != nil { - w.WriteHeader(http.StatusBadRequest) - return err + return Render(w, r, cod4server.ServerStatusError(err)) + } else { + return Render(w, r, cod4server.ServerStatus(status)) } - - return Render(w, r, cod4server.ServerStatus(status)) } diff --git a/services/capture.go b/services/capture.go index 9aa1848..0ee3083 100644 --- a/services/capture.go +++ b/services/capture.go @@ -24,6 +24,10 @@ func (cs *CaptureService) DeleteCapture(ctx context.Context, id int64) error { return cs.p.DeleteCapture(ctx, id) } +func (cs *CaptureService) SetMapScoreConted(ctx context.Context, id int64, counted bool) error { + return cs.p.SetMapScoreConted(ctx, id, counted) +} + func (cs *CaptureService) GetActiveCapures(ctx context.Context) ([]models.Capture, error) { captures, err := cs.p.GetCaptures(ctx) if err != nil { diff --git a/services/scanner.go b/services/scanner.go index 40736ac..35f003b 100644 --- a/services/scanner.go +++ b/services/scanner.go @@ -70,6 +70,7 @@ func (s *Scanner) fetchInformation(ctx context.Context, capture models.Capture) CaptureID: capture.ID, StartTime: status.MapStartTime, Map: status.MapName, + Counted: true, } err := s.p.CreateMapScore(ctx, &newMap) @@ -89,5 +90,9 @@ func (s *Scanner) fetchInformation(ctx context.Context, capture models.Capture) scores = append(scores, score) } + if len(scores) <= 0 { + return nil + } + return s.p.CreateOrUpdateScores(ctx, scores) } diff --git a/views/auth/login_form.templ b/views/auth/login_form.templ index 7f18aaf..5259f6e 100644 --- a/views/auth/login_form.templ +++ b/views/auth/login_form.templ @@ -6,22 +6,23 @@ import ( ) type LoginFormValues struct { - Username string - Password string + Username string + Password string } templ LoginForm(formValues LoginFormValues, errors map[string]string) { @layouts.Base() { @components.Form(components.FormProps{ - Title: "Log into your account", - Action: "/signin", - Method: "post", + Title: "Log into your account", + Action: "/signin", + Method: "post", SubmitText: "Login", }) {
@components.Input(components.InputProps{ Name: "username", + Type: "text", Value: formValues.Username, Error: errors["username"], Placeholder: "Your username", @@ -31,6 +32,7 @@ templ LoginForm(formValues LoginFormValues, errors map[string]string) { @components.Input(components.InputProps{ Name: "password", + Type: "password", Value: formValues.Password, Error: errors["password"], Placeholder: "Your password", diff --git a/views/auth/login_form_templ.go b/views/auth/login_form_templ.go index 38ce4b2..1a6d813 100644 --- a/views/auth/login_form_templ.go +++ b/views/auth/login_form_templ.go @@ -45,12 +45,13 @@ func LoginForm(formValues LoginFormValues, errors map[string]string) templ.Compo templ_7745c5c3_Buffer = templ.GetBuffer() defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = components.Input(components.InputProps{ Name: "username", + Type: "text", Value: formValues.Username, Error: errors["username"], Placeholder: "Your username", @@ -58,12 +59,13 @@ func LoginForm(formValues LoginFormValues, errors map[string]string) templ.Compo if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = components.Input(components.InputProps{ Name: "password", + Type: "password", Value: formValues.Password, Error: errors["password"], Placeholder: "Your password", @@ -71,7 +73,7 @@ func LoginForm(formValues LoginFormValues, errors map[string]string) templ.Compo if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/auth/login_form_templ.txt b/views/auth/login_form_templ.txt new file mode 100644 index 0000000..f300b8b --- /dev/null +++ b/views/auth/login_form_templ.txt @@ -0,0 +1,3 @@ +
+
+
diff --git a/views/capture/capture.templ b/views/capture/capture.templ index d7163d4..c1801f1 100644 --- a/views/capture/capture.templ +++ b/views/capture/capture.templ @@ -2,6 +2,7 @@ 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" import "gitea.henriburau.de/haw-lan/cod4watcher/views/components" import "fmt" import "net/url" @@ -23,21 +24,14 @@ templ Capture(capture *models.Capture, table models.ResultTable) { Loading Server status...
-
- if len(table.Rows) >= 1 { - @Medal("1. Platz", table.Rows[0].Name, "text-yellow-400") - } - 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") - } -
+ @Pedestal(table)
- @components.CaptureTable(table) + @CaptureTable(table)
+ if views.Username(ctx) != "" { + @MapSelectTable(capture) + } } } @@ -50,3 +44,46 @@ templ Medal(placement, name, color string) { } + +templ Pedestal(table models.ResultTable) { +
+ if len(table.Rows) >= 1 { + @Medal("1. Platz", table.Rows[0].Name, "text-yellow-400") + } + 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") + } +
+} + +templ MapSelectTable(capture *models.Capture) { +
+ + + + + for _, maps := range capture.MapScores { + + } + + + + + + for _, maps := range capture.MapScores { + + } + + +
+ Map + + { maps.Map } +
Enabled + +
+
+} diff --git a/views/components/capture_card.templ b/views/capture/capture_card.templ similarity index 72% rename from views/components/capture_card.templ rename to views/capture/capture_card.templ index 6d9c9b0..36ab0be 100644 --- a/views/components/capture_card.templ +++ b/views/capture/capture_card.templ @@ -1,7 +1,8 @@ -package components +package capture import "gitea.henriburau.de/haw-lan/cod4watcher/models" import "gitea.henriburau.de/haw-lan/cod4watcher/views" +import "gitea.henriburau.de/haw-lan/cod4watcher/views/components" import "fmt" import "net/url" @@ -19,11 +20,11 @@ templ CaptureCard(capture models.Capture) { if views.Username(ctx) != "" {
- @IconButtonRed("fa-solid fa-trash", fmt.Sprintf("/captures/%d", capture.ID)) + @components.IconButtonRed("fa-solid fa-trash", fmt.Sprintf("/captures/%d", capture.ID)) if capture.Active { - @IconButton("fa-solid fa-stop", fmt.Sprintf("/captures/%d/stop", capture.ID)) + @components.IconButton("fa-solid fa-stop", fmt.Sprintf("/captures/%d/stop", capture.ID)) } else { - @IconButton("fa-solid fa-play", fmt.Sprintf("/captures/%d/start", capture.ID)) + @components.IconButton("fa-solid fa-play", fmt.Sprintf("/captures/%d/start", capture.ID)) }
} diff --git a/views/components/capture_card_templ.go b/views/capture/capture_card_templ.go similarity index 70% rename from views/components/capture_card_templ.go rename to views/capture/capture_card_templ.go index e80bfda..3619641 100644 --- a/views/components/capture_card_templ.go +++ b/views/capture/capture_card_templ.go @@ -1,7 +1,7 @@ // Code generated by templ - DO NOT EDIT. // templ: version: v0.2.707 -package components +package capture //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -12,6 +12,7 @@ import "bytes" import "gitea.henriburau.de/haw-lan/cod4watcher/models" import "gitea.henriburau.de/haw-lan/cod4watcher/views" +import "gitea.henriburau.de/haw-lan/cod4watcher/views/components" import "fmt" import "net/url" @@ -28,7 +29,7 @@ func CaptureCard(capture models.Capture) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) 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/components/capture_card.templ`, Line: 11, Col: 98} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_card.templ`, Line: 12, Col: 98} } _, 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("

") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(capture.Host) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/capture_card.templ`, Line: 13, Col: 72} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_card.templ`, Line: 14, Col: 72} } _, 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.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(capture.Port) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/capture_card.templ`, Line: 13, Col: 89} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_card.templ`, Line: 14, Col: 89} } _, 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("

Loading Server status...
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if views.Username(ctx) != "" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = IconButtonRed("fa-solid fa-trash", fmt.Sprintf("/captures/%d", capture.ID)).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = components.IconButtonRed("fa-solid fa-trash", fmt.Sprintf("/captures/%d", capture.ID)).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if capture.Active { - templ_7745c5c3_Err = IconButton("fa-solid fa-stop", fmt.Sprintf("/captures/%d/stop", capture.ID)).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = components.IconButton("fa-solid fa-stop", fmt.Sprintf("/captures/%d/stop", capture.ID)).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = IconButton("fa-solid fa-play", fmt.Sprintf("/captures/%d/start", capture.ID)).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = components.IconButton("fa-solid fa-play", fmt.Sprintf("/captures/%d/start", capture.ID)).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/capture/capture_card_templ.txt b/views/capture/capture_card_templ.txt new file mode 100644 index 0000000..7e60ea7 --- /dev/null +++ b/views/capture/capture_card_templ.txt @@ -0,0 +1,9 @@ +
+

+: +

Loading Server status...
+
+
+
diff --git a/views/capture/capture_form.templ b/views/capture/capture_form.templ index 0b84c56..d6e575a 100644 --- a/views/capture/capture_form.templ +++ b/views/capture/capture_form.templ @@ -6,25 +6,26 @@ import ( ) type CaptureFormValues struct { - Host string - Port string - Name string - Active bool + Host string + Port string + Name string + Active bool ValidateServer bool } templ CaptureForm(formValues CaptureFormValues, errors map[string]string) { @layouts.Base() { @components.Form(components.FormProps{ - Title: "Create new capture", - Action: "/new/capture", - Method: "post", + Title: "Create new capture", + Action: "/new/capture", + Method: "post", SubmitText: "Create capture", }) {
@components.Input(components.InputProps{ Name: "name", + Type: "text", Value: formValues.Name, Error: errors["name"], Placeholder: "Name for the capture", @@ -34,6 +35,7 @@ templ CaptureForm(formValues CaptureFormValues, errors map[string]string) { @components.Input(components.InputProps{ Name: "host", + Type: "text", Value: formValues.Host, Error: errors["host"], Placeholder: "Host-Address of the capture", @@ -43,6 +45,7 @@ templ CaptureForm(formValues CaptureFormValues, errors map[string]string) { @components.Input(components.InputProps{ Name: "port", + Type: "text", Value: formValues.Port, Error: errors["port"], Placeholder: "Port for the capture", diff --git a/views/capture/capture_form_templ.go b/views/capture/capture_form_templ.go index cb38435..8901f5a 100644 --- a/views/capture/capture_form_templ.go +++ b/views/capture/capture_form_templ.go @@ -48,12 +48,13 @@ 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("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = components.Input(components.InputProps{ Name: "name", + Type: "text", Value: formValues.Name, Error: errors["name"], Placeholder: "Name for the capture", @@ -61,12 +62,13 @@ func CaptureForm(formValues CaptureFormValues, errors map[string]string) templ.C if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = components.Input(components.InputProps{ Name: "host", + Type: "text", Value: formValues.Host, Error: errors["host"], Placeholder: "Host-Address of the capture", @@ -74,12 +76,13 @@ func CaptureForm(formValues CaptureFormValues, errors map[string]string) templ.C if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } templ_7745c5c3_Err = components.Input(components.InputProps{ Name: "port", + Type: "text", Value: formValues.Port, Error: errors["port"], Placeholder: "Port for the capture", @@ -87,7 +90,7 @@ func CaptureForm(formValues CaptureFormValues, errors map[string]string) templ.C if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/capture/capture_form_templ.txt b/views/capture/capture_form_templ.txt new file mode 100644 index 0000000..82f9489 --- /dev/null +++ b/views/capture/capture_form_templ.txt @@ -0,0 +1,4 @@ +
+
+
+
diff --git a/views/components/capture_table.templ b/views/capture/capture_table.templ similarity index 98% rename from views/components/capture_table.templ rename to views/capture/capture_table.templ index 6a5f7b2..bbcf4d9 100644 --- a/views/components/capture_table.templ +++ b/views/capture/capture_table.templ @@ -1,4 +1,4 @@ -package components +package capture import "gitea.henriburau.de/haw-lan/cod4watcher/models" import "strconv" diff --git a/views/components/capture_table_templ.go b/views/capture/capture_table_templ.go similarity index 69% rename from views/components/capture_table_templ.go rename to views/capture/capture_table_templ.go index 9c53193..0ffdfd8 100644 --- a/views/components/capture_table_templ.go +++ b/views/capture/capture_table_templ.go @@ -1,7 +1,7 @@ // Code generated by templ - DO NOT EDIT. // templ: version: v0.2.707 -package components +package capture //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -26,102 +26,102 @@ func CaptureTable(table models.ResultTable) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, header := range table.Header { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, row := range table.Rows { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, score := range row.Individual { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(header.Title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/capture_table.templ`, Line: 14, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_table.templ`, Line: 14, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var3 string templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(header.Subtitle) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/capture_table.templ`, Line: 17, Col: 25} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_table.templ`, Line: 17, Col: 25} } _, 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("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(row.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/capture_table.templ`, Line: 27, Col: 17} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_table.templ`, Line: 27, Col: 17} } _, 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.WriteWatchModeString(templ_7745c5c3_Buffer, 7) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var5 string templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(row.Total)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/capture_table.templ`, Line: 30, Col: 32} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_table.templ`, Line: 30, Col: 32} } _, 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("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(score)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/capture_table.templ`, Line: 34, Col: 29} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture_table.templ`, Line: 34, Col: 29} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/capture/capture_table_templ.txt b/views/capture/capture_table_templ.txt new file mode 100644 index 0000000..8202436 --- /dev/null +++ b/views/capture/capture_table_templ.txt @@ -0,0 +1,12 @@ +
+ + + + + +
+
+
+ + +
diff --git a/views/capture/capture_table_update.templ b/views/capture/capture_table_update.templ new file mode 100644 index 0000000..cbee270 --- /dev/null +++ b/views/capture/capture_table_update.templ @@ -0,0 +1,8 @@ +package capture + +import "gitea.henriburau.de/haw-lan/cod4watcher/models" + +templ TableWithLeaderboard(table models.ResultTable) { + @Pedestal(table) + @CaptureTable(table) +} diff --git a/views/capture/capture_table_update_templ.go b/views/capture/capture_table_update_templ.go new file mode 100644 index 0000000..ef202a8 --- /dev/null +++ b/views/capture/capture_table_update_templ.go @@ -0,0 +1,41 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.707 +package capture + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import "gitea.henriburau.de/haw-lan/cod4watcher/models" + +func TableWithLeaderboard(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 { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = Pedestal(table).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = CaptureTable(table).Render(ctx, templ_7745c5c3_Buffer) + 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 + }) +} diff --git a/views/capture/capture_templ.go b/views/capture/capture_templ.go index e0fe6a7..d4b29aa 100644 --- a/views/capture/capture_templ.go +++ b/views/capture/capture_templ.go @@ -12,6 +12,7 @@ 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" import "gitea.henriburau.de/haw-lan/cod4watcher/views/components" import "fmt" import "net/url" @@ -35,20 +36,20 @@ func Capture(capture *models.Capture, table models.ResultTable) templ.Component templ_7745c5c3_Buffer = templ.GetBuffer() defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) 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: 15, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 16, 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("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -56,63 +57,59 @@ func Capture(capture *models.Capture, table models.ResultTable) templ.Component if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
Loading Server status...
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) 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-400").Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } + templ_7745c5c3_Err = Pedestal(table).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("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = components.CaptureTable(table).Render(ctx, templ_7745c5c3_Buffer) + templ_7745c5c3_Err = CaptureTable(table).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if views.Username(ctx) != "" { + templ_7745c5c3_Err = MapSelectTable(capture).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -145,7 +142,7 @@ func Medal(placement, name, color string) templ.Component { templ_7745c5c3_Var6 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -154,7 +151,7 @@ func Medal(placement, name, color string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11) 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} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 43, 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(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12) 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} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 43, 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("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 13) + 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 + }) +} + +func Pedestal(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 { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var11 := templ.GetChildren(ctx) + if templ_7745c5c3_Var11 == nil { + templ_7745c5c3_Var11 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 14) + 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-400").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.WriteWatchModeString(templ_7745c5c3_Buffer, 15) + 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 + }) +} + +func MapSelectTable(capture *models.Capture) 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_Var12 := templ.GetChildren(ctx) + if templ_7745c5c3_Var12 == nil { + templ_7745c5c3_Var12 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 16) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, maps := range capture.MapScores { + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 17) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var13 string + templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(maps.Map) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 72, Col: 17} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 18) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 19) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, maps := range capture.MapScores { + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 20) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var14 string + templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/captures/%d/mapscore/%d/counted/%t", capture.ID, maps.ID, !maps.Counted)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/capture/capture.templ`, Line: 82, Col: 172} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 21) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if maps.Counted { + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 22) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 23) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 24) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/capture/capture_templ.txt b/views/capture/capture_templ.txt new file mode 100644 index 0000000..5967663 --- /dev/null +++ b/views/capture/capture_templ.txt @@ -0,0 +1,24 @@ +
+
+
Loading Server status...
+
+
+
+
+ + +
+
+
+
+ + + +
Map +
Enabled
diff --git a/views/cod4server/server_status.templ b/views/cod4server/server_status.templ index a4f51b5..c976284 100644 --- a/views/cod4server/server_status.templ +++ b/views/cod4server/server_status.templ @@ -10,7 +10,13 @@ templ ServerStatus(status *models.CoD4ServerStatus) { { fmt.Sprintf("%d/%d",len(status.Score), status.MaxPlayers) }
-
+
@templ.Raw(status.Name)
} + +templ ServerStatusError(err error) { +
+ Failed to reach server +
+} diff --git a/views/cod4server/server_status_templ.go b/views/cod4server/server_status_templ.go index 9b9dec5..f521546 100644 --- a/views/cod4server/server_status_templ.go +++ b/views/cod4server/server_status_templ.go @@ -26,7 +26,7 @@ func ServerStatus(status *models.CoD4ServerStatus) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -39,7 +39,7 @@ func ServerStatus(status *models.CoD4ServerStatus) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -52,7 +52,7 @@ func ServerStatus(status *models.CoD4ServerStatus) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -60,7 +60,31 @@ func ServerStatus(status *models.CoD4ServerStatus) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) + 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 + }) +} + +func ServerStatusError(err error) 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_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/cod4server/server_status_templ.txt b/views/cod4server/server_status_templ.txt new file mode 100644 index 0000000..cb35185 --- /dev/null +++ b/views/cod4server/server_status_templ.txt @@ -0,0 +1,5 @@ +
+ +
+
+
Failed to reach server
diff --git a/views/components/button_templ.go b/views/components/button_templ.go index 6a4c306..5e24093 100644 --- a/views/components/button_templ.go +++ b/views/components/button_templ.go @@ -23,7 +23,7 @@ func Button() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -55,7 +55,7 @@ func SubmitButton() templ.Component { templ_7745c5c3_Var2 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -87,7 +87,7 @@ func IconButton(icon, url string) templ.Component { templ_7745c5c3_Var3 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -105,7 +105,7 @@ func IconButton(icon, url string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -142,7 +142,7 @@ func IconButtonRed(icon, url string) templ.Component { templ_7745c5c3_Var7 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -164,7 +164,7 @@ func IconButtonRed(icon, url string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/components/button_templ.txt b/views/components/button_templ.txt new file mode 100644 index 0000000..691a73b --- /dev/null +++ b/views/components/button_templ.txt @@ -0,0 +1,12 @@ + + + + + + diff --git a/views/components/form_templ.go b/views/components/form_templ.go index 43de612..5ce6944 100644 --- a/views/components/form_templ.go +++ b/views/components/form_templ.go @@ -30,7 +30,7 @@ func Form(props FormProps) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -65,7 +65,7 @@ func Form(props FormProps) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -97,7 +97,7 @@ func Form(props FormProps) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/components/form_templ.txt b/views/components/form_templ.txt new file mode 100644 index 0000000..fe27185 --- /dev/null +++ b/views/components/form_templ.txt @@ -0,0 +1,5 @@ +
+
+
diff --git a/views/components/input.templ b/views/components/input.templ index f032328..bb90b26 100644 --- a/views/components/input.templ +++ b/views/components/input.templ @@ -2,13 +2,14 @@ package components type InputProps struct { Name string + Type string Value string Error string Placeholder string } templ Input(props InputProps) { - + if props.Error != "" { { props.Error } } diff --git a/views/components/input_templ.go b/views/components/input_templ.go index 199e951..95a2606 100644 --- a/views/components/input_templ.go +++ b/views/components/input_templ.go @@ -12,6 +12,7 @@ import "bytes" type InputProps struct { Name string + Type string Value string Error string Placeholder string @@ -30,77 +31,90 @@ func Input(props InputProps) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(props.Placeholder) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/input.templ`, Line: 12, Col: 335} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if props.Error != "" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var6 string - templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(props.Error) + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(props.Error) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/input.templ`, Line: 13, Col: 42} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/components/input.templ`, Line: 14, Col: 42} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/components/input_templ.txt b/views/components/input_templ.txt new file mode 100644 index 0000000..6a175ea --- /dev/null +++ b/views/components/input_templ.txt @@ -0,0 +1,8 @@ + + + diff --git a/views/components/navbar_templ.go b/views/components/navbar_templ.go index 75cf033..8429070 100644 --- a/views/components/navbar_templ.go +++ b/views/components/navbar_templ.go @@ -27,27 +27,27 @@ func Nagivation() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/components/navbar_templ.txt b/views/components/navbar_templ.txt new file mode 100644 index 0000000..a1358a6 --- /dev/null +++ b/views/components/navbar_templ.txt @@ -0,0 +1,8 @@ + diff --git a/views/components/server_address_templ.go b/views/components/server_address_templ.go index 8ce3e3a..181698f 100644 --- a/views/components/server_address_templ.go +++ b/views/components/server_address_templ.go @@ -25,7 +25,7 @@ func ServerAddress(host, port string) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -38,7 +38,7 @@ func ServerAddress(host, port string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(":") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -51,7 +51,7 @@ func ServerAddress(host, port string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/components/server_address_templ.txt b/views/components/server_address_templ.txt new file mode 100644 index 0000000..0e13c5c --- /dev/null +++ b/views/components/server_address_templ.txt @@ -0,0 +1,4 @@ +
+: +
diff --git a/views/home/index.templ b/views/home/index.templ index 4b6c596..a06929a 100644 --- a/views/home/index.templ +++ b/views/home/index.templ @@ -3,6 +3,7 @@ package home import "gitea.henriburau.de/haw-lan/cod4watcher/views/layouts" import "gitea.henriburau.de/haw-lan/cod4watcher/models" import "gitea.henriburau.de/haw-lan/cod4watcher/views/components" +import "gitea.henriburau.de/haw-lan/cod4watcher/views/capture" import "gitea.henriburau.de/haw-lan/cod4watcher/views" templ Index(captures []models.Capture) { @@ -14,10 +15,9 @@ templ Index(captures []models.Capture) { } } -
- for _, capture := range captures { - @components.CaptureCard(capture) + for _, currentCapture := range captures { + @capture.CaptureCard(currentCapture) }
} diff --git a/views/home/index_templ.go b/views/home/index_templ.go index 2d036a7..686ebe7 100644 --- a/views/home/index_templ.go +++ b/views/home/index_templ.go @@ -13,6 +13,7 @@ import "bytes" import "gitea.henriburau.de/haw-lan/cod4watcher/views/layouts" import "gitea.henriburau.de/haw-lan/cod4watcher/models" import "gitea.henriburau.de/haw-lan/cod4watcher/views/components" +import "gitea.henriburau.de/haw-lan/cod4watcher/views/capture" import "gitea.henriburau.de/haw-lan/cod4watcher/views" func Index(captures []models.Capture) templ.Component { @@ -35,7 +36,7 @@ func Index(captures []models.Capture) templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } if views.Username(ctx) != "" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -45,7 +46,7 @@ func Index(captures []models.Capture) templ.Component { templ_7745c5c3_Buffer = templ.GetBuffer() defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Create new Capture") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -58,22 +59,22 @@ func Index(captures []models.Capture) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - for _, capture := range captures { - templ_7745c5c3_Err = components.CaptureCard(capture).Render(ctx, templ_7745c5c3_Buffer) + for _, currentCapture := range captures { + templ_7745c5c3_Err = capture.CaptureCard(currentCapture).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/home/index_templ.txt b/views/home/index_templ.txt new file mode 100644 index 0000000..d6794eb --- /dev/null +++ b/views/home/index_templ.txt @@ -0,0 +1,5 @@ + +Create new Capture + +
+
diff --git a/views/layouts/base_templ.go b/views/layouts/base_templ.go index fa87ba1..a405cff 100644 --- a/views/layouts/base_templ.go +++ b/views/layouts/base_templ.go @@ -25,7 +25,7 @@ func Base() templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("CoD 4 Turnier-Tracker") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -33,7 +33,7 @@ func Base() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -41,7 +41,7 @@ func Base() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/views/layouts/base_templ.txt b/views/layouts/base_templ.txt new file mode 100644 index 0000000..8690f95 --- /dev/null +++ b/views/layouts/base_templ.txt @@ -0,0 +1,3 @@ +CoD 4 Turnier-Tracker +
+