Add NumQuestions and NumAnswersPerQuestion

This commit is contained in:
Andrea Fazzi 2019-12-13 08:32:20 +01:00
parent 23fb973590
commit 2aa98c1bbb
9 changed files with 69 additions and 23 deletions

View file

@ -9,6 +9,6 @@ dev:
docker-compose -f compose/docker-compose_outside_docker.yml down
docker-compose -f compose/docker-compose_outside_docker.yml up -d db
docker-compose -f compose/docker-compose_outside_docker.yml up -d smtp
go run main.go --config=config/config_outside_docker.yaml &
go run -race main.go --config=config/config_outside_docker.yaml &
all: dockerized

View file

@ -2,6 +2,7 @@ package orm
import (
"fmt"
"log"
"net/http"
"time"
@ -21,6 +22,9 @@ type Contest struct {
StartTime time.Time
EndTime time.Time
NumQuestions int
NumAnswersPerQuestion int
Questions []*Question
Participants []*Participant `gorm:"many2many:subscriptions"`
}
@ -45,10 +49,16 @@ func (c *Contest) Create(args map[string]string, w http.ResponseWriter, r *http.
date := r.FormValue("Date")
startTime := r.FormValue("StartTime")
endTime := r.FormValue("EndTime")
log.Println("Zero time", date)
if date == "" {
r.PostForm.Set("Date", time.Time{}.String())
r.PostForm.Set("StartTime", time.Time{}.String())
r.PostForm.Set("EndTime", time.Time{}.String())
} else {
r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime))
}
err = renderer.Decode(contest, r)
if err != nil {
@ -120,17 +130,16 @@ func (c *Contest) Update(args map[string]string, w http.ResponseWriter, r *http.
startTime := r.FormValue("StartTime")
endTime := r.FormValue("EndTime")
if date == "" {
r.PostForm.Set("Date", time.Time{}.Format(time.RFC3339))
r.PostForm.Set("StartTime", time.Time{}.Format(time.RFC3339))
r.PostForm.Set("EndTime", time.Time{}.Format(time.RFC3339))
} else {
r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime))
err = r.ParseForm()
if err != nil {
return nil, err
}
r.Form["Date"][0] = fmt.Sprintf("%sT%s+00:00", date, startTime)
err = renderer.Decode(contest, r)
if err != nil {
return nil, err

View file

@ -2,9 +2,8 @@ package orm
import (
"fmt"
"strconv"
"net/http"
"strconv"
"strings"
"git.andreafazzi.eu/andrea/oef/config"
@ -108,7 +107,7 @@ func (model *Participant) AfterSave(tx *gorm.DB) error {
&Response{
Name: fmt.Sprintf("%s (%s)", contest.Name, model.String()),
ContestID: contest.ID,
ParticipantID: model.UserID,
ParticipantID: model.ID,
}).Error; err != nil {
return err
}

View file

@ -24,6 +24,12 @@ type School struct {
Code string
EmailSentDate time.Time
SchoolResponsibleLastname string
SchoolResponsibleFirstname string
ContestResponsibleLastname string
ContestResponsibleFirstname string
UserID uint
RegionID uint `schema:"region_id"`

View file

@ -1,7 +1,6 @@
package orm
import (
"log"
"net/http"
"github.com/dgrijalva/jwt-go"
@ -74,7 +73,6 @@ func NewUserModifierUpdate(r *http.Request) *UserModifierUpdate {
if r.Context().Value("user") != nil {
claims = r.Context().Value("user").(*jwt.Token).Claims.(jwt.MapClaims)
}
log.Println("UPDATE Inside useraction", claims["user_id"])
return &UserModifierUpdate{
UpdaterID: claims["user_id"].(string),
UpdaterRole: claims["role"].(string),

View file

@ -28,6 +28,7 @@ var (
"prettyDate": prettyDate,
"prettyTime": prettyTime,
"prettyDateTime": prettyDateTime,
"zeroTime": zeroTime,
"modelPath": modelPath,
"dict": dict,
"yaml": yaml,
@ -270,6 +271,10 @@ func prettyTime(value interface{}) string {
return convertTime(value)
}
func zeroTime(t *time.Time) bool {
return *t == time.Time{}
}
func modelPath(model string, action string, id uint) string {
var q template.URL

View file

@ -323,6 +323,7 @@ func Decode(dst interface{}, r *http.Request) error {
case "html":
var timeConverter = func(value string) reflect.Value {
log.Println(value)
if value == "" {
return reflect.ValueOf(time.Time{})
}

View file

@ -5,12 +5,12 @@
{{if $update}}
{{template "breadcrumb" toSlice "Contests" (all "Contest") (.Data|string) (.Data.ID|show "Contest") "Aggiorna" "current"}}
{{template "breadcrumb" toSlice "Gare" (all "Contest") (.Data|string) (.Data.ID|show "Contest") "Aggiorna" "current"}}
{{else}}
{{template "breadcrumb" toSlice "Contests" (all "Contest") "Aggiungi" "current"}}
{{template "breadcrumb" toSlice "Gare" (all "Contest") "Aggiungi" "current"}}
{{end}}
{{template "add_update_header" dict "update" $update "addTitle" "Crea nuovo ELEMENTO" "updateTitle" (printf "Aggiorna gara %s" (.Data|string))}}
{{template "add_update_header" dict "update" $update "addTitle" "Crea nuova gara" "updateTitle" (printf "Aggiorna gara %s" (.Data|string))}}
{{$form := "form_add_update"}}
<form
class="needs-validation"
@ -37,6 +37,17 @@
</div>
</div>
<div class="form-row">
<div class="col">
{{$options := ` { name: "NumQuestions",id: "contest_num_questions",label: "Numero totale delle domande presenti nella gara",placeholder: "Inserire il numero delle domande",type: "number",required: "true"} `}}
{{template "input" dict "options" ($options|yaml) "value" (.Data|field "NumQuestions") "update" $update}}
</div>
<div class="col">
{{$options := ` { name: "NumAnswersPerQuestion",id: "contest_num_answers_per_question",label: "Numero delle risposte per domanda",placeholder: "Inserire il numero delle risposte per domanda",type: "number",required: "true"} `}}
{{template "input" dict "options" ($options|yaml) "value" (.Data|field "NumAnswersPerQuestion") "update" $update}}
</div>
</div>
{{$options := ` { cancelTitle: "Annulla", saveTitle: "Salva", model: "Contest" }`}}
{{template "submit_cancel_buttons" dict "options" ($options|yaml) "id" (.Data|field "ID") "update" $update}}

View file

@ -6,7 +6,24 @@
{{template "show_header" dict "title" (.Data|string) "updatePath" (.Data.ID|update "Contest") "deletePath" (.Data.ID|delete "Contest")}}
<h2 class="karmen-relation-header">Informazioni generali sulla gara</h2>
<p>La gara si svolgerà il giorno <strong>{{.Data.Date|prettyDate}}</strong> dalle ore <strong>{{.Data.StartTime|convertTime}}</strong> alle ore <strong>{{.Data.EndTime|convertTime}}</strong>.</p>
<dl class="row">
<dt class="col-sm-3">Periodo di attività</dt>
<dd class="col-sm-9">
{{if not (.Data.Date|zeroTime)}}
La gara si svolgerà il giorno {{.Data.Date|prettyDate}} dalle ore {{.Data.StartTime|convertTime}} alle ore {{.Data.EndTime|convertTime}}
{{else}}
La gara è sempre attiva
{{end}}
</dd>
<dt class="col-sm-3">Numero di domande</dt>
<dd class="col-sm-9">{{.Data.NumQuestions}}</dd>
<dt class="col-sm-3">Numero di risposte per domanda</dt>
<dd class="col-sm-9">{{.Data.NumAnswersPerQuestion}}</dd>
</dl>
<div class="row">
<div class="col-md-12">