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
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 {
|
||||
|
@ -14,6 +14,7 @@
|
||||
export let qid;
|
||||
export let response_history = null;
|
||||
export let readonly = false;
|
||||
export let corrections = {};
|
||||
export let survey = null;
|
||||
export let value = "";
|
||||
|
||||
@ -92,6 +93,7 @@
|
||||
{proposals}
|
||||
readonly
|
||||
live={survey.direct !== null}
|
||||
{corrections}
|
||||
bind:value={value}
|
||||
on:change={() => { dispatch("change"); }}
|
||||
/>
|
||||
@ -110,6 +112,7 @@
|
||||
{proposals}
|
||||
{readonly}
|
||||
live={survey.direct !== null}
|
||||
{corrections}
|
||||
bind:value={value}
|
||||
on:change={() => { dispatch("change"); }}
|
||||
/>
|
||||
|
@ -9,6 +9,7 @@
|
||||
export let kind = 'mcq';
|
||||
export let prefixid = '';
|
||||
export let readonly = false;
|
||||
export let corrections = {};
|
||||
export let id_question = 0;
|
||||
export let value;
|
||||
|
||||
@ -91,8 +92,11 @@
|
||||
class:form-check-label={!live}
|
||||
class:btn={live}
|
||||
class:btn-lg={live}
|
||||
class:btn-primary={live && value.indexOf(proposal.id.toString()) != -1}
|
||||
class:btn-outline-primary={live && value.indexOf(proposal.id.toString()) == -1}
|
||||
class:btn-primary={live && !corrections && value.indexOf(proposal.id.toString()) != -1}
|
||||
class:btn-outline-primary={live && !corrections && value.indexOf(proposal.id.toString()) == -1}
|
||||
class:btn-success={live && corrections && corrections[proposal.id] == 0}
|
||||
class:btn-outline-warning={live && corrections && corrections[proposal.id] != 0 && corrections[proposal.id] != -100}
|
||||
class:btn-outline-danger={live && corrections && corrections[proposal.id] == -100}
|
||||
for={prefixid + 'p' + proposal.id}
|
||||
>
|
||||
{proposal.label}
|
||||
|
@ -90,6 +90,7 @@
|
||||
if (data.action && data.action == "new_question") {
|
||||
show_question = data.question;
|
||||
survey.corrected = data.corrected;
|
||||
corrections = data.corrections;
|
||||
if (timer_cancel) {
|
||||
clearInterval(timer_cancel);
|
||||
timer_cancel = null;
|
||||
@ -156,6 +157,8 @@
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let corrections = {};
|
||||
</script>
|
||||
|
||||
{#await surveyP then unused}
|
||||
@ -189,6 +192,7 @@
|
||||
{survey}
|
||||
{question}
|
||||
readonly={timer >= 100 || survey.corrected}
|
||||
{corrections}
|
||||
bind:value={value}
|
||||
on:change={sendValue}
|
||||
>
|
||||
|
Reference in New Issue
Block a user