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 @@ -
- - Probo_ - +
+ -
+ {{template "content" .}} - - diff --git a/embed/templates/sessions/sessions.html.tmpl b/embed/templates/sessions/sessions.html.tmpl index e5b04ad..66d38d4 100644 --- a/embed/templates/sessions/sessions.html.tmpl +++ b/embed/templates/sessions/sessions.html.tmpl @@ -8,7 +8,7 @@
{{$session.Title}}
{{$session.CreatedAt}}

{{$session.Description}}

- Inizia! + Inizia! diff --git a/pkg/models/response.go b/pkg/models/response.go index 71b511c..02d14b9 100644 --- a/pkg/models/response.go +++ b/pkg/models/response.go @@ -14,8 +14,9 @@ type ParticipantAnswer struct { type Response struct { Meta - SessionID string `json:"session_id"` - Answers []*ParticipantAnswer `json:"answers"` + SessionTitle string `json:"session_title"` + Participant *Participant `json:"participant"` + Answers []*ParticipantAnswer `json:"answers"` } func (r *Response) String() string { diff --git a/pkg/models/session.go b/pkg/models/session.go index 0e52303..f42414b 100644 --- a/pkg/models/session.go +++ b/pkg/models/session.go @@ -9,11 +9,13 @@ import ( type Session struct { Meta - Title string `json:"title"` - Description string `json:"description"` - Quizzes map[string]*Quiz `json:"quizzes"` - Answers map[string]*Answer `json:"answers"` - Exams map[string]*Exam `json:"exams"` + Title string `json:"title"` + Description string `json:"description"` + + Participants map[string]*Participant `json:"participants"` + Quizzes map[string]*Quiz `json:"quizzes"` + Answers map[string]*Answer `json:"answers"` + Exams map[string]*Exam `json:"exams"` } func (s *Session) String() string { diff --git a/pkg/store/file/response.go b/pkg/store/file/response.go index 788853b..55f3f7c 100644 --- a/pkg/store/file/response.go +++ b/pkg/store/file/response.go @@ -8,7 +8,7 @@ import ( type ResponseFileStore = FileStore[*models.Response, *store.Store[*models.Response]] func NewResponseFileStore(config *FileStoreConfig[*models.Response, *store.ResponseStore]) (*ResponseFileStore, error) { - return NewFileStore[*models.Response](config, store.NewStore[*models.Response]()) + return NewFileStore(config, store.NewStore[*models.Response]()) } func NewDefaultResponseFileStore() (*ResponseFileStore, error) { diff --git a/pkg/store/session.go b/pkg/store/session.go index a0ac3ed..1959cb1 100644 --- a/pkg/store/session.go +++ b/pkg/store/session.go @@ -33,10 +33,14 @@ func (s *SessionStore) Create(session *models.Session) (*models.Session, error) } } + session.Participants = make(map[string]*models.Participant, 0) session.Quizzes = make(map[string]*models.Quiz, 0) session.Answers = make(map[string]*models.Answer, 0) for _, exam := range session.Exams { + + session.Participants[exam.Participant.ID] = exam.Participant + for _, quiz := range exam.Quizzes { session.Quizzes[quiz.ID] = quiz