From c0f4455d05758347090596715a6ce5f9fe0bc291 Mon Sep 17 00:00:00 2001 From: nikurasu Date: Sat, 24 Feb 2024 15:48:02 +0100 Subject: [PATCH] feat(display-attendies): finish ui --- src/app/controller/attendies_controller.go | 18 +++++++++ src/app/routes/public_routes.go | 3 ++ src/app/static/styles/style.css | 35 +++++++++++++++++ src/app/views/index.html | 12 +++--- src/app/views/table.html | 44 +++++++--------------- src/config/fiber.go | 8 +++- src/main.go | 5 ++- 7 files changed, 85 insertions(+), 40 deletions(-) create mode 100644 src/app/static/styles/style.css diff --git a/src/app/controller/attendies_controller.go b/src/app/controller/attendies_controller.go index 8b8fb26..4281d29 100644 --- a/src/app/controller/attendies_controller.go +++ b/src/app/controller/attendies_controller.go @@ -1,6 +1,8 @@ package controller import ( + "fmt" + "github.com/gofiber/fiber/v2" "ulmer-furs.de/pretix-proxy/v2/app/service" ) @@ -19,3 +21,19 @@ func GetAttendiesByEventPublic(c *fiber.Ctx) error { c.JSON(attendies) 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, + }) +} diff --git a/src/app/routes/public_routes.go b/src/app/routes/public_routes.go index f389766..ef263d5 100644 --- a/src/app/routes/public_routes.go +++ b/src/app/routes/public_routes.go @@ -6,6 +6,9 @@ import ( ) func PublicRoutes(app *fiber.App) { + ui := app.Group("/ui") + attendiesUi := ui.Group("/attendies") + attendiesUi.Get("/:name", controller.GetAttendiesByEventPublicTable) apiv1 := app.Group("/api/v1/public") attendies := apiv1.Group("/attendies") webhooks := apiv1.Group("/webhooks") diff --git a/src/app/static/styles/style.css b/src/app/static/styles/style.css new file mode 100644 index 0000000..8db6b2b --- /dev/null +++ b/src/app/static/styles/style.css @@ -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; +} \ No newline at end of file diff --git a/src/app/views/index.html b/src/app/views/index.html index 2121800..a411dfa 100644 --- a/src/app/views/index.html +++ b/src/app/views/index.html @@ -4,14 +4,12 @@ {{.Title}} + -

{{.Title}}

-

Events count: {{.Count}}

- - {{template "table" .}} +
+

{{.Title}}

+ {{template "table" .}} +
\ No newline at end of file diff --git a/src/app/views/table.html b/src/app/views/table.html index a57dce2..109cdd5 100644 --- a/src/app/views/table.html +++ b/src/app/views/table.html @@ -1,36 +1,18 @@ {{define "table"}} - - - - - - - - - - - - - - - - {{range .Events}} - - - - - - - - - - - - - - + + + + - {{end}} + + + {{range .Attendies}} + + + + + {{end}} +
NameOrganizerEventItemIdBadgeItemIdRestaurantItemIdParticipationQuestionIdRoleQuestionIdNameOptionIdSuiterOptionIdGuestOptionIdSpotterOptionIdPhotographOptionIdSpecialAnimal
{{.Name}}{{.Organizer}}{{.Event}}{{.ItemIdBadge}}{{.ItemIdRestaurant}}{{.ItemIdParticipation}}{{.QuestionIdRole}}{{.QuestionIdName}}{{.OptionIdSuiter}}{{.OptionIdGuest}}{{.OptionIdSpotter}}{{.OptionIdPhotograph}}{{.OptionIdSpecialAnimal}}
NameRole
{{.Nickname}}{{.Role.Name}}
{{end}} \ No newline at end of file diff --git a/src/config/fiber.go b/src/config/fiber.go index 0766314..0f4fc68 100644 --- a/src/config/fiber.go +++ b/src/config/fiber.go @@ -5,14 +5,20 @@ import ( "net/http" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/filesystem" "github.com/gofiber/template/html/v2" ) var App *fiber.App -func SetupFiber(viewFS embed.FS) { +func SetupFiber(viewFS embed.FS, staticFS embed.FS) { engine := html.NewFileSystem(http.FS(viewFS), ".html") App = fiber.New(fiber.Config{ Views: engine, }) + App.Use("/static", filesystem.New(filesystem.Config{ + Root: http.FS(staticFS), + PathPrefix: "app/static", + Browse: true, + })) } diff --git a/src/main.go b/src/main.go index 20db0d3..7fcc24d 100644 --- a/src/main.go +++ b/src/main.go @@ -12,12 +12,15 @@ import ( //go:embed app/views/* var viewFS embed.FS +//go:embed app/static/* +var staticFS embed.FS + func main() { config.LoadEnv() config.Connect() config.SetupValidator() config.SetupMiddlewares() - config.SetupFiber(viewFS) + config.SetupFiber(viewFS, staticFS) config.SetupCors() config.SetupHttp()