frontend: treat MCQ justification as key flag, instead of special case

This commit is contained in:
nemunaire 2019-01-17 22:30:39 +01:00
commit b6769086c2
4 changed files with 126 additions and 99 deletions

View file

@ -9,8 +9,6 @@ import (
type FlagLabel struct {
Label string
IdChoice int64
Checksum []byte
Solved bool
}
// IsMCQJustification tells you if this key represent a justification from a MCQ.

View file

@ -22,20 +22,6 @@ type myTeamHint struct {
File string `json:"file,omitempty"`
Cost int64 `json:"cost"`
}
type myTeamMCQJustifiedChoice struct {
Label string `json:"label"`
Solved bool `json:"solved,omitempty"`
Value bool `json:"value,omitempty"`
Help string `json:"help,omitempty"`
}
type myTeamMCQ struct {
Title string `json:"title"`
Justify bool `json:"justify,omitempty"`
Choices map[int64]interface{} `json:"choices,omitempty"`
Solved *time.Time `json:"solved,omitempty"`
PSolved *time.Time `json:"part_solved,omitempty"`
Soluce string `json:"soluce,omitempty"`
}
type myTeamFlag struct {
Label string `json:"label"`
Help string `json:"help,omitempty"`
@ -46,6 +32,19 @@ type myTeamFlag struct {
Choices map[string]string `json:"choices,omitempty"`
ChoicesCost int64 `json:"choices_cost,omitempty"`
}
type myTeamMCQJustifiedChoice struct {
Label string `json:"label"`
Value bool `json:"value,omitempty"`
Justification myTeamFlag `json:"justification,omitempty"`
}
type myTeamMCQ struct {
Title string `json:"title"`
Justify bool `json:"justify,omitempty"`
Choices map[int64]interface{} `json:"choices,omitempty"`
Solved *time.Time `json:"solved,omitempty"`
PSolved *time.Time `json:"part_solved,omitempty"`
Soluce string `json:"soluce,omitempty"`
}
type myTeamExercice struct {
ThemeId int64 `json:"theme_id"`
Statement string `json:"statement"`
@ -171,7 +170,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
// Expose exercice flags
justifiedMCQ := map[int64]FlagLabel{}
justifiedMCQ := map[int64]myTeamFlag{}
exercice.Flags = map[int64]myTeamFlag{}
if flags, err := e.GetFlagKeys(); err != nil {
@ -185,19 +184,19 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
continue
}
if fl, err := k.GetMCQJustification(); err == nil {
fl.Checksum = k.Checksum
if t != nil && t.HasPartiallySolved(k) != nil {
fl.Solved = true
}
justifiedMCQ[fl.IdChoice] = fl
continue
} else if t == nil {
// Retrieve solved state or solution for public iface
if t == nil {
flag.Soluce = hex.EncodeToString(k.Checksum)
} else if PartialValidation {
flag.Solved = t.HasPartiallySolved(k)
}
var fl FlagLabel
if fl, err = k.GetMCQJustification(); err == nil {
k.Label = fl.Label
}
// Treat array flags
if k.Label[0] == '`' && len(k.Label) > 3 {
flag.Label = k.Label[3:]
flag.Separator = string(k.Label[1])
@ -206,6 +205,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
flag.Label = k.Label
}
// Fill more information if the flag is displaied
if flag.Solved == nil {
flag.Help = k.Help
if choices, err := k.GetChoices(); err != nil {
@ -220,7 +220,12 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
}
}
exercice.Flags[k.Id] = flag
// Append to corresponding flags' map
if fl.IdChoice != 0 {
justifiedMCQ[fl.IdChoice] = flag
} else {
exercice.Flags[k.Id] = flag
}
}
}
@ -258,19 +263,14 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
if v, ok := justifiedMCQ[e.Id]; ok {
m.Justify = true
if t == nil {
soluce += hex.EncodeToString(v.Checksum)
}
if m.PSolved != nil || v.Solved {
if m.PSolved != nil || v.Solved != nil {
jc := myTeamMCQJustifiedChoice{
Label: e.Label,
Solved: v.Solved,
Value: v.Solved,
Help: v.Label,
Value: v.Solved != nil,
Justification: v,
}
if !v.Solved {
if v.Solved == nil {
fullySolved = false
}