Implement number flags
This commit is contained in:
parent
30d0afe43f
commit
c3742ade4e
6 changed files with 104 additions and 5 deletions
|
@ -111,13 +111,14 @@ func ExecValidatorRegexp(vre string, val []byte, ignorecase bool) ([]byte, error
|
|||
}
|
||||
|
||||
// AddRawFlagKey creates and fills a new struct FlagKey, from a non-hashed flag, and registers it into the database.
|
||||
func (e Exercice) AddRawFlagKey(name string, placeholder string, ignorecase bool, multiline bool, validator_regexp *string, raw_value []byte, choicescost int64) (f FlagKey, err error) {
|
||||
func (e Exercice) AddRawFlagKey(name string, t string, placeholder string, ignorecase bool, multiline bool, validator_regexp *string, raw_value []byte, choicescost int64) (f FlagKey, err error) {
|
||||
hash, errr := ComputeHashedFlag(raw_value, ignorecase, validator_regexp)
|
||||
if errr != nil {
|
||||
return f, err
|
||||
}
|
||||
|
||||
f = FlagKey{
|
||||
Type: t,
|
||||
Label: name,
|
||||
Placeholder: placeholder,
|
||||
IgnoreCase: ignorecase,
|
||||
|
|
|
@ -46,6 +46,9 @@ type myTeamFlag struct {
|
|||
Justify bool `json:"justify,omitempty"`
|
||||
Choices map[string]interface{} `json:"choices,omitempty"`
|
||||
ChoicesCost int64 `json:"choices_cost,omitempty"`
|
||||
Min *float64 `json:"min,omitempty"`
|
||||
Max *float64 `json:"max,omitempty"`
|
||||
Step *float64 `json:"step,omitempty"`
|
||||
}
|
||||
type myTeamMCQJustifiedChoice struct {
|
||||
Label string `json:"label"`
|
||||
|
@ -204,6 +207,39 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
Help: k.Help,
|
||||
}
|
||||
|
||||
if strings.HasPrefix(flag.Type, "number") {
|
||||
fields := strings.Split(flag.Type, ",")
|
||||
if len(fields) == 4 {
|
||||
flag.Type = fields[0]
|
||||
|
||||
var tmp_min, tmp_max, tmp_step float64
|
||||
|
||||
if len(fields[1]) > 0 {
|
||||
tmp_min, err = strconv.ParseFloat(fields[1], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flag.Min = &tmp_min
|
||||
}
|
||||
|
||||
if len(fields[2]) > 0 {
|
||||
tmp_max, err = strconv.ParseFloat(fields[2], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flag.Max = &tmp_max
|
||||
}
|
||||
|
||||
if len(fields[3]) > 0 {
|
||||
tmp_step, err = strconv.ParseFloat(fields[3], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flag.Step = &tmp_step
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve solved state or solution for public iface
|
||||
if t == nil {
|
||||
flag.IgnoreCase = k.IgnoreCase
|
||||
|
|
Reference in a new issue