Compare commits
5 Commits
startseite
...
82870e100f
Author | SHA1 | Date | |
---|---|---|---|
82870e100f | |||
2b119f6752 | |||
c04932383e | |||
8ea0c2964a | |||
519dc82023 |
2
main.go
2
main.go
@ -20,10 +20,10 @@ func main() {
|
||||
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
mux.HandleFunc("/", server.DisplayTable(db))
|
||||
mux.HandleFunc("/submit/", server.SubmitForm(db, &i, &j))
|
||||
mux.HandleFunc("/search/", server.DisplayResults(db))
|
||||
mux.HandleFunc("/new-briefing/", server.DisplayForm(&i))
|
||||
mux.HandleFunc("/add-participant/", server.AddParticipant(&i))
|
||||
mux.HandleFunc("/submit-form/", server.SubmitForm(db, &i, &j))
|
||||
|
||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||
}
|
||||
|
@ -37,6 +37,12 @@ func getCredentials() (string, string, error) {
|
||||
return strings.TrimSpace(user), strings.TrimSpace(pass), nil
|
||||
}
|
||||
|
||||
func reverseOrder(bs *[]types.Briefing) {
|
||||
for i, j := 0, len(*bs)-1; i < j; i, j = i+1, j-1 {
|
||||
(*bs)[i], (*bs)[j] = (*bs)[j], (*bs)[i]
|
||||
}
|
||||
}
|
||||
|
||||
func Open(dbName string) (*DB, error) {
|
||||
var err error
|
||||
db := new(DB)
|
||||
@ -63,18 +69,18 @@ func Open(dbName string) (*DB, error) {
|
||||
func (db *DB) WriteBriefing(b *types.Briefing) error {
|
||||
for i := 0; i < len(b.Participants); i++ {
|
||||
result, err := db.Exec("INSERT INTO "+db.Name+" (instructor_first,"+
|
||||
"instructor_last, date, time, state, location, participant_first,"+
|
||||
"participant_last, company) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
" instructor_last, date, time, state, location, participant_first,"+
|
||||
" participant_last, company) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
b.FirstName, b.LastName, b.Date, b.Time, b.State, b.Location,
|
||||
b.Participants[i].FirstName, b.Participants[i].LastName,
|
||||
b.Participants[i].Company)
|
||||
if err != nil {
|
||||
return fmt.Errorf("*DB.WriteBriefing: db.Exec(\"INSERT INTO"+
|
||||
"\"+db.Name+\" (instructor_first, instructor_last, date, time, state,"+
|
||||
"location, participant_first, participant_last, company) VALUES (?, ?,"+
|
||||
"?, ?, ?, ?, ?, ?, ?)\", b.FirstName, b.LastName, b.Date, b.Time,"+
|
||||
"b.State, b.Location, b.Participants[i].FirstName,"+
|
||||
"b.Participants[i].LastName, b.Participants[i].Company): %v\n", err)
|
||||
" \"+db.Name+\" (instructor_first, instructor_last, date, time, state,"+
|
||||
" location, participant_first, participant_last, company) VALUES (?, ?,"+
|
||||
" ?, ?, ?, ?, ?, ?, ?)\", b.FirstName, b.LastName, b.Date, b.Time,"+
|
||||
" b.State, b.Location, b.Participants[i].FirstName,"+
|
||||
" b.Participants[i].LastName, b.Participants[i].Company): %v\n", err)
|
||||
}
|
||||
|
||||
_, err = result.LastInsertId()
|
||||
@ -108,6 +114,7 @@ func (db *DB) ReadAll() (*[]types.Briefing, error) {
|
||||
bs = append(bs, *b)
|
||||
}
|
||||
|
||||
reverseOrder(&bs)
|
||||
return &bs, nil
|
||||
}
|
||||
|
||||
@ -145,5 +152,6 @@ func (db *DB) ReadByName(name string) (*[]types.Briefing, error) {
|
||||
bs = append(bs, *b)
|
||||
}
|
||||
|
||||
reverseOrder(&bs)
|
||||
return &bs, nil
|
||||
}
|
||||
|
@ -49,7 +49,7 @@
|
||||
{{ template "participant" . }}
|
||||
</div>
|
||||
|
||||
<button type="submit" hx-post="/submit/" hx-target="#content" hx-swap="innerHTML">
|
||||
<button type="submit" hx-post="/submit-form/" hx-target="#content" hx-swap="innerHTML">
|
||||
Senden
|
||||
</button>
|
||||
</form>
|
||||
|
14
templates/question.html
Normal file
14
templates/question.html
Normal file
@ -0,0 +1,14 @@
|
||||
{{ define "question" }}
|
||||
<div id="question-{{ .QuestionNumber }}">
|
||||
<h2>Frage {{ .QuestionNumber }}
|
||||
<p>{{ .Question }}</p
|
||||
<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 }}
|
@ -19,10 +19,8 @@
|
||||
{{ define "content" }}
|
||||
<form>
|
||||
<label for="search-input">Suche</label>
|
||||
<input type="text" name="search" id="search-input" />
|
||||
<button type="submit" hx-post="/search/" hx-target="#results" hx-swap="innerHTML">
|
||||
Suchen
|
||||
</button>
|
||||
<input type="text" name="search" id="search-input" hx-post="/search/" hx-target="#results" hx-swap="innerHTML"
|
||||
hx-trigger="keyup changed delay:200ms" />
|
||||
</form>
|
||||
|
||||
<form>
|
||||
@ -34,12 +32,12 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2">Name Unterweiser</th>
|
||||
<th colspan="2">Unterweiser</th>
|
||||
<th>Datum</th>
|
||||
<th>Uhrzeit</th>
|
||||
<th>Stand</th>
|
||||
<th>Ort</th>
|
||||
<th colspan="2">Name Teilnehmer</th>
|
||||
<th colspan="2">Teilnehmer</th>
|
||||
<th>Firma</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
Reference in New Issue
Block a user