Add admin page
This commit is contained in:
51
database/admin.go
Normal file
51
database/admin.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"log"
|
||||
"trikotwaschliste/models"
|
||||
)
|
||||
|
||||
func DbAdminMainpage(pool *pgxpool.Pool) gin.H {
|
||||
var items []models.Washlist
|
||||
var persons []models.Person
|
||||
|
||||
witems, err := pool.Query(context.Background(), "SELECT wa.id, pe.name, ga.created_at, wa.washed \nFROM washlist wa\nINNER JOIN persons pe ON wa.personid = pe.id\nINNER JOIN gamedata ga ON wa.gamedataid = ga.id ORDER BY ga.created_at ASC")
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
|
||||
var item models.Washlist
|
||||
for witems.Next() {
|
||||
err = witems.Scan(&item.Id, &item.Person, &item.Date, &item.Washed)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
item.DateString = item.Date.Format(layoutDE)
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
// get persons
|
||||
wperson, err := pool.Query(context.Background(), "SELECT id, name FROM persons ORDER BY name ASC")
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
|
||||
persons = append(persons, models.Person{
|
||||
Id: -1,
|
||||
Name: "-- Auswählen --",
|
||||
})
|
||||
var person models.Person
|
||||
for wperson.Next() {
|
||||
err = wperson.Scan(&person.Id, &person.Name)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
persons = append(persons, person)
|
||||
}
|
||||
|
||||
|
||||
return gin.H{"items": items, "persons": persons}
|
||||
}
|
14
handler/admin.go
Normal file
14
handler/admin.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"net/http"
|
||||
"trikotwaschliste/database"
|
||||
)
|
||||
|
||||
func AdminMainPage(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.HTML(http.StatusAccepted, "adminindex.html", database.DbAdminMainpage(pool))
|
||||
}
|
||||
}
|
@@ -25,6 +25,6 @@ func UploadName(pool *pgxpool.Pool) gin.HandlerFunc {
|
||||
|
||||
func Credits() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.HTML(http.StatusAccepted, "credits.html", gin.H{"version":"1.0"})
|
||||
c.HTML(http.StatusAccepted, "credits.html", gin.H{"version":"1.1"})
|
||||
}
|
||||
}
|
||||
|
56
html/admin/adminindex.html
Normal file
56
html/admin/adminindex.html
Normal file
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Trikotwaschliste - Admin</title>
|
||||
<link rel="stylesheet" type="text/css" href="/static/semantic.min.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{{template "navbaradmin"}}
|
||||
<div class="ui center">
|
||||
<h1 class="">Trikotwaschliste Admin</h1>
|
||||
<table class="ui celled table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Person</th>
|
||||
<th>Datum</th>
|
||||
<th>Waschperson</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ $items := .items}}
|
||||
{{ $persons := .persons}}
|
||||
{{range $item := $items}}
|
||||
<tr>
|
||||
<td>{{$item.Person}}</td>
|
||||
<td>{{$item.DateString}}</td>
|
||||
<td>
|
||||
<div class="center">
|
||||
<form class="ui form" action="/uploadname" method="POST">
|
||||
<input type="hidden" id="washid" name="washid" value="{{ $item.Id}}">
|
||||
<select name="names" id="names">
|
||||
<!--<option value="-1" selected disabled hidden>Choose here</option>-->
|
||||
{{range $person := $persons}}
|
||||
{{if eq $item.Washed $person.Id}}
|
||||
<option value="{{$person.Id}}" selected>{{$person.Name}}</option>
|
||||
{{else}}
|
||||
<option value="{{$person.Id}}">{{$person.Name}}</option>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</select>
|
||||
<input class="button" type="submit" value="Speichern">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@@ -5,6 +5,7 @@
|
||||
|
||||
<div class="right menu">
|
||||
<a href="/credits"><div class="item">Credits</div></a>
|
||||
<a href="/admin"><div class="item">Admin</div></a>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
10
html/static/navbaradmin.html
Normal file
10
html/static/navbaradmin.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{{define "navbaradmin"}}
|
||||
<div class="ui menu">
|
||||
<a href="/admin"><div class="header item">Trikotwaschliste Admin</div></a>
|
||||
|
||||
<div class="right menu">
|
||||
<a href="/credits"><div class="item">Credits</div></a>
|
||||
<a href="/"><div class="item">Startseite</div></a>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
@@ -15,10 +15,11 @@ func RoutesInit(router *gin.Engine, pool *pgxpool.Pool, config *models.Config) {
|
||||
router.GET("/persons", handler.ShowPersonsList(pool))
|
||||
|
||||
// Basic auth accounts
|
||||
//authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{
|
||||
//}))
|
||||
authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{
|
||||
config.ADMIN_NAME: config.ADMIN_PASSWORD,
|
||||
}))
|
||||
|
||||
// Basic auth routes
|
||||
|
||||
authorized.GET("/", handler.AdminMainPage(pool))
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user