|
|
|
@ -21,15 +21,14 @@ func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.H
|
|
|
|
|
|
|
|
|
|
for _, i := range instructors {
|
|
|
|
|
if r.PostFormValue("login") == fmt.Sprint(i.ID) {
|
|
|
|
|
session := new(Session)
|
|
|
|
|
session.ID = uuid.New()
|
|
|
|
|
session.Briefing = new(data.Briefing)
|
|
|
|
|
session.InstructorID = i.ID
|
|
|
|
|
(*ss) = append((*ss), session)
|
|
|
|
|
cs <- session
|
|
|
|
|
session := Session{
|
|
|
|
|
ID: uuid.New(),
|
|
|
|
|
Briefing: &data.Briefing{InstructorID: i.ID},
|
|
|
|
|
}
|
|
|
|
|
(*ss) = append((*ss), &session)
|
|
|
|
|
cs <- &session
|
|
|
|
|
|
|
|
|
|
data := new(tableHTMLData)
|
|
|
|
|
data.SessionID = session.ID
|
|
|
|
|
data := tableHTMLData{SessionID: session.ID}
|
|
|
|
|
data.OTD, err = db.GetAllOverviewTableData()
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
@ -61,34 +60,30 @@ func (s *Session) HandleSearch(db *data.DB) http.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
func (s *Session) HandleNewBriefing() http.HandlerFunc {
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
data := new(participantHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", data)
|
|
|
|
|
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", participantHTMLData{SessionID: s.ID})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Session) HandleNewParticipant(cp chan<- *BriefingParticipant) http.HandlerFunc {
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
var err error
|
|
|
|
|
p := new(BriefingParticipant)
|
|
|
|
|
p.Participant = new(data.Participant)
|
|
|
|
|
p.NoIncorrect = -1
|
|
|
|
|
p.AllowRetry = false
|
|
|
|
|
participant := BriefingParticipant{
|
|
|
|
|
Participant: new(data.Participant),
|
|
|
|
|
NoIncorrect: -1,
|
|
|
|
|
AllowRetry: false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.Login, err = generateLogin()
|
|
|
|
|
participant.Login, err = generateLogin()
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
s.Participants = append(s.Participants, p)
|
|
|
|
|
cp <- p
|
|
|
|
|
s.Participants = append(s.Participants, &participant)
|
|
|
|
|
cp <- &participant
|
|
|
|
|
|
|
|
|
|
data := new(participantHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.Login = p.Login
|
|
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
data := participantHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
BriefingParticipant: BriefingParticipant{Login: participant.Login},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "new", data)
|
|
|
|
@ -111,9 +106,10 @@ func (s *Session) HandleBriefingForm(db *data.DB) http.HandlerFunc {
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := new(summaryHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.ParticipantsData = make([]participantHTMLData, len(s.Participants))
|
|
|
|
|
data := summaryHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
ParticipantsData: make([]participantHTMLData, len(s.Participants)),
|
|
|
|
|
}
|
|
|
|
|
for i, p := range s.Participants {
|
|
|
|
|
data.ParticipantsData[i].SessionID = s.ID
|
|
|
|
|
data.ParticipantsData[i].BriefingParticipant = *p
|
|
|
|
@ -127,9 +123,10 @@ func HandleExternalLogin(ss *[]*Session) http.HandlerFunc {
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
session, participant, loginCorrect := findCorrectLogin(r.PostFormValue("login"), ss)
|
|
|
|
|
if loginCorrect {
|
|
|
|
|
data := new(participantHTMLData)
|
|
|
|
|
data.SessionID = session.ID
|
|
|
|
|
data.Login = participant.Login
|
|
|
|
|
data := participantHTMLData{
|
|
|
|
|
SessionID: session.ID,
|
|
|
|
|
BriefingParticipant: BriefingParticipant{Login: participant.Login},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Must(template.ParseFiles("templates/participant.html")).ExecuteTemplate(w, "content", data)
|
|
|
|
|
} else {
|
|
|
|
@ -150,11 +147,14 @@ func (s *Session) HandleParticipant(db *data.DB, p *BriefingParticipant) http.Ha
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := new(questionHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.Login = p.Login
|
|
|
|
|
data.Question = s.Questions[0]
|
|
|
|
|
data.QuestionID = 1
|
|
|
|
|
data := questionHTMLData{
|
|
|
|
|
participantHTMLData: participantHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
BriefingParticipant: BriefingParticipant{Login: p.Login},
|
|
|
|
|
},
|
|
|
|
|
QuestionID: 1,
|
|
|
|
|
Question: s.Questions[0],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
|
|
|
|
}
|
|
|
|
@ -168,11 +168,14 @@ func (s *Session) HandleAnswer(db *data.DB, p *BriefingParticipant, i int64) htt
|
|
|
|
|
log.Panicln(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := new(questionHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.Login = p.Login
|
|
|
|
|
data.Question = s.Questions[i]
|
|
|
|
|
data.QuestionID = i + 1
|
|
|
|
|
data := questionHTMLData{
|
|
|
|
|
participantHTMLData: participantHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
BriefingParticipant: BriefingParticipant{Login: p.Login},
|
|
|
|
|
},
|
|
|
|
|
QuestionID: i + 1,
|
|
|
|
|
Question: s.Questions[i],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
|
|
|
|
} else {
|
|
|
|
@ -188,10 +191,13 @@ func (s *Session) HandleAnswer(db *data.DB, p *BriefingParticipant, i int64) htt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := new(resultHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.BriefingParticipant = *p
|
|
|
|
|
data.Questions = makeHTMLQuestions(s.Questions, p.GivenAnswers)
|
|
|
|
|
data := resultHTMLData{
|
|
|
|
|
participantHTMLData: participantHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
BriefingParticipant: *p,
|
|
|
|
|
},
|
|
|
|
|
Questions: makeHTMLQuestions(s.Questions, p.GivenAnswers),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if data.NoIncorrect == 0 {
|
|
|
|
|
if err := db.WriteGivenAnswers(*s.Briefing, *p.Participant, s.Questions, p.GivenAnswers); err != nil {
|
|
|
|
@ -218,18 +224,24 @@ func (s *Session) HandleRetry(p *BriefingParticipant, i *int) http.HandlerFunc {
|
|
|
|
|
p.AllowRetry = false
|
|
|
|
|
(*i) = 0
|
|
|
|
|
|
|
|
|
|
data := new(questionHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.Login = p.Login
|
|
|
|
|
data.Question = s.Questions[*i]
|
|
|
|
|
data.QuestionID = int64(*i + 1)
|
|
|
|
|
data := questionHTMLData{
|
|
|
|
|
participantHTMLData: participantHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
BriefingParticipant: BriefingParticipant{Login: p.Login},
|
|
|
|
|
},
|
|
|
|
|
QuestionID: int64(*i + 1),
|
|
|
|
|
Question: s.Questions[*i],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Must(template.ParseFiles("templates/question.html")).ExecuteTemplate(w, "content", data)
|
|
|
|
|
} else {
|
|
|
|
|
data := new(resultHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.BriefingParticipant = *p
|
|
|
|
|
data.Questions = makeHTMLQuestions(s.Questions, p.GivenAnswers)
|
|
|
|
|
data := resultHTMLData{
|
|
|
|
|
participantHTMLData: participantHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
BriefingParticipant: *p,
|
|
|
|
|
},
|
|
|
|
|
Questions: makeHTMLQuestions(s.Questions, p.GivenAnswers),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Must(template.ParseFiles("templates/result.html")).ExecuteTemplate(w, "content", data)
|
|
|
|
|
}
|
|
|
|
@ -238,9 +250,10 @@ func (s *Session) HandleRetry(p *BriefingParticipant, i *int) http.HandlerFunc {
|
|
|
|
|
|
|
|
|
|
func (s *Session) HandleRefresh(p *BriefingParticipant) http.HandlerFunc {
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
data := new(participantHTMLData)
|
|
|
|
|
data.SessionID = s.ID
|
|
|
|
|
data.BriefingParticipant = *p
|
|
|
|
|
data := participantHTMLData{
|
|
|
|
|
SessionID: s.ID,
|
|
|
|
|
BriefingParticipant: *p,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template.Must(template.ParseFiles("templates/summary.html")).ExecuteTemplate(w, "participant", data)
|
|
|
|
|
}
|
|
|
|
|