From 94440e78defd0e36edc5b50f91ffd26cfe155e40 Mon Sep 17 00:00:00 2001 From: prokopparuzek Date: Tue, 28 Oct 2025 16:46:11 +0100 Subject: [PATCH] admin penalizace --- admin.go | 31 +++++++++++++++++++++++++++++++ klice.go | 1 + templates.go | 7 +++++++ templates/adminPanel.html | 1 + templates/adminPenalties.html | 29 +++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 templates/adminPenalties.html diff --git a/admin.go b/admin.go index af5063f..0735153 100644 --- a/admin.go +++ b/admin.go @@ -631,3 +631,34 @@ func AdminQRHandler(w http.ResponseWriter, r *http.Request) { return } } + +func AdminPenaltiesHandler(w http.ResponseWriter, r *http.Request) { + if !isAdmin(r) { + http.Redirect(w, r, "/admin/login", http.StatusSeeOther) + return + } + // Fetch all penalties with team names and task orders + rows, err := db.Query("SELECT teams.name, tasks.order_num, penalties.minutes FROM penalties JOIN teams ON penalties.team_id = teams.id JOIN tasks ON penalties.task_id = tasks.id ORDER BY teams.name, tasks.order_num") + if err != nil { + http.Error(w, "Database error", http.StatusInternalServerError) + return + } + defer rows.Close() + var penalties []AdminPenaltiesTemplateS + for rows.Next() { + var penalty AdminPenaltiesTemplateS + if err := rows.Scan(&penalty.TeamName, &penalty.TaskOrder, &penalty.Minutes); err != nil { + http.Error(w, "Database error", http.StatusInternalServerError) + return + } + penalties = append(penalties, penalty) + } + if err := rows.Err(); err != nil { + http.Error(w, "Database error", http.StatusInternalServerError) + return + } + if err := AdminPenaltiesTemplate.Execute(w, penalties); err != nil { + http.Error(w, "Template error", http.StatusInternalServerError) + return + } +} diff --git a/klice.go b/klice.go index fafec47..5f25d72 100644 --- a/klice.go +++ b/klice.go @@ -355,6 +355,7 @@ func main() { http.HandleFunc("/admin/cipher", AdminCipherHandler) http.HandleFunc("/admin/positions", AdminPositionsHandler) http.HandleFunc("/admin/qr", AdminQRHandler) + http.HandleFunc("/admin/penalties", AdminPenaltiesHandler) // static files http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) diff --git a/templates.go b/templates.go index 84a8693..716c541 100644 --- a/templates.go +++ b/templates.go @@ -79,6 +79,12 @@ type AdminLevelTemplateS struct { Name string } +type AdminPenaltiesTemplateS struct { + TeamName string + TaskOrder uint + Minutes int +} + var CipherTemplate = template.Must(template.ParseFiles("templates/assignment.html")) var TeamTemplate = template.Must(template.ParseFiles("templates/team.html")) var AdminTeamsTemplate = template.Must(template.ParseFiles("templates/adminTeams.html")) @@ -87,3 +93,4 @@ var AdminLevelTemplate = template.Must(template.ParseFiles("templates/adminLevel var AdminCipherTemplate = template.Must(template.ParseFiles("templates/adminCiphers.html")) var AdminPositionsTemplate = template.Must(template.ParseFiles("templates/adminPositions.html")) var AdminQRsTemplate = template.Must(template.ParseFiles("templates/adminQR.html")) +var AdminPenaltiesTemplate = template.Must(template.ParseFiles("templates/adminPenalties.html")) diff --git a/templates/adminPanel.html b/templates/adminPanel.html index 79dcd19..6a055f4 100644 --- a/templates/adminPanel.html +++ b/templates/adminPanel.html @@ -14,6 +14,7 @@ Šifry
Pozice
QR Kódy
+ Penalizace týmů

diff --git a/templates/adminPenalties.html b/templates/adminPenalties.html new file mode 100644 index 0000000..01e38cd --- /dev/null +++ b/templates/adminPenalties.html @@ -0,0 +1,29 @@ + + + + + + Penalizace týmů + + + +

Penalizace týmů

+ + + + + + + {{range .}} + + + + + + {{end}} +
Název týmuPořadí šifryMinuty
{{.TeamName}}{{.TaskOrder}}{{.Minutes}}
+
+ Zpět na admin panel + + + \ No newline at end of file