Compare commits
3 Commits
b4d453b108
...
tailwind_c
Author | SHA1 | Date | |
---|---|---|---|
408fb2bbc2 | |||
59e1016123 | |||
3cfcb721e8 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@ tmp
|
|||||||
test.sql
|
test.sql
|
||||||
static/test.jpg
|
static/test.jpg
|
||||||
static/test.mp4
|
static/test.mp4
|
||||||
|
node_modules
|
||||||
|
static/css/output.css
|
||||||
|
package.json
|
||||||
|
package-lock.json
|
||||||
|
@ -24,11 +24,11 @@ import (
|
|||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type briefing struct {
|
type Briefing struct {
|
||||||
*data.Briefing
|
*data.Briefing
|
||||||
participants []*participant
|
UUID uuid.UUID
|
||||||
questions []data.Question
|
Participants []*Participant
|
||||||
uuid uuid.UUID
|
Questions []data.Question
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateLogin() (string, error) {
|
func generateLogin() (string, error) {
|
||||||
@ -41,33 +41,33 @@ func generateLogin() (string, error) {
|
|||||||
return hex.EncodeToString(bs), nil
|
return hex.EncodeToString(bs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *briefing) handleNewParticipant(cp chan<- *participant) http.HandlerFunc {
|
func (b *Briefing) handleNewParticipant(cp chan<- *Participant) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
participant := participant{
|
participant := Participant{
|
||||||
Participant: new(data.Participant),
|
Participant: new(data.Participant),
|
||||||
numberIncorrect: -1,
|
NoIncorrect: -1,
|
||||||
allowRetry: false,
|
AllowRetry: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
participant.login, err = generateLogin()
|
participant.Login, err = generateLogin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
b.participants = append(b.participants, &participant)
|
b.Participants = append(b.Participants, &participant)
|
||||||
cp <- &participant
|
cp <- &participant
|
||||||
|
|
||||||
data := participantHTMLData{
|
data := participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: participant,
|
Participant: Participant{Login: participant.Login},
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "new", data)
|
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "new", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *briefing) handleBriefingForm(db *data.DB, s *Session) http.HandlerFunc {
|
func (b *Briefing) handleBriefingForm(db *data.DB, s *Session) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
b.DateTime = time.Now().Format("2006-01-02 15:04:05")
|
b.DateTime = time.Now().Format("2006-01-02 15:04:05")
|
||||||
b.Location = r.PostFormValue("location")
|
b.Location = r.PostFormValue("location")
|
||||||
@ -81,13 +81,13 @@ func (b *briefing) handleBriefingForm(db *data.DB, s *Session) http.HandlerFunc
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := summaryHTMLData{
|
data := summaryHTMLData{
|
||||||
sessionID: s.uuid,
|
SessionID: s.UUID,
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participantsData: make([]participantHTMLData, len(b.participants)),
|
ParticipantsData: make([]participantHTMLData, len(b.Participants)),
|
||||||
}
|
}
|
||||||
for i, p := range b.participants {
|
for i, p := range b.Participants {
|
||||||
data.participantsData[i].briefingID = b.uuid
|
data.ParticipantsData[i].BriefingID = b.UUID
|
||||||
data.participantsData[i].participant = *p
|
data.ParticipantsData[i].Participant = *p
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/summary.html")).ExecuteTemplate(w, "content", data)
|
template.Must(template.ParseFiles("templates/summary.html")).ExecuteTemplate(w, "content", data)
|
||||||
|
@ -17,41 +17,41 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type tableHTMLData struct {
|
type tableHTMLData struct {
|
||||||
otd []data.OverviewTableData
|
OTD []data.OverviewTableData
|
||||||
sessionID uuid.UUID
|
SessionID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type participantHTMLData struct {
|
type participantHTMLData struct {
|
||||||
participant
|
Participant
|
||||||
briefingID uuid.UUID
|
BriefingID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type questionHTMLData struct {
|
type questionHTMLData struct {
|
||||||
question data.Question
|
Question data.Question
|
||||||
participantHTMLData
|
participantHTMLData
|
||||||
questionID int64
|
QuestionID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type resultAnswer struct {
|
type resultAnswer struct {
|
||||||
text string
|
Text string
|
||||||
correct bool
|
Correct bool
|
||||||
chosen bool
|
Chosen bool
|
||||||
isImage bool // TODO: relocate to sessionStructs if possible
|
IsImage bool // TODO: relocate to sessionStructs if possible
|
||||||
id int64
|
ID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type resultQuestion struct {
|
type resultQuestion struct {
|
||||||
text string
|
Text string
|
||||||
answers []resultAnswer
|
Answers []resultAnswer
|
||||||
}
|
}
|
||||||
|
|
||||||
type resultHTMLData struct {
|
type resultHTMLData struct {
|
||||||
questions []resultQuestion
|
Questions []resultQuestion
|
||||||
participantHTMLData
|
participantHTMLData
|
||||||
}
|
}
|
||||||
|
|
||||||
type summaryHTMLData struct {
|
type summaryHTMLData struct {
|
||||||
participantsData []participantHTMLData
|
ParticipantsData []participantHTMLData
|
||||||
sessionID uuid.UUID
|
SessionID uuid.UUID
|
||||||
briefingID uuid.UUID
|
BriefingID uuid.UUID
|
||||||
}
|
}
|
||||||
|
@ -21,19 +21,6 @@ import (
|
|||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
func findCorrectLogin(l string, ss *[]*Session) (*briefing, *participant, bool) {
|
|
||||||
for _, s := range *ss {
|
|
||||||
for _, b := range s.briefings {
|
|
||||||
for _, p := range b.participants {
|
|
||||||
if l == p.login {
|
|
||||||
return b, p, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.HandlerFunc {
|
func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
instructors, err := db.GetInstructors()
|
instructors, err := db.GetInstructors()
|
||||||
@ -45,15 +32,15 @@ func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.H
|
|||||||
for _, i := range instructors {
|
for _, i := range instructors {
|
||||||
if r.PostFormValue("login") == fmt.Sprint(i.ID) {
|
if r.PostFormValue("login") == fmt.Sprint(i.ID) {
|
||||||
session := Session{
|
session := Session{
|
||||||
uuid: uuid.New(),
|
UUID: uuid.New(),
|
||||||
instructor: *i,
|
Instructor: *i,
|
||||||
briefings: make([]*briefing, 0),
|
Briefings: make([]*Briefing, 0),
|
||||||
}
|
}
|
||||||
(*ss) = append((*ss), &session)
|
(*ss) = append((*ss), &session)
|
||||||
cs <- &session
|
cs <- &session
|
||||||
|
|
||||||
data := tableHTMLData{sessionID: session.uuid}
|
data := tableHTMLData{SessionID: session.UUID}
|
||||||
data.otd, err = db.GetAllOverviewTableData()
|
data.OTD, err = db.GetAllOverviewTableData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
@ -67,13 +54,26 @@ func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.H
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findCorrectLogin(l string, ss *[]*Session) (*Briefing, *Participant, bool) {
|
||||||
|
for _, s := range *ss {
|
||||||
|
for _, b := range s.Briefings {
|
||||||
|
for _, p := range b.Participants {
|
||||||
|
if l == p.Login {
|
||||||
|
return b, p, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil, false
|
||||||
|
}
|
||||||
|
|
||||||
func HandleExternalLogin(ss *[]*Session) http.HandlerFunc {
|
func HandleExternalLogin(ss *[]*Session) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
briefing, participant, loginCorrect := findCorrectLogin(r.PostFormValue("login"), ss)
|
briefing, participant, loginCorrect := findCorrectLogin(r.PostFormValue("login"), ss)
|
||||||
if loginCorrect {
|
if loginCorrect {
|
||||||
data := participantHTMLData{
|
data := participantHTMLData{
|
||||||
briefingID: briefing.uuid,
|
BriefingID: briefing.UUID,
|
||||||
participant: *participant,
|
Participant: Participant{Login: participant.Login},
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/participant.html")).ExecuteTemplate(w, "content", data)
|
template.Must(template.ParseFiles("templates/participant.html")).ExecuteTemplate(w, "content", data)
|
||||||
|
@ -20,15 +20,31 @@ import (
|
|||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mux struct {
|
type Mux struct {
|
||||||
*http.ServeMux
|
*http.ServeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMux() *mux {
|
func NewMux() *Mux {
|
||||||
return &mux{ServeMux: http.NewServeMux()}
|
return &Mux{ServeMux: http.NewServeMux()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQuestions(db *data.DB, b *briefing) {
|
func (mux *Mux) handleParticipants(db *data.DB, cp <-chan *Participant, b *Briefing) {
|
||||||
|
for p := range cp {
|
||||||
|
p.GivenAnswers = make([]int, len(b.Questions))
|
||||||
|
|
||||||
|
mux.HandleFunc("/submit-participant/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleParticipant(db, b))
|
||||||
|
mux.HandleFunc("/end-video/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleEndOfVideo(b))
|
||||||
|
var i int
|
||||||
|
for i = range b.Questions {
|
||||||
|
mux.HandleFunc("/submit-answer/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/"+fmt.Sprint(i+1)+"/", p.handleAnswer(db, b, int64(i+1)))
|
||||||
|
}
|
||||||
|
mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleAllowRetry())
|
||||||
|
mux.HandleFunc("/retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleRetry(b, &i))
|
||||||
|
mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleRefresh(b))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getQuestions(db *data.DB, b *Briefing) {
|
||||||
questionIDs := make([]string, 4)
|
questionIDs := make([]string, 4)
|
||||||
|
|
||||||
for i := 0; i < len(questionIDs); i++ {
|
for i := 0; i < len(questionIDs); i++ {
|
||||||
@ -36,59 +52,43 @@ func getQuestions(db *data.DB, b *briefing) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
b.questions, err = db.GetQuestions(questionIDs)
|
b.Questions, err = db.GetQuestions(questionIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range b.questions {
|
for i := range b.Questions {
|
||||||
for j := range b.questions[i].Answers {
|
for j := range b.Questions[i].Answers {
|
||||||
if parts := strings.Split(b.questions[i].Answers[j].Text, ":/"); parts[0] == "file" {
|
if parts := strings.Split(b.Questions[i].Answers[j].Text, ":/"); parts[0] == "file" {
|
||||||
b.questions[i].Answers[j].Text = parts[1]
|
b.Questions[i].Answers[j].Text = parts[1]
|
||||||
b.questions[i].Answers[j].IsImage = true
|
b.Questions[i].Answers[j].IsImage = true
|
||||||
} else {
|
} else {
|
||||||
b.questions[i].Answers[j].IsImage = false
|
b.Questions[i].Answers[j].IsImage = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mux *mux) handleParticipants(db *data.DB, cp <-chan *participant, b *briefing) {
|
func (mux *Mux) handleBriefings(db *data.DB, cb <-chan *Briefing, s *Session) {
|
||||||
for p := range cp {
|
participantChan := make(chan *Participant)
|
||||||
p.givenAnswers = make([]int, len(b.questions))
|
|
||||||
|
|
||||||
mux.HandleFunc("/submit-participant/"+fmt.Sprint(b.uuid)+"/"+fmt.Sprint(p.login)+"/", p.handleParticipant(db, b))
|
|
||||||
mux.HandleFunc("/end-video/"+fmt.Sprint(b.uuid)+"/"+fmt.Sprint(p.login)+"/", p.handleEndOfVideo(b))
|
|
||||||
var i int
|
|
||||||
for i = range b.questions {
|
|
||||||
mux.HandleFunc("/submit-answer/"+fmt.Sprint(b.uuid)+"/"+fmt.Sprint(p.login)+"/"+fmt.Sprint(i+1)+"/", p.handleAnswer(db, b, int64(i+1)))
|
|
||||||
}
|
|
||||||
mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.uuid)+"/"+fmt.Sprint(p.login)+"/", p.handleAllowRetry())
|
|
||||||
mux.HandleFunc("/retry/"+fmt.Sprint(b.uuid)+"/"+fmt.Sprint(p.login)+"/", p.handleRetry(b, &i))
|
|
||||||
mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.uuid)+"/"+fmt.Sprint(p.login)+"/", p.handleRefresh(b))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mux *mux) handleBriefings(db *data.DB, cb <-chan *briefing, s *Session) {
|
|
||||||
participantChan := make(chan *participant)
|
|
||||||
for b := range cb {
|
for b := range cb {
|
||||||
getQuestions(db, b)
|
getQuestions(db, b)
|
||||||
|
|
||||||
mux.HandleFunc("/new-participant/"+fmt.Sprint(b.uuid)+"/", b.handleNewParticipant(participantChan))
|
mux.HandleFunc("/new-participant/"+fmt.Sprint(b.UUID)+"/", b.handleNewParticipant(participantChan))
|
||||||
mux.HandleFunc("/submit-form/"+fmt.Sprint(b.uuid)+"/", b.handleBriefingForm(db, s))
|
mux.HandleFunc("/submit-form/"+fmt.Sprint(b.UUID)+"/", b.handleBriefingForm(db, s))
|
||||||
|
|
||||||
go mux.handleParticipants(db, participantChan, b)
|
go mux.handleParticipants(db, participantChan, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mux *mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session) {
|
func (mux *Mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session) {
|
||||||
briefingChan := make(chan *briefing)
|
briefingChan := make(chan *Briefing)
|
||||||
for s := range cs {
|
for s := range cs {
|
||||||
(*ss) = append((*ss), s)
|
(*ss) = append((*ss), s)
|
||||||
|
|
||||||
mux.HandleFunc("/search/"+fmt.Sprint(s.uuid)+"/", s.handleSearch(db))
|
mux.HandleFunc("/search/"+fmt.Sprint(s.UUID)+"/", s.handleSearch(db))
|
||||||
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.uuid)+"/", s.handleNewBriefing(briefingChan))
|
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.UUID)+"/", s.handleNewBriefing(briefingChan))
|
||||||
mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.uuid)+"/", s.handleBriefingDone(db))
|
mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.UUID)+"/", s.handleBriefingDone(db))
|
||||||
|
|
||||||
go mux.handleBriefings(db, briefingChan, s)
|
go mux.handleBriefings(db, briefingChan, s)
|
||||||
}
|
}
|
||||||
|
@ -21,45 +21,45 @@ import (
|
|||||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type participant struct {
|
type Participant struct {
|
||||||
*data.Participant
|
*data.Participant
|
||||||
login string
|
Login string
|
||||||
givenAnswers []int
|
GivenAnswers []int
|
||||||
numberIncorrect int
|
NoIncorrect int
|
||||||
allowRetry bool
|
AllowRetry bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleGivenAnswer(p *participant, i int64, r *http.Request) error {
|
func handleGivenAnswer(p *Participant, i int64, r *http.Request) error {
|
||||||
answer, err := strconv.Atoi(r.PostFormValue("answer"))
|
answer, err := strconv.Atoi(r.PostFormValue("answer"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error: handleGivenAnswer: strconv.Atoi(): %v", err)
|
return fmt.Errorf("error: handleGivenAnswer: strconv.Atoi(): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.givenAnswers[i] = answer
|
p.GivenAnswers[i] = answer
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeResultQuestions(sq []data.Question, givenAnswers []int) []resultQuestion {
|
func makeResultQuestions(sq []data.Question, givenAnswers []int) []resultQuestion {
|
||||||
questions := make([]resultQuestion, len(sq))
|
questions := make([]resultQuestion, len(sq))
|
||||||
for i, q := range sq {
|
for i, q := range sq {
|
||||||
questions[i].text = q.Text
|
questions[i].Text = q.Text
|
||||||
questions[i].answers = make([]resultAnswer, len(q.Answers))
|
questions[i].Answers = make([]resultAnswer, len(q.Answers))
|
||||||
|
|
||||||
for j := range q.Answers {
|
for j := range q.Answers {
|
||||||
questions[i].answers[j].id = q.Answers[j].ID
|
questions[i].Answers[j].ID = q.Answers[j].ID
|
||||||
questions[i].answers[j].text = q.Answers[j].Text
|
questions[i].Answers[j].Text = q.Answers[j].Text
|
||||||
questions[i].answers[j].isImage = q.Answers[j].IsImage
|
questions[i].Answers[j].IsImage = q.Answers[j].IsImage
|
||||||
|
|
||||||
if j+1 == q.Correct {
|
if j+1 == q.Correct {
|
||||||
questions[i].answers[j].correct = true
|
questions[i].Answers[j].Correct = true
|
||||||
} else {
|
} else {
|
||||||
questions[i].answers[j].correct = false
|
questions[i].Answers[j].Correct = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if j+1 == givenAnswers[i] {
|
if j+1 == givenAnswers[i] {
|
||||||
questions[i].answers[j].chosen = true
|
questions[i].Answers[j].Chosen = true
|
||||||
} else {
|
} else {
|
||||||
questions[i].answers[j].chosen = false
|
questions[i].Answers[j].Chosen = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,11 +67,11 @@ func makeResultQuestions(sq []data.Question, givenAnswers []int) []resultQuestio
|
|||||||
return questions
|
return questions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *participant) handleParticipant(db *data.DB, b *briefing) http.HandlerFunc {
|
func (p *Participant) handleParticipant(db *data.DB, b *Briefing) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
p.FirstName = r.PostFormValue("first-" + fmt.Sprint(p.login))
|
p.FirstName = r.PostFormValue("first-" + fmt.Sprint(p.Login))
|
||||||
p.LastName = r.PostFormValue("last-" + fmt.Sprint(p.login))
|
p.LastName = r.PostFormValue("last-" + fmt.Sprint(p.Login))
|
||||||
p.Company = r.PostFormValue("company-" + fmt.Sprint(p.login))
|
p.Company = r.PostFormValue("company-" + fmt.Sprint(p.Login))
|
||||||
|
|
||||||
err := db.WriteParticipant(p.Participant)
|
err := db.WriteParticipant(p.Participant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -80,17 +80,17 @@ func (p *participant) handleParticipant(db *data.DB, b *briefing) http.HandlerFu
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := participantHTMLData{
|
data := participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: *p,
|
Participant: *p,
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/video.html")).ExecuteTemplate(w, "content", data)
|
template.Must(template.ParseFiles("templates/video.html")).ExecuteTemplate(w, "content", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *participant) handleAnswer(db *data.DB, b *briefing, i int64) http.HandlerFunc {
|
func (p *Participant) handleAnswer(db *data.DB, b *Briefing, i int64) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if i < int64(len(b.questions)) {
|
if i < int64(len(b.Questions)) {
|
||||||
if err := handleGivenAnswer(p, i-1, r); err != nil {
|
if err := handleGivenAnswer(p, i-1, r); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
@ -98,11 +98,11 @@ func (p *participant) handleAnswer(db *data.DB, b *briefing, i int64) http.Handl
|
|||||||
|
|
||||||
data := questionHTMLData{
|
data := questionHTMLData{
|
||||||
participantHTMLData: participantHTMLData{
|
participantHTMLData: participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: participant{login: p.login},
|
Participant: Participant{Login: p.Login},
|
||||||
},
|
},
|
||||||
questionID: i + 1,
|
QuestionID: i + 1,
|
||||||
question: b.questions[i],
|
Question: b.Questions[i],
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
||||||
@ -112,23 +112,23 @@ func (p *participant) handleAnswer(db *data.DB, b *briefing, i int64) http.Handl
|
|||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.numberIncorrect = 0
|
p.NoIncorrect = 0
|
||||||
for i, q := range b.questions {
|
for i, q := range b.Questions {
|
||||||
if p.givenAnswers[i] != q.Correct {
|
if p.GivenAnswers[i] != q.Correct {
|
||||||
p.numberIncorrect++
|
p.NoIncorrect++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data := resultHTMLData{
|
data := resultHTMLData{
|
||||||
participantHTMLData: participantHTMLData{
|
participantHTMLData: participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: *p,
|
Participant: *p,
|
||||||
},
|
},
|
||||||
questions: makeResultQuestions(b.questions, p.givenAnswers),
|
Questions: makeResultQuestions(b.Questions, p.GivenAnswers),
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.numberIncorrect == 0 {
|
if data.NoIncorrect == 0 {
|
||||||
if err := db.WriteGivenAnswers(*b.Briefing, *p.Participant, b.questions, p.givenAnswers); err != nil {
|
if err := db.WriteGivenAnswers(*b.Briefing, *p.Participant, b.Questions, p.GivenAnswers); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
@ -139,36 +139,36 @@ func (p *participant) handleAnswer(db *data.DB, b *briefing, i int64) http.Handl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *participant) handleAllowRetry() http.HandlerFunc {
|
func (p *Participant) handleAllowRetry() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
p.numberIncorrect = -1
|
p.NoIncorrect = -1
|
||||||
p.allowRetry = true
|
p.AllowRetry = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *participant) handleRetry(b *briefing, i *int) http.HandlerFunc {
|
func (p *Participant) handleRetry(b *Briefing, i *int) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if p.allowRetry {
|
if p.AllowRetry {
|
||||||
p.allowRetry = false
|
p.AllowRetry = false
|
||||||
(*i) = 0
|
(*i) = 0
|
||||||
|
|
||||||
data := questionHTMLData{
|
data := questionHTMLData{
|
||||||
participantHTMLData: participantHTMLData{
|
participantHTMLData: participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: participant{login: p.login},
|
Participant: Participant{Login: p.Login},
|
||||||
},
|
},
|
||||||
questionID: int64(*i + 1),
|
QuestionID: int64(*i + 1),
|
||||||
question: b.questions[*i],
|
Question: b.Questions[*i],
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
||||||
} else {
|
} else {
|
||||||
data := resultHTMLData{
|
data := resultHTMLData{
|
||||||
participantHTMLData: participantHTMLData{
|
participantHTMLData: participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: *p,
|
Participant: *p,
|
||||||
},
|
},
|
||||||
questions: makeResultQuestions(b.questions, p.givenAnswers),
|
Questions: makeResultQuestions(b.Questions, p.GivenAnswers),
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/result.html")).ExecuteTemplate(w, "content", data)
|
template.Must(template.ParseFiles("templates/result.html")).ExecuteTemplate(w, "content", data)
|
||||||
@ -176,26 +176,26 @@ func (p *participant) handleRetry(b *briefing, i *int) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *participant) handleRefresh(b *briefing) http.HandlerFunc {
|
func (p *Participant) handleRefresh(b *Briefing) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
data := participantHTMLData{
|
data := participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: *p,
|
Participant: *p,
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/summary.html")).ExecuteTemplate(w, "participant", data)
|
template.Must(template.ParseFiles("templates/summary.html")).ExecuteTemplate(w, "participant", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *participant) handleEndOfVideo(b *briefing) http.HandlerFunc {
|
func (p *Participant) handleEndOfVideo(b *Briefing) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
data := questionHTMLData{
|
data := questionHTMLData{
|
||||||
participantHTMLData: participantHTMLData{
|
participantHTMLData: participantHTMLData{
|
||||||
briefingID: b.uuid,
|
BriefingID: b.UUID,
|
||||||
participant: participant{login: p.login},
|
Participant: Participant{Login: p.Login},
|
||||||
},
|
},
|
||||||
questionID: 1,
|
QuestionID: 1,
|
||||||
question: b.questions[0],
|
Question: b.Questions[0],
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
||||||
|
@ -21,9 +21,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
instructor data.Instructor
|
UUID uuid.UUID
|
||||||
briefings []*briefing
|
Instructor data.Instructor
|
||||||
uuid uuid.UUID
|
Briefings []*Briefing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) handleSearch(db *data.DB) http.HandlerFunc {
|
func (s *Session) handleSearch(db *data.DB) http.HandlerFunc {
|
||||||
@ -31,8 +31,8 @@ func (s *Session) handleSearch(db *data.DB) http.HandlerFunc {
|
|||||||
var err error
|
var err error
|
||||||
data := tableHTMLData{}
|
data := tableHTMLData{}
|
||||||
|
|
||||||
data.sessionID = s.uuid
|
data.SessionID = s.UUID
|
||||||
data.otd, err = db.GetOverviewTableDataByName(r.PostFormValue("search"))
|
data.OTD, err = db.GetOverviewTableDataByName(r.PostFormValue("search"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
@ -41,22 +41,22 @@ func (s *Session) handleSearch(db *data.DB) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) handleNewBriefing(cb chan<- *briefing) http.HandlerFunc {
|
func (s *Session) handleNewBriefing(cb chan<- *Briefing) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
briefing := briefing{Briefing: &data.Briefing{InstructorID: s.instructor.ID}, uuid: uuid.New()}
|
briefing := Briefing{Briefing: &data.Briefing{InstructorID: s.Instructor.ID}, UUID: uuid.New()}
|
||||||
s.briefings = append(s.briefings, &briefing)
|
s.Briefings = append(s.Briefings, &briefing)
|
||||||
cb <- &briefing
|
cb <- &briefing
|
||||||
|
|
||||||
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", participantHTMLData{briefingID: briefing.uuid})
|
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", participantHTMLData{BriefingID: briefing.UUID})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) handleBriefingDone(db *data.DB) http.HandlerFunc {
|
func (s *Session) handleBriefingDone(db *data.DB) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
data := tableHTMLData{sessionID: s.uuid}
|
data := tableHTMLData{SessionID: s.UUID}
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
data.otd, err = db.GetAllOverviewTableData()
|
data.OTD, err = db.GetAllOverviewTableData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
|
3
static/css/input.css
Normal file
3
static/css/input.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
9
tailwind.config.js
Normal file
9
tailwind.config.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: ["./templates/*.html"],
|
||||||
|
theme: {
|
||||||
|
extend: {},
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
<link rel="stylesheet" href="/static/css/style.css">
|
||||||
|
<link rel="stylesheet" href="/static/css/output.css">
|
||||||
<title>Sicherheitsunterweisung</title>
|
<title>Sicherheitsunterweisung</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user