feat(display-attendies): finish ui

This commit is contained in:
nikurasu 2024-02-24 15:48:02 +01:00
parent cdd5e74693
commit c0f4455d05
Signed by: Nikurasu
GPG key ID: 9E7F14C03EF1F271
7 changed files with 85 additions and 40 deletions

View file

@ -1,6 +1,8 @@
package controller package controller
import ( import (
"fmt"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"ulmer-furs.de/pretix-proxy/v2/app/service" "ulmer-furs.de/pretix-proxy/v2/app/service"
) )
@ -19,3 +21,19 @@ func GetAttendiesByEventPublic(c *fiber.Ctx) error {
c.JSON(attendies) c.JSON(attendies)
return c.SendStatus(fiber.StatusOK) return c.SendStatus(fiber.StatusOK)
} }
func GetAttendiesByEventPublicTable(c *fiber.Ctx) error {
name := c.Params("name")
event, err := service.Get_db_event_by_event(name)
if err != nil {
return c.Status(fiber.ErrNotFound.Code).SendString("event not found")
}
attendies, err := service.GetAttendiesByEventPrivacy(event, false)
if err != nil {
return c.Status(fiber.ErrNotFound.Code).SendString("attendies not found")
}
return c.Render("app/views/index", fiber.Map{
"Title": fmt.Sprintf("%s Attendies", *event.Event),
"Attendies": attendies,
})
}

View file

@ -6,6 +6,9 @@ import (
) )
func PublicRoutes(app *fiber.App) { func PublicRoutes(app *fiber.App) {
ui := app.Group("/ui")
attendiesUi := ui.Group("/attendies")
attendiesUi.Get("/:name", controller.GetAttendiesByEventPublicTable)
apiv1 := app.Group("/api/v1/public") apiv1 := app.Group("/api/v1/public")
attendies := apiv1.Group("/attendies") attendies := apiv1.Group("/attendies")
webhooks := apiv1.Group("/webhooks") webhooks := apiv1.Group("/webhooks")

View file

@ -0,0 +1,35 @@
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
background-color: #151719;
}
main {
min-width: 60vw;
}
h1 {
color: #ffffff;
}
table {
border-collapse: collapse;
}
.tableHeading {
background-color: #fae4b9;
}
th, td {
border-style: hidden;
padding: 15px;
}
tbody>tr:nth-child(even) {
background-color: #f6f6f6;
}
tbody>tr:nth-child(odd) {
background-color: #e9e9e9;
}

View file

@ -4,14 +4,12 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Title}}</title> <title>{{.Title}}</title>
<link rel="stylesheet" href="/static/styles/style.css">
</head> </head>
<body> <body>
<main>
<h1>{{.Title}}</h1> <h1>{{.Title}}</h1>
<p>Events count: <span id="count">{{.Count}}</span></p>
<script>
counter = parseInt(document.getElementById("count").innerHTML)
console.log(counter + 1)
</script>
{{template "table" .}} {{template "table" .}}
</main>
</body> </body>
</html> </html>

View file

@ -1,36 +1,18 @@
{{define "table"}} {{define "table"}}
<table> <table>
<tr> <thead>
<tr class="tableHeading">
<th>Name</th> <th>Name</th>
<th>Organizer</th> <th>Role</th>
<th>Event</th>
<th>ItemIdBadge</th>
<th>ItemIdRestaurant</th>
<th>ItemIdParticipation</th>
<th>QuestionIdRole</th>
<th>QuestionIdName</th>
<th>OptionIdSuiter</th>
<th>OptionIdGuest</th>
<th>OptionIdSpotter</th>
<th>OptionIdPhotograph</th>
<th>OptionIdSpecialAnimal</th>
</tr> </tr>
{{range .Events}} </thead>
<tbody>
{{range .Attendies}}
<tr> <tr>
<td>{{.Name}}</td> <td>{{.Nickname}}</td>
<td>{{.Organizer}}</td> <td>{{.Role.Name}}</td>
<td>{{.Event}}</td>
<td>{{.ItemIdBadge}}</td>
<td>{{.ItemIdRestaurant}}</td>
<td>{{.ItemIdParticipation}}</td>
<td>{{.QuestionIdRole}}</td>
<td>{{.QuestionIdName}}</td>
<td>{{.OptionIdSuiter}}</td>
<td>{{.OptionIdGuest}}</td>
<td>{{.OptionIdSpotter}}</td>
<td>{{.OptionIdPhotograph}}</td>
<td>{{.OptionIdSpecialAnimal}}</td>
</tr> </tr>
{{end}} {{end}}
</tbody>
</table> </table>
{{end}} {{end}}

View file

@ -5,14 +5,20 @@ import (
"net/http" "net/http"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/template/html/v2" "github.com/gofiber/template/html/v2"
) )
var App *fiber.App var App *fiber.App
func SetupFiber(viewFS embed.FS) { func SetupFiber(viewFS embed.FS, staticFS embed.FS) {
engine := html.NewFileSystem(http.FS(viewFS), ".html") engine := html.NewFileSystem(http.FS(viewFS), ".html")
App = fiber.New(fiber.Config{ App = fiber.New(fiber.Config{
Views: engine, Views: engine,
}) })
App.Use("/static", filesystem.New(filesystem.Config{
Root: http.FS(staticFS),
PathPrefix: "app/static",
Browse: true,
}))
} }

View file

@ -12,12 +12,15 @@ import (
//go:embed app/views/* //go:embed app/views/*
var viewFS embed.FS var viewFS embed.FS
//go:embed app/static/*
var staticFS embed.FS
func main() { func main() {
config.LoadEnv() config.LoadEnv()
config.Connect() config.Connect()
config.SetupValidator() config.SetupValidator()
config.SetupMiddlewares() config.SetupMiddlewares()
config.SetupFiber(viewFS) config.SetupFiber(viewFS, staticFS)
config.SetupCors() config.SetupCors()
config.SetupHttp() config.SetupHttp()