Fix countdown and reset response StartTime when len(SingleResponses) is zero
This commit is contained in:
parent
52b572dc25
commit
eaa9c405aa
4 changed files with 28 additions and 7 deletions
12
dist/main.bundle.js
vendored
12
dist/main.bundle.js
vendored
File diff suppressed because one or more lines are too long
|
@ -240,7 +240,7 @@ func (model *Response) Update(db *Database, args map[string]string, w http.Respo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the contest is still active
|
// Check if the contest is still active
|
||||||
if !response.(*Response).IsActive() {
|
if isParticipant(r) && !response.(*Response).IsActive() {
|
||||||
return nil, errors.OutOfTime
|
return nil, errors.OutOfTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,6 +251,14 @@ func (model *Response) Update(db *Database, args map[string]string, w http.Respo
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there aren't single responses then participant
|
||||||
|
// response Starttime is resetted.
|
||||||
|
if isAdministrator(r) {
|
||||||
|
if len(response.(*Response).SingleResponses) == 0 {
|
||||||
|
response.(*Response).StartTime = time.Time{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WriteUpdater(r, response.(*Response))
|
WriteUpdater(r, response.(*Response))
|
||||||
|
|
||||||
_, err = SaveResponse(db, response)
|
_, err = SaveResponse(db, response)
|
||||||
|
|
10
src/index.js
10
src/index.js
|
@ -2,7 +2,7 @@ import './style.css'
|
||||||
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
var timeleft = parseInt($("#timeleft").html());
|
var timeleft = parseInt($("#timeleft").html());
|
||||||
if (timeleft > 0) {
|
if (timeleft > 0) {
|
||||||
|
@ -10,7 +10,13 @@ $(function () {
|
||||||
} else {
|
} else {
|
||||||
timeleft = 0;
|
timeleft = 0;
|
||||||
}
|
}
|
||||||
$("#timeleft").html(timeleft)
|
|
||||||
|
$("#timeleft").html(timeleft);
|
||||||
|
|
||||||
|
var minutes = Math.floor(timeleft/60);
|
||||||
|
var seconds = timeleft % 60;
|
||||||
|
|
||||||
|
$("#timeleft_view").html(minutes+":"+seconds.toString().padStart(2, "0"));
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
$("#reloadCaptcha").on("click",function(eventObject) {
|
$("#reloadCaptcha").on("click",function(eventObject) {
|
||||||
|
|
|
@ -71,7 +71,8 @@
|
||||||
<dt>Gara</dt><dd>{{.Data.Contest}}</dd>
|
<dt>Gara</dt><dd>{{.Data.Contest}}</dd>
|
||||||
<dt>Partecipante</dt><dd>{{.Data.Participant}}</dd>
|
<dt>Partecipante</dt><dd>{{.Data.Participant}}</dd>
|
||||||
{{- if $isParticipant -}}
|
{{- if $isParticipant -}}
|
||||||
<dt>Tempo rimanente</dt>{{if .Data.TimeLeft}}<dd><span id="timeleft">{{.Data.TimeLeft.Seconds|toInt}}</span> secondi rimanenti</dd>{{else}}<dd>La gara è sempre attiva</dd>{{end}}
|
<span id="timeleft" style="display: none">{{.Data.TimeLeft.Seconds|toInt}}</span>
|
||||||
|
<dt>Tempo rimanente</dt>{{if .Data.TimeLeft}}<dd><span id="timeleft_view"></span> minuti rimanenti</dd>{{else}}<dd>La gara è sempre attiva</dd>{{end}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</dl>
|
</dl>
|
||||||
<button type="submit" class="btn btn-primary" form="{{$form}}">Salva</button>
|
<button type="submit" class="btn btn-primary" form="{{$form}}">Salva</button>
|
||||||
|
|
Loading…
Reference in a new issue