diff --git a/orm/contest.go b/orm/contest.go index 44cfb6dd..7ae62b59 100644 --- a/orm/contest.go +++ b/orm/contest.go @@ -31,8 +31,12 @@ type Contest struct { NumQuestions int NumAnswersPerQuestion int + ResetStartTime bool + Questions []*Question Participants []*Participant `gorm:"many2many:subscriptions"` + + prevStartTime time.Time } 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 } + // FIXME: Should not be hard set. + contest.(*Contest).ResetStartTime = false + err = r.ParseForm() if err != nil { return nil, err @@ -154,10 +161,21 @@ func (c *Contest) Update(db *Database, args map[string]string, w http.ResponseWr if err != nil { return nil, err } + contest, err = c.Read(db, args, w, r) if err != nil { 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 } } diff --git a/templates/contests_add_update.html.tpl b/templates/contests_add_update.html.tpl index ee6cb9ef..c3452755 100644 --- a/templates/contests_add_update.html.tpl +++ b/templates/contests_add_update.html.tpl @@ -54,6 +54,15 @@ {{template "input" dict "options" ($options|yaml) "value" (.Data|field "NumAnswersPerQuestion") "update" $update}} + + {{if $update}} +
+
+ {{$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}} +
+
+ {{end}} {{$options := ` { cancelTitle: "Annulla", saveTitle: "Salva", model: "Contest" }`}} {{template "submit_cancel_buttons" dict "options" ($options|yaml) "id" (.Data|field "ID") "update" $update}}