Prefill public completion form with current timer if present, and allow refresh
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
sto
2026-04-24 09:05:59 +02:00
parent 0bea437b48
commit 1650b22407

View File

@@ -48,19 +48,26 @@
= form.check_box :completed, class: "form-check-input"
= form.label :completed
javascript:
savetime = "";
ispatch = #{method == :patch};
completedEl = document.getElementById('completion_completed');
completedEl.addEventListener('change', (e) => {
const timeEl = document.getElementById('time');
const missingPiecesEl = document.getElementById('missing_pieces');
const remainingPiecesEl = document.getElementById('remaining_pieces');
const refreshEl = document.getElementById('refresh');
if (e.target.checked) {
timeEl.value = '#{@completion.display_time_from_start}';
if (ispatch) timeEl.value = '#{@completion.display_time_from_start}';
else timeEl.value = savetime;
missingPiecesEl.style.display = 'block';
remainingPiecesEl.style.display = 'none';
if (refreshEl) refreshEl.style.display = '';
} else {
savetime = timeEl.value;
timeEl.value = '#{display_time(@contest.duration_seconds)}';
missingPiecesEl.style.display = 'none';
remainingPiecesEl.style.display = 'block';
if (refreshEl) refreshEl.style.display = 'none';
}
})
.row.mb-3
@@ -68,8 +75,32 @@
.form-floating
= form.text_field :display_time_from_start, autocomplete: "off", class: "form-control", id: "time"
= form.label :display_time_from_start, class: "required"
.form-text
= t("activerecord.attributes.completion.display_time_from_start_description")
- unless method == :patch
.col.mt-2
a.btn.btn-primary id="refresh"
= t("helpers.buttons.refresh")
.form-text
= t("activerecord.attributes.completion.display_time_from_start_description")
- if @contest.start_time.present? && method != :patch
javascript:
startTime = #{@contest.start_time.present? ? @contest.start_time.to_i : "null"};
pauseTime = #{@contest.pause_time.present? ? @contest.pause_time.to_i : "null"};
function updateTime() {
const timeEl = document.getElementById('time');
if (timeEl) {
if (startTime) {
let s = Math.floor((Date.now() - 1000 * startTime) / 1000);
if (pauseTime) s = Math.floor(pauseTime - startTime);
let ss = s % 60;
let mm = Math.floor(s / 60) % 60;
let hh = Math.floor(s / 3600);
timeEl.value = `${hh}:${mm < 10 ? `0${mm}` : mm}:${ss < 10 ? `0${ss}` : ss}`;
}
}
}
refreshButton = document.getElementById("refresh");
refreshButton?.addEventListener('click', updateTime);
updateTime();
.row.mb-3 id="missing_pieces"
.col
.form-floating