HTML-Seiten modularer aufgebaut und table.html hinzugefügt
This commit is contained in:
parent
8ae3019b9c
commit
15675d5e6c
8
main.go
8
main.go
@ -27,8 +27,14 @@ func main() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
bs, err := db.ReadAll()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
mux.HandleFunc("/", server.DisplayForm(&i))
|
||||
// mux.HandleFunc("/", server.DisplayForm(&i))
|
||||
mux.HandleFunc("/", server.DisplayTable(bs))
|
||||
mux.HandleFunc("/add-participant/", server.AddParticipant(&i))
|
||||
mux.HandleFunc("/submit/", server.SubmitForm(cb, &i, &j))
|
||||
|
||||
|
@ -8,16 +8,22 @@ import (
|
||||
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
||||
)
|
||||
|
||||
func DisplayTable(bs *[]types.Briefing) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("templates/index.html", "templates/table.html")).Execute(w, bs)
|
||||
}
|
||||
}
|
||||
|
||||
func DisplayForm(i *int64) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("templates/form.html")).Execute(w, i)
|
||||
template.Must(template.ParseFiles("templates/index.html", "templates/form.html")).Execute(w, i)
|
||||
}
|
||||
}
|
||||
|
||||
func AddParticipant(i *int64) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
*i++
|
||||
template.Must(template.ParseFiles("templates/form.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i)
|
||||
template.Must(template.ParseFiles("templates/form.html")).ExecuteTemplate(w, "participant", i)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,69 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
{{ define "participant" }}
|
||||
<div id="participant-{{ . }}">
|
||||
<label for="participant-first-input-{{ . }}">Vorname</label>
|
||||
<input type="text" name="participant-first-{{ . }}" id="participant-first-input-{{ . }}" />
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<title>Sicherheitsunterweisung</title>
|
||||
</head>
|
||||
<label for="participant-last-input-{{ . }}">Nachname</label>
|
||||
<input type="text" name="participant-last-{{ . }}" id="participant-last-input-{{ . }}" />
|
||||
|
||||
<body>
|
||||
<h1>Sicherheitsunterweisung</h1>
|
||||
<label for="participant-company-input-{{ . }}">Firma</label>
|
||||
<input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" />
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<form>
|
||||
<div id="instructor">
|
||||
<label for="instructor-first-input">Unterweiser Vorname</label>
|
||||
<input type="text" name="instructor-first" id="instructor-first-input" />
|
||||
{{ define "content" }}
|
||||
<form>
|
||||
<div id="instructor">
|
||||
<label for="instructor-first-input">Unterweiser Vorname</label>
|
||||
<input type="text" name="instructor-first" id="instructor-first-input" />
|
||||
|
||||
<label for="instructor-last-input">Unterweiser Nachname</label>
|
||||
<input type="text" name="instructor-last" id="instructor-last-input" />
|
||||
</div>
|
||||
<label for="instructor-last-input">Unterweiser Nachname</label>
|
||||
<input type="text" name="instructor-last" id="instructor-last-input" />
|
||||
</div>
|
||||
|
||||
<div id="date">
|
||||
<label for="date-input">Datum</label>
|
||||
<input type="date" name="date" id="date-input" />
|
||||
</div>
|
||||
<div id="date">
|
||||
<label for="date-input">Datum</label>
|
||||
<input type="date" name="date" id="date-input" />
|
||||
</div>
|
||||
|
||||
<div id="time">
|
||||
<label for="time-input">Uhrzeit</label>
|
||||
<input type="time" name="time" id="time-input" />
|
||||
</div>
|
||||
<div id="time">
|
||||
<label for="time-input">Uhrzeit</label>
|
||||
<input type="time" name="time" id="time-input" />
|
||||
</div>
|
||||
|
||||
<div id="state">
|
||||
<label for="state-input">Stand vom</label>
|
||||
<input type="date" name="state" id="state-input" />
|
||||
</div>
|
||||
<div id="state">
|
||||
<label for="state-input">Stand vom</label>
|
||||
<input type="date" name="state" id="state-input" />
|
||||
</div>
|
||||
|
||||
<div id="location">
|
||||
<label for="location-input">Ort</label>
|
||||
<input type="text" name="location" id="location-input" />
|
||||
</div>
|
||||
<div id="location">
|
||||
<label for="location-input">Ort</label>
|
||||
<input type="text" name="location" id="location-input" />
|
||||
</div>
|
||||
|
||||
<div id="participants">
|
||||
<button type="button" hx-post="/add-participant/" hx-target="#participants" hx-swap="beforeend"
|
||||
hx-trigger="click">
|
||||
+
|
||||
</button>
|
||||
|
||||
<div id="participant-{{ . }}">
|
||||
<label for="participant-first-input-{{ . }}">Vorname</label>
|
||||
<input type="text" name="participant-first-{{ . }}" id="participant-first-input-{{ . }}" />
|
||||
|
||||
<label for="participant-last-input-{{ . }}">Nachname</label>
|
||||
<input type="text" name="participant-last-{{ . }}" id="participant-last-input-{{ . }}" />
|
||||
|
||||
<label for="participant-company-input-{{ . }}">Firma</label>
|
||||
<input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" hx-post="/submit/">
|
||||
Senden
|
||||
<div id="participants">
|
||||
<button type="button" hx-post="/add-participant/" hx-target="#participants" hx-swap="beforeend" hx-trigger="click">
|
||||
+
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<script src="/static/js/htmx.min.js" type="text/javascript"></script>
|
||||
</body>
|
||||
{{ template "participant" . }}
|
||||
</div>
|
||||
|
||||
</html>
|
||||
<button type="submit" hx-post="/submit/">Senden</button>
|
||||
</form>
|
||||
{{ end }}
|
||||
|
19
templates/index.html
Normal file
19
templates/index.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<title>Sicherheitsunterweisung</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Sicherheitsunterweisung</h1>
|
||||
|
||||
{{ template "content" . }}
|
||||
|
||||
<script src="/static/js/htmx.min.js" type="text/javascript"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,12 +0,0 @@
|
||||
{{ define "participant" }}
|
||||
<div id="participant-{{ . }}">
|
||||
<label for="participant-first-input-{{ . }}">Vorname</label>
|
||||
<input type="text" name="participant-first-{{ . }}" id="participant-first-input-{{ . }}" />
|
||||
|
||||
<label for="participant-last-input-{{ . }}">Nachname</label>
|
||||
<input type="text" name="participant-last-{{ . }}" id="participant-last-input-{{ . }}" />
|
||||
|
||||
<label for="participant-company-input-{{ . }}">Firma</label>
|
||||
<input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" />
|
||||
</div>
|
||||
{{ end }}
|
39
templates/table.html
Normal file
39
templates/table.html
Normal file
@ -0,0 +1,39 @@
|
||||
{{ define "row" }}
|
||||
<tr>
|
||||
<td>{{ .FirstName }}</td>
|
||||
<td>{{ .LastName }}</td>
|
||||
<td>{{ .Date }}</td>
|
||||
<td>{{ .Time }}</td>
|
||||
<td>{{ .State }}</td>
|
||||
<td>{{ .Location }}</td>
|
||||
{{ range .Participants }}
|
||||
<td>{{ .FirstName }}</td>
|
||||
<td>{{ .LastName }}</td>
|
||||
<td>{{ .Company }}</td>
|
||||
{{ end }}
|
||||
</tr>
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
<form>
|
||||
<label for="search-input">Suche</label>
|
||||
<input type="text" name="search" id="search-input" />
|
||||
<button type="submit" hx-post="" hx-target="" hx-swap="">Suchen</button>
|
||||
</form>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th colspan="2">Name Unterweiser</th>
|
||||
<th>Datum</th>
|
||||
<th>Uhrzeit</th>
|
||||
<th>Stand</th>
|
||||
<th>Ort</th>
|
||||
<th colspan="2">Name Teilnehmer</th>
|
||||
<th>Firma</th>
|
||||
</tr>
|
||||
|
||||
{{ range . }}
|
||||
{{ template "row" . }}
|
||||
{{ end }}
|
||||
</table>
|
||||
{{ end }}
|
Loading…
x
Reference in New Issue
Block a user