Add flag to reset StartTime value
This commit is contained in:
parent
93b940eb08
commit
36eed0709c
2 changed files with 27 additions and 0 deletions
|
@ -31,8 +31,12 @@ type Contest struct {
|
||||||
NumQuestions int
|
NumQuestions int
|
||||||
NumAnswersPerQuestion int
|
NumAnswersPerQuestion int
|
||||||
|
|
||||||
|
ResetStartTime bool
|
||||||
|
|
||||||
Questions []*Question
|
Questions []*Question
|
||||||
Participants []*Participant `gorm:"many2many:subscriptions"`
|
Participants []*Participant `gorm:"many2many:subscriptions"`
|
||||||
|
|
||||||
|
prevStartTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Contest) GetID() uint { return c.ID }
|
func (c *Contest) GetID() uint { return c.ID }
|
||||||
|
@ -127,6 +131,9 @@ func (c *Contest) Update(db *Database, args map[string]string, w http.ResponseWr
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Should not be hard set.
|
||||||
|
contest.(*Contest).ResetStartTime = false
|
||||||
|
|
||||||
err = r.ParseForm()
|
err = r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -154,10 +161,21 @@ func (c *Contest) Update(db *Database, args map[string]string, w http.ResponseWr
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
contest, err = c.Read(db, args, w, r)
|
contest, err = c.Read(db, args, w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optionally reset participant start time
|
||||||
|
if contest.(*Contest).ResetStartTime {
|
||||||
|
err := db._db.Debug().Model(&Response{}).Where("contest_id=?", contest.(*Contest).ID).Update("start_time", time.Time{}).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return contest.(*Contest), nil
|
return contest.(*Contest), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,15 @@
|
||||||
{{template "input" dict "options" ($options|yaml) "value" (.Data|field "NumAnswersPerQuestion") "update" $update}}
|
{{template "input" dict "options" ($options|yaml) "value" (.Data|field "NumAnswersPerQuestion") "update" $update}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{if $update}}
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="col">
|
||||||
|
{{$options := ` { name: "ResetStartTime",id: "contest_reset_start_time",label: "Resetta la prima eventuale visualizzazione dei partecipanti",formClass: "form-check form-check-inline" } `}}
|
||||||
|
{{template "checkbox" dict "options" ($options|yaml) "value" (.Data|field "ResetStartTime") "update" $update}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{$options := ` { cancelTitle: "Annulla", saveTitle: "Salva", model: "Contest" }`}}
|
{{$options := ` { cancelTitle: "Annulla", saveTitle: "Salva", model: "Contest" }`}}
|
||||||
{{template "submit_cancel_buttons" dict "options" ($options|yaml) "id" (.Data|field "ID") "update" $update}}
|
{{template "submit_cancel_buttons" dict "options" ($options|yaml) "id" (.Data|field "ID") "update" $update}}
|
||||||
|
|
Loading…
Reference in a new issue