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"
|
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DisplayTable(db *db.DB) http.HandlerFunc {
|
func displayTable(w http.ResponseWriter, db *db.DB) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
bs, err := db.GetAllOverviewTableData()
|
bs, err := db.GetAllOverviewTableData()
|
||||||
if err != nil {
|
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)
|
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 {
|
func AddParticipant(s *types.Session) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
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 {
|
if err != nil {
|
||||||
http.Error(w, "AddParticipant: generateUUID(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
http.Error(w, "AddParticipant: generateUUID(): "+fmt.Sprint(err), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Logins = append(s.Logins, login)
|
s.Logins = append(s.Logins, data.Login)
|
||||||
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "new", 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 {
|
func SubmitBriefingForm(s *types.Session, db *db.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
briefing := new(types.Briefing)
|
briefing := new(types.Briefing)
|
||||||
|
var err error
|
||||||
// TODO: Dropdownmenü
|
|
||||||
// instructorFirstName := r.PostFormValue("instructor-first")
|
|
||||||
// instructorLastName := r.PostFormValue("instructor-last")
|
|
||||||
|
|
||||||
briefing.Date = now.Format("2006-01-02")
|
briefing.Date = now.Format("2006-01-02")
|
||||||
briefing.Time = now.Format("15:04:05")
|
briefing.Time = now.Format("15:04:05")
|
||||||
briefing.Location = r.PostFormValue("location")
|
briefing.Location = r.PostFormValue("location")
|
||||||
briefing.DocumentName = r.PostFormValue("document") // TODO: in HTML einfügen
|
briefing.DocumentName = r.PostFormValue("document-name")
|
||||||
briefing.AsOf = r.PostFormValue("state") // TODO: Umbenennen
|
briefing.AsOf = r.PostFormValue("as-of")
|
||||||
// briefing.InstructorID = r.PostFormValue("instructor-id") // TODO: aus Dropdown holen
|
|
||||||
|
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.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 {
|
func DisplayParticipantForm(ss []*types.Session) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
type data struct {
|
type httpData struct {
|
||||||
SessionID uuid.UUID
|
SessionID uuid.UUID
|
||||||
UUID string
|
UUID string
|
||||||
}
|
}
|
||||||
|
|
||||||
if loginIsCorrect(r.PostFormValue("login"), ss) {
|
if loginIsCorrect(r.PostFormValue("login"), ss) {
|
||||||
data := new(data)
|
data := new(httpData)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
data.UUID, err = generateUUID()
|
data.UUID, err = generateUUID()
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
{{ define "add-button" }}
|
{{ define "add-buttons" }}
|
||||||
<button type="button" hx-post="/add-participant/" hx-target="this" hx-swap="outerHTML">
|
<div id="briefing-buttons">
|
||||||
|
<button type="button" hx-post="/add-participant-{{ .SessionID }}/" hx-target="#briefing-buttons" hx-swap="outerHTML">
|
||||||
Neuer Teilnehmer
|
Neuer Teilnehmer
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
<button type="submit" hx-post="/submit-form-{{ .SessionID }}/" hx-target="#content" hx-swap="innerHTML">
|
||||||
|
Fertig
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "new" }}
|
{{ define "new" }}
|
||||||
<span>{{ . }}</span>
|
{{ template "add-buttons" . }}
|
||||||
{{ template "add-button" . }}
|
<p>{{ .Login }}</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
@ -35,10 +41,6 @@
|
|||||||
<input type="date" name="as-of" id="as-of" />
|
<input type="date" name="as-of" id="as-of" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ template "add-button" . }}
|
{{ template "add-buttons" . }}
|
||||||
|
|
||||||
<button type="submit" hx-post="/submit-form-{{ .SessionID }}/" hx-target="#content" hx-swap="innerHTML">
|
|
||||||
OK
|
|
||||||
</button>
|
|
||||||
</form>
|
</form>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user