Instructor Form zum Laufen gebracht
This commit is contained in:
parent
b78e30d109
commit
d054b3644b
2
main.go
2
main.go
@ -36,7 +36,7 @@ func main() {
|
||||
mux.HandleFunc("/internal-login/", server.DisplayTable(db))
|
||||
mux.HandleFunc("/external-login/", server.DisplayParticipantForm(sessions))
|
||||
mux.HandleFunc("/search/", server.DisplaySearchResults(db))
|
||||
mux.HandleFunc("/new-briefing/", server.DisplayInstructorForm(sessionChan))
|
||||
mux.HandleFunc("/new-briefing/", server.DisplayInstructorForm(db, sessionChan))
|
||||
|
||||
go handleSessions(mux, db, sessions, sessionChan)
|
||||
|
||||
|
@ -291,10 +291,13 @@ func (db *DB) GetLastID(table string) (int, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (db *DB) GetInstructors() (*[]*types.Instructor, error) {
|
||||
func (db *DB) GetInstructors() ([]*types.Instructor, error) {
|
||||
rows, err := db.Query(`
|
||||
SELECT *
|
||||
FROM instructors
|
||||
ORDER BY
|
||||
last_name,
|
||||
first_name
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("*DB.GetInstructors: db.Query(): %v\n", err)
|
||||
@ -303,11 +306,11 @@ func (db *DB) GetInstructors() (*[]*types.Instructor, error) {
|
||||
instructors := make([]*types.Instructor, 0)
|
||||
for rows.Next() {
|
||||
instructor := new(types.Instructor)
|
||||
if err = rows.Scan(instructor); err != nil {
|
||||
if err = rows.Scan(&instructor.ID, &instructor.FirstName, &instructor.LastName, &instructor.PersonnelID); err != nil {
|
||||
return nil, fmt.Errorf("*DB.GetInstructors: rows.Scan(): %v\n", err)
|
||||
}
|
||||
instructors = append(instructors, instructor)
|
||||
}
|
||||
|
||||
return &instructors, nil
|
||||
return instructors, nil
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -34,13 +35,38 @@ func DisplaySearchResults(db *db.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func DisplayInstructorForm(cs chan<- *types.Session) http.HandlerFunc {
|
||||
func DisplayInstructorForm(db *db.DB, cs chan<- *types.Session) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
type option struct {
|
||||
ID int64
|
||||
String string
|
||||
}
|
||||
|
||||
type htmlData struct {
|
||||
SessionID uuid.UUID
|
||||
Options []option
|
||||
}
|
||||
|
||||
session := new(types.Session)
|
||||
session.ID = uuid.New()
|
||||
cs <- session
|
||||
|
||||
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", session.ID)
|
||||
instructors, err := db.GetInstructors()
|
||||
if err != nil {
|
||||
http.Error(w, "DisplayInstructorForm: db.GetInstructors(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
data := new(htmlData)
|
||||
data.SessionID = session.ID
|
||||
for _, instructor := range instructors {
|
||||
option := new(option)
|
||||
option.ID = instructor.ID
|
||||
option.String = instructor.LastName + ", " + instructor.FirstName + ": " + fmt.Sprint(instructor.PersonnelID)
|
||||
data.Options = append(data.Options, *option)
|
||||
}
|
||||
|
||||
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", data)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,10 @@ type Person struct {
|
||||
LastName string
|
||||
}
|
||||
|
||||
type Instructor Person
|
||||
type Instructor struct {
|
||||
Person
|
||||
PersonnelID int
|
||||
}
|
||||
|
||||
type Participant struct {
|
||||
Person
|
||||
|
@ -12,26 +12,32 @@
|
||||
{{ 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" />
|
||||
<label for="instructor">Unterweiser</label>
|
||||
<select id="instructor" name="instructor">
|
||||
{{ range .Options }}
|
||||
<option value="{{ .ID }}">{{ .String }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="location">
|
||||
<label for="location-input">Ort</label>
|
||||
<input type="text" name="location" id="location-input" />
|
||||
<label for="location">Ort</label>
|
||||
<input type="text" name="location" id="location" />
|
||||
</div>
|
||||
|
||||
<div id="document-name">
|
||||
<label for="document-name">Dokument</label>
|
||||
<input type="text" name="document-name" id="document-name" />
|
||||
</div>
|
||||
|
||||
<div id="state">
|
||||
<label for="state-input">Stand vom</label>
|
||||
<input type="date" name="state" id="state-input" />
|
||||
<label for="as-of">Stand vom</label>
|
||||
<input type="date" name="as-of" id="as-of" />
|
||||
</div>
|
||||
|
||||
{{ template "add-button" . }}
|
||||
|
||||
<button type="submit" hx-post="/submit-form/" hx-target="#content" hx-swap="innerHTML">
|
||||
<button type="submit" hx-post="/submit-form-{{ .SessionID }}/" hx-target="#content" hx-swap="innerHTML">
|
||||
OK
|
||||
</button>
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user