diff --git a/cmd/filter/format.go b/cmd/filter/format.go index 2bcb53e..e8af0ba 100644 --- a/cmd/filter/format.go +++ b/cmd/filter/format.go @@ -9,6 +9,6 @@ var ( filterTypeFormats = map[string]string{ "participants": "👫 Participants filter 👫", "quizzes": "❓ Quizzes filter ❓", - "responses": "📝 Responsesfilter 📝", + "responses": "📝 Responses filter 📝", } ) diff --git a/cmd/serve.go b/cmd/serve.go index 5afc309..80a468f 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -67,8 +67,8 @@ func runServer(cmd *cobra.Command, args []string) { mux.Handle("POST /login", serve.Recover(loginController)) mux.Handle("GET /sessions", serve.Recover(sessionsController)) - mux.Handle("GET /sessions/{uuid}/exams/{token}", serve.Recover(examController)) - mux.Handle("POST /sessions/{uuid}/exams/{token}", serve.Recover(examController)) + mux.Handle("GET /sessions/{uuid}/exams/{participantID}", serve.Recover(examController)) + mux.Handle("POST /sessions/{uuid}/exams/{participantID}", serve.Recover(examController)) mux.Handle("GET /public/", http.StripPrefix("/public", http.FileServer(http.Dir("public")))) diff --git a/cmd/serve/exam.go b/cmd/serve/exam.go index 5e7b2e9..1a1cded 100644 --- a/cmd/serve/exam.go +++ b/cmd/serve/exam.go @@ -14,22 +14,22 @@ var ExamHandler = func(c *Controller, w http.ResponseWriter, r *http.Request) { panic(err) } - participantToken := r.PathValue("token") + participantID := r.PathValue("participantID") session, err := c.sStore.Read(r.PathValue("uuid")) if err != nil { panic(err) } - exam, ok := session.Exams[participantToken] + exam, ok := session.Exams[participantID] if !ok { panic(errors.New("Exam not found in the store!")) } examWithSession := struct { *models.Exam - SessionID string - }{exam, session.ID} + Session *models.Session + }{exam, session} switch r.Method { @@ -49,12 +49,14 @@ var ExamHandler = func(c *Controller, w http.ResponseWriter, r *http.Request) { answers := make([]*models.ParticipantAnswer, 0) + participant := session.Participants[participantID] + for quizID, values := range r.Form { correct := false + quiz := session.Quizzes[quizID] for _, answerID := range values { - log.Info(answerID) if quiz.Correct.ID == answerID { correct = true } @@ -64,8 +66,9 @@ var ExamHandler = func(c *Controller, w http.ResponseWriter, r *http.Request) { response, err := c.rStore.Create( &models.Response{ - SessionID: session.ID, - Answers: answers, + SessionTitle: session.Title, + Participant: participant, + Answers: answers, }) if err != nil { panic(err) diff --git a/cmd/serve/sessions.go b/cmd/serve/sessions.go index 66156bc..877ef1c 100644 --- a/cmd/serve/sessions.go +++ b/cmd/serve/sessions.go @@ -15,7 +15,7 @@ var SessionsHandler = func(c *Controller, w http.ResponseWriter, r *http.Request claims := token.Claims.(jwt.MapClaims) var participantSessions []struct { - Token string + ParticipantID string *models.Session } @@ -23,9 +23,9 @@ var SessionsHandler = func(c *Controller, w http.ResponseWriter, r *http.Request for _, exam := range session.Exams { if exam.Participant.Token == claims["token"] { s := struct { - Token string + ParticipantID string *models.Session - }{exam.Participant.Token, session} + }{exam.Participant.ID, session} participantSessions = append(participantSessions, s) break } diff --git a/cmd/session/session.go b/cmd/session/session.go index a49d00c..701c6ad 100644 --- a/cmd/session/session.go +++ b/cmd/session/session.go @@ -96,8 +96,9 @@ func New(path string, stdin string) *SessionModel { viewport := viewport.New() - table := table.New(table.WithRelWidths(20, 30, 30, 20)) + table := table.New(table.WithRelWidths(20, 10, 25, 25, 20)) table.Model.SetColumns([]btTable.Column{ + {Title: "UUID", Width: 20}, {Title: "Token", Width: 20}, {Title: "Lastname", Width: 20}, {Title: "Firstname", Width: 20}, @@ -285,9 +286,10 @@ func (m *SessionModel) showErrorOnStatusBar(err error) { func (m *SessionModel) updateTableContent(session *models.Session) { rows := make([]btTable.Row, 0) - for token, exam := range session.Exams { + for _, exam := range session.Exams { rows = append(rows, btTable.Row{ - token, + sanitize(exam.Participant.ID), + exam.Participant.Token, exam.Participant.Lastname, exam.Participant.Firstname, exam.Participant.Attributes.Get("class"), @@ -303,8 +305,8 @@ func (m *SessionModel) updateViewportContent(session *models.Session) { panic(errors.New("Session have not exams")) } - currentToken := m.table.SelectedRow()[0] - currentExam := session.Exams[currentToken] + currentUUID := m.table.SelectedRow()[0] + currentExam := session.Exams[desanitize(currentUUID)] if currentExam == nil { panic("Current token is not associate to any exam!") @@ -466,3 +468,10 @@ func sanitize(text string) string { // required to resolve this problem. return strings.Replace(text, "-", "–", -1) } + +func desanitize(text string) string { + // FIXME: The use of a standard '-' character causes rendering + // issues within the viewport. Further investigation is + // required to resolve this problem. + return strings.Replace(text, "–", "-", -1) +} diff --git a/embed/templates/exam/layout-exam.html.tmpl b/embed/templates/exam/layout-exam.html.tmpl index 994d78b..53819ed 100644 --- a/embed/templates/exam/layout-exam.html.tmpl +++ b/embed/templates/exam/layout-exam.html.tmpl @@ -8,34 +8,29 @@
-