Implement missing & remaining pieces propagation + cleaner forms
This commit is contained in:
@@ -32,17 +32,55 @@
|
||||
- else
|
||||
= form.hidden_field :puzzle_id
|
||||
.row.mb-3
|
||||
.col
|
||||
.form-check.form-switch
|
||||
= form.check_box :completed, class: "form-check-input"
|
||||
= form.label :completed
|
||||
javascript:
|
||||
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');
|
||||
if (e.target.checked) {
|
||||
timeEl.style.display = 'block';
|
||||
missingPiecesEl.style.display = 'block';
|
||||
remainingPiecesEl.style.display = 'none';
|
||||
} else {
|
||||
timeEl.style.display = 'none';
|
||||
missingPiecesEl.style.display = 'none';
|
||||
remainingPiecesEl.style.display = 'block';
|
||||
}
|
||||
})
|
||||
.row.mb-3 id="time"
|
||||
.col
|
||||
.form-floating
|
||||
= form.text_field :display_time_from_start, autocomplete: "off", class: "form-control"
|
||||
= form.label :display_time_from_start, class: "required"
|
||||
.row.mb-3
|
||||
.row.mb-3 id="missing_pieces"
|
||||
.col
|
||||
.form-floating
|
||||
= form.text_field :missing_pieces, autocomplete: "off", class: "form-control"
|
||||
= form.label :missing_pieces
|
||||
.row.mb-3 id="remaining_pieces" style="display: none;"
|
||||
.col
|
||||
.form-floating
|
||||
= form.text_field :remaining_pieces, autocomplete: "off", class: "form-control"
|
||||
= form.label :remaining_pieces
|
||||
.form-text
|
||||
= t("activerecord.attributes.completion.remaining_pieces_description")
|
||||
javascript:
|
||||
completedEl = document.getElementById('completion_completed');
|
||||
timeEl = document.getElementById('time');
|
||||
missingPiecesEl = document.getElementById('missing_pieces');
|
||||
remainingPiecesEl = document.getElementById('remaining_pieces');
|
||||
if (completedEl.checked) {
|
||||
timeEl.style.display = 'block';
|
||||
missingPiecesEl.style.display = 'block';
|
||||
remainingPiecesEl.style.display = 'none';
|
||||
} else {
|
||||
timeEl.style.display = 'none';
|
||||
missingPiecesEl.style.display = 'none';
|
||||
remainingPiecesEl.style.display = 'block';
|
||||
}
|
||||
.row
|
||||
.col
|
||||
= form.submit submit_text, class: "btn btn-primary"
|
||||
@@ -33,6 +33,10 @@
|
||||
.row.mt-5
|
||||
.col
|
||||
h3 Completions
|
||||
.row
|
||||
.col
|
||||
.alert.alert-info
|
||||
= t("contestants.edit.completions_note")
|
||||
table.table.table-striped.table-hover
|
||||
thead
|
||||
tr
|
||||
@@ -44,6 +48,8 @@
|
||||
- else
|
||||
th scope="col"
|
||||
= t("activerecord.attributes.completion.display_time")
|
||||
th scope="col"
|
||||
= t("activerecord.attributes.completion.missing_pieces")
|
||||
th scope="col"
|
||||
= t("activerecord.attributes.completion.remaining_pieces")
|
||||
th scope="col"
|
||||
@@ -56,6 +62,8 @@
|
||||
- if @contest.puzzles.size > 1
|
||||
td
|
||||
= completion.display_relative_time
|
||||
td
|
||||
= completion.missing_pieces
|
||||
td
|
||||
= completion.remaining_pieces
|
||||
td
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
= form_with model: @offline, url: "/public/#{@contest.friendly_id}/offline/#{@offline.generate_token_for(:token)}" do |form|
|
||||
= form.hidden_field :completed
|
||||
h3 = t("offlines.form.start_message")
|
||||
h3 = t("offlines.form.start_message", name: @offline.name)
|
||||
h1 id="display-time" style="font-size: 80px;"
|
||||
javascript:
|
||||
const startTime = #{@offline.start_time.to_i};
|
||||
startTime = #{@offline.start_time.to_i};
|
||||
function updateTime() {
|
||||
const displayTimeEl = document.getElementById('display-time');
|
||||
const s = Math.floor((Date.now() - 1000 * startTime) / 1000);
|
||||
let ss = s % 60;
|
||||
let mm = Math.floor(s / 60) % 60;
|
||||
let hh = Math.floor(s / 3600);
|
||||
displayTimeEl.innerHTML = `${hh < 10 ? `0${hh}` : hh}:${mm < 10 ? `0${mm}` : mm}:${ss < 10 ? `0${ss}` : ss}`;
|
||||
setTimeout(updateTime, 1000);
|
||||
if (displayTimeEl) {
|
||||
const s = Math.floor((Date.now() - 1000 * startTime) / 1000);
|
||||
let ss = s % 60;
|
||||
let mm = Math.floor(s / 60) % 60;
|
||||
let hh = Math.floor(s / 3600);
|
||||
displayTimeEl.innerHTML = `${hh < 10 ? `0${hh}` : hh}:${mm < 10 ? `0${mm}` : mm}:${ss < 10 ? `0${ss}` : ss}`;
|
||||
setTimeout(updateTime, 1000);
|
||||
} else {
|
||||
setTimeout(updateTime, 20);
|
||||
}
|
||||
}
|
||||
setTimeout(updateTime, 50);
|
||||
setTimeout(updateTime, 1);
|
||||
.row.mt-5.mb-3
|
||||
.col
|
||||
.form-text.mb-1
|
||||
@@ -35,20 +38,49 @@
|
||||
}
|
||||
|
||||
setMaxUploadSize();
|
||||
.row.mt-4.mb-3
|
||||
.row.mb-3
|
||||
.col
|
||||
.form-check.form-switch
|
||||
= form.check_box :completed, class: "form-check-input"
|
||||
= form.label :completed
|
||||
javascript:
|
||||
completedEl = document.getElementById('offline_completed');
|
||||
completedEl.addEventListener('change', (e) => {
|
||||
missingPiecesEl = document.getElementById('missing_pieces');
|
||||
remainingPiecesEl = document.getElementById('remaining_pieces');
|
||||
if (e.target.checked) {
|
||||
missingPiecesEl.style.display = 'block';
|
||||
remainingPiecesEl.style.display = 'none';
|
||||
} else {
|
||||
missingPiecesEl.style.display = 'none';
|
||||
remainingPiecesEl.style.display = 'block';
|
||||
}
|
||||
})
|
||||
.row.mb-3 id="missing_pieces" style="display: none;"
|
||||
.col
|
||||
.form-floating
|
||||
= form.text_field :missing_pieces, autocomplete: "off", class: "form-control"
|
||||
= form.label :missing_pieces
|
||||
.form-text
|
||||
= t("offlines.form.missing_pieces")
|
||||
.row.mb-3
|
||||
.row.mb-3 id="remaining_pieces"
|
||||
.col
|
||||
.form-floating
|
||||
= form.text_field :remaining_pieces, autocomplete: "off", class: "form-control"
|
||||
= form.label :remaining_pieces
|
||||
.form-text
|
||||
= t("offlines.form.remaining_pieces")
|
||||
javascript:
|
||||
completedEl = document.getElementById('offline_completed');
|
||||
missingPiecesEl = document.getElementById('missing_pieces');
|
||||
remainingPiecesEl = document.getElementById('remaining_pieces');
|
||||
if (completedEl.checked) {
|
||||
missingPiecesEl.style.display = 'block';
|
||||
remainingPiecesEl.style.display = 'none';
|
||||
} else {
|
||||
missingPiecesEl.style.display = 'none';
|
||||
remainingPiecesEl.style.display = 'block';
|
||||
}
|
||||
.row.mt-4
|
||||
.col
|
||||
= form.submit t("helpers.buttons.end"), class: "btn btn-primary"
|
||||
Reference in New Issue
Block a user