frontend: fix bugs according to monsterTable
This commit is contained in:
parent
b82e138c4d
commit
309ade3e72
4 changed files with 13 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ddServer/model"
|
||||||
"embed"
|
"embed"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -8,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// MainHandler
|
// MainHandler
|
||||||
func MainHandler(content embed.FS) http.HandlerFunc {
|
func MainHandler(content embed.FS, monsters *[]model.Monster) http.HandlerFunc {
|
||||||
log.Print("MainHandler called")
|
log.Print("MainHandler called")
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := template.ParseFS(content, "templates/main.html", "templates/monsterForm.html", "templates/monster.html", "templates/monsterTable.html")
|
tmpl, err := template.ParseFS(content, "templates/main.html", "templates/monsterForm.html", "templates/monster.html", "templates/monsterTable.html")
|
||||||
|
|
@ -17,8 +18,12 @@ func MainHandler(content embed.FS) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
|
||||||
err = tmpl.ExecuteTemplate(w, "main", map[string]interface{}{
|
err = tmpl.ExecuteTemplate(w, "main", map[string]interface{}{
|
||||||
"Title": "Dungeons & Dragons Monster Generator",
|
"Title": "Dungeons & Dragons Monster Generator",
|
||||||
|
"Monsters": *monsters,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Template execution error: %v\n", err)
|
log.Printf("Template execution error: %v\n", err)
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -28,7 +28,7 @@ func main() {
|
||||||
http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename))
|
http.HandleFunc("/submit", handlers.SubmitHandler(content, &chars, &Monsters, filename))
|
||||||
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.FS(content))))
|
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.FS(content))))
|
||||||
http.HandleFunc("/addMonster", handlers.AddMonster(&Monsters))
|
http.HandleFunc("/addMonster", handlers.AddMonster(&Monsters))
|
||||||
http.HandleFunc("/main", handlers.MainHandler(content))
|
http.HandleFunc("/main", handlers.MainHandler(content, &Monsters))
|
||||||
http.HandleFunc("/about", handlers.AboutHandler(content))
|
http.HandleFunc("/about", handlers.AboutHandler(content))
|
||||||
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
http.HandleFunc("/contact", handlers.ContactHandler(content))
|
||||||
http.HandleFunc("/monsterTable", handlers.MonsterTableHandler(content, &Monsters))
|
http.HandleFunc("/monsterTable", handlers.MonsterTableHandler(content, &Monsters))
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,15 @@
|
||||||
|
|
||||||
<div id="navbarBasicExample" class="navbar-menu">
|
<div id="navbarBasicExample" class="navbar-menu">
|
||||||
<div class="navbar-start">
|
<div class="navbar-start">
|
||||||
<a href="/" class="navbar-item" hx-get="/main" hx-target="#main-content">
|
<a href="/" class="navbar-item" hx-get="/main" hx-target="#main-content" hx-boost="true">
|
||||||
Dungeons & Dragons
|
Dungeons & Dragons
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/about" class="navbar-item" hx-get="/about" hx-target="#main-content">
|
<a href="/about" class="navbar-item" hx-get="/about" hx-target="#main-content" hx-boost="true">
|
||||||
About
|
About
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="/contact" class="navbar-item" hx-get="/contact" hx-target="#main-content">
|
<a href="/contact" class="navbar-item" hx-get="/contact" hx-target="#main-content" hx-boost="true">
|
||||||
Contact
|
Contact
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<p class="title is-4">Monster Form</p>
|
<p class="title is-4">Monster Form</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<form action="/submit" method="post" class="">
|
<form hx-boost="true" action="/submit" method="post" class="">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<td><label for="filename">Filename:</label></td>
|
<td><label for="filename">Filename:</label></td>
|
||||||
<div class="control"><input type="text" name="filename" required placeholder="Dateiname"
|
<div class="control"><input type="text" name="filename" required placeholder="Dateiname"
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button type="button" hx-post="/addMonster" hx-trigger="click" hx-target="#monster-table"
|
<button type="button" hx-post="/addMonster" hx-trigger="click" hx-target="#monster-table"
|
||||||
hx-swap="outerHTML" class="button is-info">Add
|
hx-swap="outerHTML" class="button is-info" hx-boost="true">Add
|
||||||
Monster</button>
|
Monster</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue