Kleine Änderungen für Sessions
This commit is contained in:
parent
d054b3644b
commit
aded71394d
@ -15,13 +15,17 @@ import (
|
||||
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
||||
)
|
||||
|
||||
func DisplayTable(db *db.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
func displayTable(w http.ResponseWriter, db *db.DB) {
|
||||
bs, err := db.GetAllOverviewTableData()
|
||||
if err != nil {
|
||||
http.Error(w, "DisplayTable: *DB.GetAllOverviewTableData(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
||||
http.Error(w, "displayTable: *DB.GetAllOverviewTableData(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
||||
}
|
||||
template.Must(template.ParseFiles("templates/table.html")).ExecuteTemplate(w, "content", bs)
|
||||
}
|
||||
|
||||
func DisplayTable(db *db.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
displayTable(w, db)
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,36 +86,53 @@ func generateUUID() (string, error) {
|
||||
|
||||
func AddParticipant(s *types.Session) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
login, err := generateUUID()
|
||||
type httpData struct {
|
||||
SessionID uuid.UUID
|
||||
Login string
|
||||
}
|
||||
|
||||
data := new(httpData)
|
||||
var err error
|
||||
|
||||
data.SessionID = s.ID
|
||||
data.Login, err = generateUUID()
|
||||
if err != nil {
|
||||
http.Error(w, "AddParticipant: generateUUID(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
s.Logins = append(s.Logins, login)
|
||||
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "new", login)
|
||||
s.Logins = append(s.Logins, data.Login)
|
||||
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "new", data)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Hier weiter machen, irgendwie die b.ID herausgeben,
|
||||
// am besten hier auch die p.IDs rausgeben, damit diese später verknüpft werden können
|
||||
func SubmitBriefingForm(s *types.Session, db *db.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
now := time.Now()
|
||||
briefing := new(types.Briefing)
|
||||
|
||||
// TODO: Dropdownmenü
|
||||
// instructorFirstName := r.PostFormValue("instructor-first")
|
||||
// instructorLastName := r.PostFormValue("instructor-last")
|
||||
var err error
|
||||
|
||||
briefing.Date = now.Format("2006-01-02")
|
||||
briefing.Time = now.Format("15:04:05")
|
||||
briefing.Location = r.PostFormValue("location")
|
||||
briefing.DocumentName = r.PostFormValue("document") // TODO: in HTML einfügen
|
||||
briefing.AsOf = r.PostFormValue("state") // TODO: Umbenennen
|
||||
// briefing.InstructorID = r.PostFormValue("instructor-id") // TODO: aus Dropdown holen
|
||||
briefing.DocumentName = r.PostFormValue("document-name")
|
||||
briefing.AsOf = r.PostFormValue("as-of")
|
||||
|
||||
briefing.InstructorID, err = strconv.ParseInt(r.PostFormValue("instructor"), 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "SubmitBriefingForm: strconv.ParseInt(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
err = db.WriteBriefing(briefing)
|
||||
if err != nil {
|
||||
http.Error(w, "SubmitBriefingForm: db.WriteBriefing(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
db.WriteBriefing(briefing)
|
||||
s.BriefingID = briefing.ID
|
||||
s.InstructorID = briefing.InstructorID
|
||||
|
||||
displayTable(w, db)
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,13 +163,13 @@ func newParticipant(l string) (*types.Participant, error) {
|
||||
|
||||
func DisplayParticipantForm(ss []*types.Session) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
type data struct {
|
||||
type httpData struct {
|
||||
SessionID uuid.UUID
|
||||
UUID string
|
||||
}
|
||||
|
||||
if loginIsCorrect(r.PostFormValue("login"), ss) {
|
||||
data := new(data)
|
||||
data := new(httpData)
|
||||
var err error
|
||||
|
||||
data.UUID, err = generateUUID()
|
||||
|
@ -1,12 +1,18 @@
|
||||
{{ define "add-button" }}
|
||||
<button type="button" hx-post="/add-participant/" hx-target="this" hx-swap="outerHTML">
|
||||
{{ define "add-buttons" }}
|
||||
<div id="briefing-buttons">
|
||||
<button type="button" hx-post="/add-participant-{{ .SessionID }}/" hx-target="#briefing-buttons" hx-swap="outerHTML">
|
||||
Neuer Teilnehmer
|
||||
</button>
|
||||
</button>
|
||||
|
||||
<button type="submit" hx-post="/submit-form-{{ .SessionID }}/" hx-target="#content" hx-swap="innerHTML">
|
||||
Fertig
|
||||
</button>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{ define "new" }}
|
||||
<span>{{ . }}</span>
|
||||
{{ template "add-button" . }}
|
||||
{{ template "add-buttons" . }}
|
||||
<p>{{ .Login }}</p>
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
@ -35,10 +41,6 @@
|
||||
<input type="date" name="as-of" id="as-of" />
|
||||
</div>
|
||||
|
||||
{{ template "add-button" . }}
|
||||
|
||||
<button type="submit" hx-post="/submit-form-{{ .SessionID }}/" hx-target="#content" hx-swap="innerHTML">
|
||||
OK
|
||||
</button>
|
||||
{{ template "add-buttons" . }}
|
||||
</form>
|
||||
{{ end }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user