Display mcq and ucq corrections
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
8acdf30ba4
commit
e0cd502c35
4 changed files with 54 additions and 14 deletions
53
direct.go
53
direct.go
|
|
@ -98,10 +98,16 @@ func msgCurrentState(survey *Survey) (msg WSMessage) {
|
|||
Action: "pause",
|
||||
}
|
||||
} else {
|
||||
var correction map[string]int
|
||||
if survey.Corrected {
|
||||
correction = getCorrectionString(*survey.Direct)
|
||||
}
|
||||
|
||||
msg = WSMessage{
|
||||
Action: "new_question",
|
||||
QuestionId: survey.Direct,
|
||||
Corrected: survey.Corrected,
|
||||
Action: "new_question",
|
||||
QuestionId: survey.Direct,
|
||||
Corrected: survey.Corrected,
|
||||
Corrections: correction,
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
@ -147,14 +153,15 @@ func WSWriteAll(message WSMessage) {
|
|||
}
|
||||
|
||||
type WSMessage struct {
|
||||
Action string `json:"action"`
|
||||
SurveyId *int64 `json:"survey,omitempty"`
|
||||
QuestionId *int64 `json:"question,omitempty"`
|
||||
Stats map[string]interface{} `json:"stats,omitempty"`
|
||||
UserId *int64 `json:"user,omitempty"`
|
||||
Response string `json:"value,omitempty"`
|
||||
Corrected bool `json:"corrected,omitempty"`
|
||||
Timer uint `json:"timer,omitempty"`
|
||||
Action string `json:"action"`
|
||||
SurveyId *int64 `json:"survey,omitempty"`
|
||||
QuestionId *int64 `json:"question,omitempty"`
|
||||
Stats map[string]interface{} `json:"stats,omitempty"`
|
||||
UserId *int64 `json:"user,omitempty"`
|
||||
Response string `json:"value,omitempty"`
|
||||
Corrected bool `json:"corrected,omitempty"`
|
||||
Corrections map[string]int `json:"corrections,omitempty"`
|
||||
Timer uint `json:"timer,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Survey) WSWriteAll(message WSMessage) {
|
||||
|
|
@ -231,6 +238,25 @@ loopadmin:
|
|||
log.Println(u.Login, "admin disconnected")
|
||||
}
|
||||
|
||||
func getCorrectionString(qid int64) (ret map[string]int) {
|
||||
q, err := getQuestion(int(qid))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
cts, err := q.GetCorrectionTemplates()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ret = map[string]int{}
|
||||
for _, ct := range cts {
|
||||
ret[ct.RegExp] = ct.Score
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func SurveyWSAdmin(c *gin.Context) {
|
||||
u := c.MustGet("LoggedUser").(*User)
|
||||
survey := c.MustGet("survey").(*Survey)
|
||||
|
|
@ -286,7 +312,7 @@ func SurveyWSAdmin(c *gin.Context) {
|
|||
survey.Corrected = v.Corrected
|
||||
survey.Update()
|
||||
|
||||
survey.WSWriteAll(WSMessage{Action: "new_question", QuestionId: v.QuestionId, Corrected: true})
|
||||
survey.WSWriteAll(WSMessage{Action: "new_question", QuestionId: v.QuestionId, Corrected: true, Corrections: getCorrectionString(*v.QuestionId)})
|
||||
} else {
|
||||
survey.WSWriteAll(WSMessage{Action: "pause"})
|
||||
WSAdminWriteAll(WSMessage{Action: "pause", SurveyId: &survey.Id})
|
||||
|
|
@ -296,6 +322,9 @@ func SurveyWSAdmin(c *gin.Context) {
|
|||
} else {
|
||||
survey.Direct = v.QuestionId
|
||||
survey.Corrected = v.Corrected
|
||||
if v.Corrected {
|
||||
v.Corrections = getCorrectionString(*v.QuestionId)
|
||||
}
|
||||
}
|
||||
_, err = survey.Update()
|
||||
if err != nil {
|
||||
|
|
|
|||
Reference in a new issue