sync: introducing showlines property for vectors
It allows players to know in advance how many items the vector is composed.
This commit is contained in:
parent
a545112cb2
commit
b4fa57f9c9
4 changed files with 35 additions and 9 deletions
|
@ -35,6 +35,7 @@ type ExerciceFlag struct {
|
|||
Type string `toml:",omitempty"`
|
||||
Raw interface{}
|
||||
Separator string `toml:",omitempty"`
|
||||
ShowLines bool `toml:",omitempty"`
|
||||
Ordered bool `toml:",omitempty"`
|
||||
CaseSensitive bool `toml:",omitempty"`
|
||||
ValidatorRe string `toml:"validator_regexp,omitempty"`
|
||||
|
|
|
@ -34,7 +34,7 @@ func validatorRegexp(vre string) (validator_regexp *string) {
|
|||
return
|
||||
}
|
||||
|
||||
func getRawKey(input interface{}, validatorRe string, ordered bool) (raw string, prep string, errs []string) {
|
||||
func getRawKey(input interface{}, validatorRe string, ordered bool, showLines bool) (raw string, prep string, errs []string) {
|
||||
separator := ","
|
||||
|
||||
// Concatenate array
|
||||
|
@ -71,9 +71,19 @@ func getRawKey(input interface{}, validatorRe string, ordered bool) (raw string,
|
|||
sort.Strings(fitems)
|
||||
ignord = "t"
|
||||
}
|
||||
|
||||
nbLines := 0
|
||||
if showLines {
|
||||
if len(fitems) > 9 {
|
||||
errs = append(errs, "too much items in vector to use ShowLines features, max 9.")
|
||||
} else {
|
||||
nbLines = len(fitems)
|
||||
}
|
||||
}
|
||||
|
||||
raw = strings.Join(fitems, separator) + separator
|
||||
|
||||
prep = "`" + separator + ignord
|
||||
prep = fmt.Sprintf("`%s%s%d", separator, ignord, nbLines)
|
||||
} else if f, ok := input.(int64); ok {
|
||||
raw = fmt.Sprintf("%d", f)
|
||||
} else if f, ok := input.(string); !ok {
|
||||
|
@ -95,7 +105,7 @@ func buildKeyFlag(exercice fic.Exercice, flag ExerciceFlag, flagline int, defaul
|
|||
flag.Label = flag.Label[1:]
|
||||
}
|
||||
|
||||
raw, prep, terrs := getRawKey(flag.Raw, flag.ValidatorRe, flag.Ordered)
|
||||
raw, prep, terrs := getRawKey(flag.Raw, flag.ValidatorRe, flag.Ordered, flag.ShowLines)
|
||||
|
||||
if len(terrs) > 0 {
|
||||
for _, err := range terrs {
|
||||
|
@ -137,7 +147,7 @@ func buildKeyFlag(exercice fic.Exercice, flag ExerciceFlag, flagline int, defaul
|
|||
}
|
||||
|
||||
for _, choice := range flag.Choice {
|
||||
val, prep, terrs := getRawKey(choice.Value, "", false)
|
||||
val, prep, terrs := getRawKey(choice.Value, "", false, false)
|
||||
if len(terrs) > 0 {
|
||||
for _, err := range terrs {
|
||||
errs = append(errs, fmt.Sprintf("%q: flag #%d: %s", path.Base(exercice.Path), flagline, err))
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
var alertNbLines = true;
|
||||
|
||||
function treatFlagKey(flag) {
|
||||
if (flag.values !== undefined) {
|
||||
if (flag.separator) {
|
||||
for (var i = flag.values.length - 1; i >= 0; i--) {
|
||||
if (!flag.values[i].length)
|
||||
flag.values.splice(i, 1);
|
||||
if (flag.nb_lines && (flag.values[i] == undefined || !flag.values[i].length)) {
|
||||
if (alertNbLines) {
|
||||
alertNbLines = false;
|
||||
if (!confirm("Lorsque plusieurs flags sont attendus pour une même question, ceux-ci ne sont pas validés un par un. Ils ne sont validés qu'une fois tous les champs remplis correctement. (Sauf mention contraire, l'ordre n'importe pas)"))
|
||||
console.log(flag.values[9999].length); // Launch exception here to avoid form validation
|
||||
}
|
||||
}
|
||||
else if (!flag.values[i].length) {
|
||||
flag.values.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (flag.ignore_order)
|
||||
|
@ -123,7 +133,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
Liste de propositions (<ng-pluralize count="$ctrl.key.choices_cost * $ctrl.settings.wchoiceCurrentCoefficient" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize>)
|
||||
</button>
|
||||
</div>
|
||||
<div class="input-group-append" ng-if="$ctrl.key.separator && $last">
|
||||
<div class="input-group-append" ng-if="$ctrl.key.separator && !$ctrl.key.nb_lines && $last">
|
||||
<button class="btn btn-success" type="button" ng-click="$ctrl.additem(key)" title="Ajouter un élément.">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
</button>
|
||||
|
@ -357,6 +367,8 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
data.exercices[eid].flags[fid].value = $scope.my.exercices[eid].flags[fid].value;
|
||||
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].flags && $scope.my.exercices[eid].flags[fid] && $scope.my.exercices[eid].flags[fid].values !== undefined)
|
||||
data.exercices[eid].flags[fid].values = $scope.my.exercices[eid].flags[fid].values;
|
||||
else if (data.exercices[eid].flags[fid].nb_lines)
|
||||
data.exercices[eid].flags[fid].values = Array(data.exercices[eid].flags[fid].nb_lines);
|
||||
else
|
||||
data.exercices[eid].flags[fid].values = [""];
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
@ -29,6 +30,7 @@ type myTeamFlag struct {
|
|||
Label string `json:"label"`
|
||||
Help string `json:"help,omitempty"`
|
||||
Separator string `json:"separator,omitempty"`
|
||||
NbLines uint64 `json:"nb_lines,omitempty"`
|
||||
IgnoreOrder bool `json:"ignore_order,omitempty"`
|
||||
IgnoreCase bool `json:"ignore_case,omitempty"`
|
||||
ValidatorRe *string `json:"validator_regexp,omitempty"`
|
||||
|
@ -205,10 +207,11 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
}
|
||||
|
||||
// Treat array flags
|
||||
if k.Label[0] == '`' && len(k.Label) > 3 {
|
||||
flag.Label = k.Label[3:]
|
||||
if k.Label[0] == '`' && len(k.Label) > 4 {
|
||||
flag.Label = k.Label[4:]
|
||||
flag.Separator = string(k.Label[1])
|
||||
flag.IgnoreOrder = k.Label[2] == 't'
|
||||
flag.NbLines, _ = strconv.ParseUint(string(k.Label[3]), 10, 8)
|
||||
} else {
|
||||
flag.Label = k.Label
|
||||
}
|
||||
|
|
Reference in a new issue