Add NumQuestions and NumAnswersPerQuestion
This commit is contained in:
parent
23fb973590
commit
2aa98c1bbb
9 changed files with 69 additions and 23 deletions
2
Makefile
2
Makefile
|
@ -9,6 +9,6 @@ dev:
|
||||||
docker-compose -f compose/docker-compose_outside_docker.yml down
|
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 db
|
||||||
docker-compose -f compose/docker-compose_outside_docker.yml up -d smtp
|
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
|
all: dockerized
|
||||||
|
|
|
@ -2,6 +2,7 @@ package orm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -21,6 +22,9 @@ type Contest struct {
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
EndTime time.Time
|
EndTime time.Time
|
||||||
|
|
||||||
|
NumQuestions int
|
||||||
|
NumAnswersPerQuestion int
|
||||||
|
|
||||||
Questions []*Question
|
Questions []*Question
|
||||||
Participants []*Participant `gorm:"many2many:subscriptions"`
|
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")
|
date := r.FormValue("Date")
|
||||||
startTime := r.FormValue("StartTime")
|
startTime := r.FormValue("StartTime")
|
||||||
endTime := r.FormValue("EndTime")
|
endTime := r.FormValue("EndTime")
|
||||||
|
log.Println("Zero time", date)
|
||||||
r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
|
if date == "" {
|
||||||
r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
|
r.PostForm.Set("Date", time.Time{}.String())
|
||||||
r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime))
|
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)
|
err = renderer.Decode(contest, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -120,17 +130,16 @@ func (c *Contest) Update(args map[string]string, w http.ResponseWriter, r *http.
|
||||||
startTime := r.FormValue("StartTime")
|
startTime := r.FormValue("StartTime")
|
||||||
endTime := r.FormValue("EndTime")
|
endTime := r.FormValue("EndTime")
|
||||||
|
|
||||||
r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
|
if date == "" {
|
||||||
r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
|
r.PostForm.Set("Date", time.Time{}.Format(time.RFC3339))
|
||||||
r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime))
|
r.PostForm.Set("StartTime", time.Time{}.Format(time.RFC3339))
|
||||||
|
r.PostForm.Set("EndTime", time.Time{}.Format(time.RFC3339))
|
||||||
err = r.ParseForm()
|
} else {
|
||||||
if err != nil {
|
r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime))
|
||||||
return nil, err
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Form["Date"][0] = fmt.Sprintf("%sT%s+00:00", date, startTime)
|
|
||||||
|
|
||||||
err = renderer.Decode(contest, r)
|
err = renderer.Decode(contest, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -2,9 +2,8 @@ package orm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.andreafazzi.eu/andrea/oef/config"
|
"git.andreafazzi.eu/andrea/oef/config"
|
||||||
|
@ -108,7 +107,7 @@ func (model *Participant) AfterSave(tx *gorm.DB) error {
|
||||||
&Response{
|
&Response{
|
||||||
Name: fmt.Sprintf("%s (%s)", contest.Name, model.String()),
|
Name: fmt.Sprintf("%s (%s)", contest.Name, model.String()),
|
||||||
ContestID: contest.ID,
|
ContestID: contest.ID,
|
||||||
ParticipantID: model.UserID,
|
ParticipantID: model.ID,
|
||||||
}).Error; err != nil {
|
}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,12 @@ type School struct {
|
||||||
Code string
|
Code string
|
||||||
EmailSentDate time.Time
|
EmailSentDate time.Time
|
||||||
|
|
||||||
|
SchoolResponsibleLastname string
|
||||||
|
SchoolResponsibleFirstname string
|
||||||
|
|
||||||
|
ContestResponsibleLastname string
|
||||||
|
ContestResponsibleFirstname string
|
||||||
|
|
||||||
UserID uint
|
UserID uint
|
||||||
RegionID uint `schema:"region_id"`
|
RegionID uint `schema:"region_id"`
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package orm
|
package orm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/dgrijalva/jwt-go"
|
"github.com/dgrijalva/jwt-go"
|
||||||
|
@ -74,7 +73,6 @@ func NewUserModifierUpdate(r *http.Request) *UserModifierUpdate {
|
||||||
if r.Context().Value("user") != nil {
|
if r.Context().Value("user") != nil {
|
||||||
claims = r.Context().Value("user").(*jwt.Token).Claims.(jwt.MapClaims)
|
claims = r.Context().Value("user").(*jwt.Token).Claims.(jwt.MapClaims)
|
||||||
}
|
}
|
||||||
log.Println("UPDATE Inside useraction", claims["user_id"])
|
|
||||||
return &UserModifierUpdate{
|
return &UserModifierUpdate{
|
||||||
UpdaterID: claims["user_id"].(string),
|
UpdaterID: claims["user_id"].(string),
|
||||||
UpdaterRole: claims["role"].(string),
|
UpdaterRole: claims["role"].(string),
|
||||||
|
|
|
@ -28,6 +28,7 @@ var (
|
||||||
"prettyDate": prettyDate,
|
"prettyDate": prettyDate,
|
||||||
"prettyTime": prettyTime,
|
"prettyTime": prettyTime,
|
||||||
"prettyDateTime": prettyDateTime,
|
"prettyDateTime": prettyDateTime,
|
||||||
|
"zeroTime": zeroTime,
|
||||||
"modelPath": modelPath,
|
"modelPath": modelPath,
|
||||||
"dict": dict,
|
"dict": dict,
|
||||||
"yaml": yaml,
|
"yaml": yaml,
|
||||||
|
@ -270,6 +271,10 @@ func prettyTime(value interface{}) string {
|
||||||
return convertTime(value)
|
return convertTime(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func zeroTime(t *time.Time) bool {
|
||||||
|
return *t == time.Time{}
|
||||||
|
}
|
||||||
|
|
||||||
func modelPath(model string, action string, id uint) string {
|
func modelPath(model string, action string, id uint) string {
|
||||||
var q template.URL
|
var q template.URL
|
||||||
|
|
||||||
|
|
|
@ -323,6 +323,7 @@ func Decode(dst interface{}, r *http.Request) error {
|
||||||
|
|
||||||
case "html":
|
case "html":
|
||||||
var timeConverter = func(value string) reflect.Value {
|
var timeConverter = func(value string) reflect.Value {
|
||||||
|
log.Println(value)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
return reflect.ValueOf(time.Time{})
|
return reflect.ValueOf(time.Time{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
{{if $update}}
|
{{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}}
|
{{else}}
|
||||||
{{template "breadcrumb" toSlice "Contests" (all "Contest") "Aggiungi" "current"}}
|
{{template "breadcrumb" toSlice "Gare" (all "Contest") "Aggiungi" "current"}}
|
||||||
{{end}}
|
{{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 := "form_add_update"}}
|
||||||
<form
|
<form
|
||||||
class="needs-validation"
|
class="needs-validation"
|
||||||
|
@ -37,6 +37,17 @@
|
||||||
</div>
|
</div>
|
||||||
</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" }`}}
|
{{$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}}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,24 @@
|
||||||
{{template "show_header" dict "title" (.Data|string) "updatePath" (.Data.ID|update "Contest") "deletePath" (.Data.ID|delete "Contest")}}
|
{{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>
|
<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="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue