admin penalizace
This commit is contained in:
31
admin.go
31
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
|
||||
}
|
||||
}
|
||||
|
||||
1
klice.go
1
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"))))
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<a href="/admin/cipher">Šifry</a> <br>
|
||||
<a href="/admin/positions">Pozice</a> <br>
|
||||
<a href="/admin/qr">QR Kódy</a> <br>
|
||||
<a href="/admin/penalties">Penalizace týmů</a> <br>
|
||||
<hr>
|
||||
<form method="post" action="/admin/logout">
|
||||
<input type="submit" value="Logout">
|
||||
|
||||
29
templates/adminPenalties.html
Normal file
29
templates/adminPenalties.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Penalizace týmů</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Penalizace týmů</h1>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Název týmu</th>
|
||||
<th>Pořadí šifry</th>
|
||||
<th>Minuty</th>
|
||||
</tr>
|
||||
{{range .}}
|
||||
<tr>
|
||||
<td>{{.TeamName}}</td>
|
||||
<td>{{.TaskOrder}}</td>
|
||||
<td>{{.Minutes}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
<hr>
|
||||
<a href="/admin">Zpět na admin panel</a>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user