diff --git a/main.go b/main.go index a36e40b..95a3736 100644 --- a/main.go +++ b/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)) diff --git a/packages/server/server.go b/packages/server/server.go index 28ae6b1..0059a0a 100644 --- a/packages/server/server.go +++ b/packages/server/server.go @@ -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) } } diff --git a/templates/form.html b/templates/form.html index 452bf83..2ef2f40 100644 --- a/templates/form.html +++ b/templates/form.html @@ -1,69 +1,54 @@ - - +{{ define "participant" }} +
+ + - - - - - Sicherheitsunterweisung - + + - -

Sicherheitsunterweisung

+ + +
+{{ end }} -
-
- - +{{ define "content" }} + +
+ + - - -
+ + +
-
- - -
+
+ + +
-
- - -
+
+ + +
-
- - -
+
+ + +
-
- - -
+
+ + +
-
- - -
- - - - - - - - -
-
- - -
- - + {{ template "participant" . }} + - + + +{{ end }} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..3ec42b0 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,19 @@ + + + + + + + + Sicherheitsunterweisung + + + +

Sicherheitsunterweisung

+ + {{ template "content" . }} + + + + + diff --git a/templates/participant.html b/templates/participant.html deleted file mode 100644 index 9ed45a6..0000000 --- a/templates/participant.html +++ /dev/null @@ -1,12 +0,0 @@ -{{ define "participant" }} -
- - - - - - - - -
-{{ end }} diff --git a/templates/table.html b/templates/table.html new file mode 100644 index 0000000..3398dbc --- /dev/null +++ b/templates/table.html @@ -0,0 +1,39 @@ +{{ define "row" }} + + {{ .FirstName }} + {{ .LastName }} + {{ .Date }} + {{ .Time }} + {{ .State }} + {{ .Location }} + {{ range .Participants }} + {{ .FirstName }} + {{ .LastName }} + {{ .Company }} + {{ end }} + +{{ end }} + +{{ define "content" }} +
+ + + +
+ + + + + + + + + + + + + {{ range . }} + {{ template "row" . }} + {{ end }} +
Name UnterweiserDatumUhrzeitStandOrtName TeilnehmerFirma
+{{ end }}