Array flags can be non-ordered
This commit is contained in:
parent
dbf1985d25
commit
0e36a850cf
|
@ -22,6 +22,7 @@ Tous les textes doivent utiliser l'encodage UTF8.
|
|||
* `label = "Intitulé"` : (facultatif, par défaut : `Flag`) intitulé du drapeau ;
|
||||
* `raw = 'MieH2athxuPhai6u'` ou `raw = ['part1', 'part2']` : drapeau exact à trouver ; sous forme de tableau, le participant n'aura pas connaissaance du nombre d'éléments ;
|
||||
* `validator_regexp = "^(?:sudo +)?(.*)$"` : (facultatif) expression rationnelle dont les groupes capturés serviront comme chaîne à valider (notez que `?:` au début d'un groupe ne le capturera pas) ;
|
||||
* `ordered = false` : (facultatif, par défaut : `false`) ignore l'ordre dans lequels les éléments du tableau sont passés ;
|
||||
* `ignorecase = true` : (facultatif, par défaut : `false`) ignore la case de ce drapeau ;
|
||||
* `help = "Indication"` : (facultatif) chaîne de caractères placée sous le champ du formulaire, idéale pour donner une indication de format ;
|
||||
* `[[flag.unlock_file]]` : bloque l'accès à un fichier tant que le flag n'est pas obtenu :
|
||||
|
|
|
@ -31,6 +31,7 @@ type ExerciceFlag struct {
|
|||
Label string `toml:",omitempty"`
|
||||
Raw interface{}
|
||||
Separator string `toml:",omitempty"`
|
||||
Ordered bool `toml:",omitempty"`
|
||||
IgnoreCase bool `toml:",omitempty"`
|
||||
ValidatorRe string `toml:"validator_regexp,omitempty"`
|
||||
Help string `toml:",omitempty"`
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
|
@ -70,13 +71,14 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
errs = append(errs, fmt.Sprintf("%q: flag #%d: separator truncated to %q", path.Base(exercice.Path), nline + 1, flag.Separator))
|
||||
}
|
||||
|
||||
var fitems []string
|
||||
for i, v := range f {
|
||||
if g, ok := v.(string); ok {
|
||||
if strings.Index(g, flag.Separator) != -1 {
|
||||
errs = append(errs, fmt.Sprintf("%q: flag #%d: flag items cannot contain %q character as it is used as separator. Change the separator attribute for this flag.", path.Base(exercice.Path), nline + 1, flag.Separator))
|
||||
continue flags
|
||||
} else {
|
||||
raw += g + flag.Separator
|
||||
fitems = append(fitems, g)
|
||||
}
|
||||
} else {
|
||||
errs = append(errs, fmt.Sprintf("%q: flag #%d, item %d has an invalid type: can only be string, is %T.", path.Base(exercice.Path), nline + 1, i, v))
|
||||
|
@ -84,7 +86,15 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
}
|
||||
}
|
||||
|
||||
flag.Label = "`" + flag.Separator + flag.Label
|
||||
ignord := "t"
|
||||
if flag.Ordered {
|
||||
sort.Strings(fitems)
|
||||
ignord = "f"
|
||||
}
|
||||
|
||||
raw = strings.Join(fitems, flag.Separator) + flag.Separator
|
||||
|
||||
flag.Label = "`" + flag.Separator + ignord + flag.Label
|
||||
} else if f, ok := flag.Raw.(int64); ok {
|
||||
raw = fmt.Sprintf("%d", f)
|
||||
} else if f, ok := flag.Raw.(string); !ok {
|
||||
|
|
|
@ -294,7 +294,10 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
flag.values.splice(i, 1);
|
||||
}
|
||||
|
||||
flag.value = flag.values.join(flag.separator) + flag.separator;
|
||||
if (flag.ignoreorder)
|
||||
flag.value = flag.values.slice().sort().join(flag.separator) + flag.separator;
|
||||
else
|
||||
flag.value = flag.values.join(flag.separator) + flag.separator;
|
||||
|
||||
if (flag.values.length == 0)
|
||||
flag.values = [""];
|
||||
|
|
|
@ -40,6 +40,7 @@ type myTeamFlag struct {
|
|||
Label string `json:"label"`
|
||||
Help string `json:"help,omitempty"`
|
||||
Separator string `json:"separator,omitempty"`
|
||||
IgnoreOrder bool `json:"ignore_order,omitempty"`
|
||||
Solved *time.Time `json:"found,omitempty"`
|
||||
Soluce string `json:"soluce,omitempty"`
|
||||
Choices map[string]string `json:"choices,omitempty"`
|
||||
|
@ -195,9 +196,10 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
flag.Solved = t.HasPartiallySolved(k)
|
||||
}
|
||||
|
||||
if k.Label[0] == '`' && len(k.Label) > 2 {
|
||||
flag.Label = k.Label[2:]
|
||||
if k.Label[0] == '`' && len(k.Label) > 3 {
|
||||
flag.Label = k.Label[3:]
|
||||
flag.Separator = string(k.Label[1])
|
||||
flag.IgnoreOrder = k.Label[2] == 't'
|
||||
} else {
|
||||
flag.Label = k.Label
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user