Compare commits
No commits in common. "15675d5e6c5331f21052587fa4f1561aa33f5c2d" and "da77201a931386101b3a2a7877e6dd3729934035" have entirely different histories.
15675d5e6c
...
da77201a93
10
main.go
10
main.go
@ -17,8 +17,8 @@ func writeBriefing(ch chan *types.Briefing, db *db.DB) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var i, j int64
|
var i, j int64
|
||||||
i, j = 1, 1
|
|
||||||
|
|
||||||
|
i, j = 1, 1
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
cb := make(chan *types.Briefing)
|
cb := make(chan *types.Briefing)
|
||||||
|
|
||||||
@ -27,14 +27,8 @@ func main() {
|
|||||||
log.Fatalln(err)
|
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.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("/add-participant/", server.AddParticipant(&i))
|
||||||
mux.HandleFunc("/submit/", server.SubmitForm(cb, &i, &j))
|
mux.HandleFunc("/submit/", server.SubmitForm(cb, &i, &j))
|
||||||
|
|
||||||
|
@ -86,31 +86,6 @@ func (db *DB) WriteBriefing(b *types.Briefing) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) ReadAll() (*[]types.Briefing, error) {
|
|
||||||
bs := make([]types.Briefing, 0)
|
|
||||||
|
|
||||||
rows, err := db.Query("SELECT *" + " FROM " + db.Name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("*DB.ReadAll: db.Query(\"SELECT * FROM \"+db.Name): %v\n", err)
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
for rows.Next() {
|
|
||||||
b := new(types.Briefing)
|
|
||||||
p := new(types.Participant)
|
|
||||||
|
|
||||||
if err := rows.Scan(&p.ID, &b.FirstName, &b.LastName, &b.Date, &b.Time,
|
|
||||||
&b.State, &b.Location, &p.FirstName, &p.LastName, &p.Company); err != nil {
|
|
||||||
return nil, fmt.Errorf("*DB.ReadAll: db.Query(): %v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
b.Participants = append(b.Participants, *p)
|
|
||||||
bs = append(bs, *b)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *DB) ReadByName(name string) (*[]types.Briefing, error) {
|
func (db *DB) ReadByName(name string) (*[]types.Briefing, error) {
|
||||||
bs := make([]types.Briefing, 0)
|
bs := make([]types.Briefing, 0)
|
||||||
|
|
||||||
|
@ -8,22 +8,16 @@ import (
|
|||||||
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
"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 {
|
func DisplayForm(i *int64) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
template.Must(template.ParseFiles("templates/index.html", "templates/form.html")).Execute(w, i)
|
template.Must(template.ParseFiles("templates/index.html")).Execute(w, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddParticipant(i *int64) http.HandlerFunc {
|
func AddParticipant(i *int64) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
*i++
|
*i++
|
||||||
template.Must(template.ParseFiles("templates/form.html")).ExecuteTemplate(w, "participant", i)
|
template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,54 +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 }}
|
|
||||||
|
|
||||||
{{ 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>
|
|
||||||
|
|
||||||
<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="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="participants">
|
|
||||||
<button type="button" hx-post="/add-participant/" hx-target="#participants" hx-swap="beforeend" hx-trigger="click">
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{{ template "participant" . }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" hx-post="/submit/">Senden</button>
|
|
||||||
</form>
|
|
||||||
{{ end }}
|
|
@ -11,7 +11,57 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Sicherheitsunterweisung</h1>
|
<h1>Sicherheitsunterweisung</h1>
|
||||||
|
|
||||||
{{ template "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>
|
||||||
|
|
||||||
|
<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="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="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
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
<script src="/static/js/htmx.min.js" type="text/javascript"></script>
|
<script src="/static/js/htmx.min.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
|
12
templates/participant.html
Normal file
12
templates/participant.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{{ 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 }}
|
@ -1,39 +0,0 @@
|
|||||||
{{ 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