From 00e14b7cfffa48bea8847d5d3ad1fa31acf687f8 Mon Sep 17 00:00:00 2001 From: sto Date: Tue, 25 Aug 2026 09:26:29 +0200 Subject: [PATCH] Make asking for missing pieces in forms optional --- app/controllers/contests_controller.rb | 2 +- app/models/contest.rb | 1 + app/views/completions/_form.html.slim | 5 +++-- app/views/contests/settings_onsite_edit.html.slim | 6 +++++- config/locales/en.yml | 1 + config/locales/fr.yml | 1 + db/migrate/20260825071844_add_missing_pieces_to_contest.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories/contests.rb | 1 + 9 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20260825071844_add_missing_pieces_to_contest.rb diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index bc98fa6..9916740 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -328,7 +328,7 @@ class ContestsController < ApplicationController end def settings_onsite_params - params.expect(contest: [ :code, :organizer_form ]) + params.expect(contest: [ :code, :organizer_form, :missing_pieces ]) end def settings_online_params diff --git a/app/models/contest.rb b/app/models/contest.rb index a9840bf..4d2034e 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -8,6 +8,7 @@ # duration :string # duration_seconds :integer # lang :string default("en") +# missing_pieces :boolean # name :string # offline_form :boolean default(FALSE) # organizer_form :boolean diff --git a/app/views/completions/_form.html.slim b/app/views/completions/_form.html.slim index 88a0f12..341fe40 100644 --- a/app/views/completions/_form.html.slim +++ b/app/views/completions/_form.html.slim @@ -78,6 +78,7 @@ javascript: savetime = ""; ispatch = #{method == :patch}; + showMissingPieces = #{@completion.contest.missing_pieces} // Actions for radio buttons. completed_radio_yes_el = document.getElementById('completed_radio_yes'); @@ -90,7 +91,7 @@ if (ispatch) timeEl.value = '#{@completion.display_time_from_start}'; else timeEl.value = savetime; timeEl.parentElement.parentElement.parentElement.style.display = ''; - missingPiecesEl.style.display = 'block'; + if (showMissingPieces) missingPiecesEl.style.display = 'block'; remainingPiecesEl.style.display = 'none'; submitEl.style.display = ''; if (refreshEl) refreshEl.style.display = ''; @@ -150,7 +151,7 @@ updateTime(); / Text field for recording the missing pieces, if any. - .row.mt-3 id="missing_pieces" style="display: #{@completion.completed ? "" : "none"};" + .row.mt-3 id="missing_pieces" style="display: #{@completion.completed && @completion.contest.missing_pieces ? "" : "none"};" .col .form-floating = form.text_field :missing_pieces, autocomplete: "off", class: "form-control" diff --git a/app/views/contests/settings_onsite_edit.html.slim b/app/views/contests/settings_onsite_edit.html.slim index cc60dfd..a8db7f4 100644 --- a/app/views/contests/settings_onsite_edit.html.slim +++ b/app/views/contests/settings_onsite_edit.html.slim @@ -10,13 +10,17 @@ .form-check.form-switch = form.check_box :organizer_form, class: "form-check-input" = form.label :organizer_form - .form-text = t("activerecord.attributes.contest.organizer_form") .row.mt-3.mb-3 .col .form-floating = form.text_field :code, autocomplete: "off", class: "form-control" = form.label :code, class: "required" .form-text = t("activerecord.attributes.contest.code_description") + .row.mt-1 + .col + .form-check.form-switch + = form.check_box :missing_pieces, class: "form-check-input" + = form.label :missing_pieces .row.mt-4 .col = form.submit t("helpers.buttons.update"), class: "btn btn-primary" \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2154d84..a831e85 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -59,6 +59,7 @@ en: duration: Duration duration_description: Format h:mm or hh:mm lang: Language for the public scoreboard + missing_pieces: Ask for missing pieces for completed puzzles name: Name offline_form: Enable the offline participation form offline_form_description: Offline participants will have to fill the form by providing an image taken of the puzzle before starting solving it, and validate their finish time with an upload of an image of the completed puzzle diff --git a/config/locales/fr.yml b/config/locales/fr.yml index ad749a3..662137e 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -30,6 +30,7 @@ fr: duration: Durée duration_description: Format h:mm ou hh:mm lang: Langue pour le classement public + missing_pieces: Demander le nombre de pièces manquantes pour les puzzles complétés name: Nom offline_form: Activer le formulaire de participation hors-ligne offline_form_description: Les participant.e.s hors-ligne pourront participer en prenant une photo du puzzle avant de le commencer, puis valider leur temps avec une photo du puzzle une fois complété diff --git a/db/migrate/20260825071844_add_missing_pieces_to_contest.rb b/db/migrate/20260825071844_add_missing_pieces_to_contest.rb new file mode 100644 index 0000000..22d87be --- /dev/null +++ b/db/migrate/20260825071844_add_missing_pieces_to_contest.rb @@ -0,0 +1,5 @@ +class AddMissingPiecesToContest < ActiveRecord::Migration[8.0] + def change + add_column :contests, :missing_pieces, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 432f5c0..c0eef81 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2026_07_30_055752) do +ActiveRecord::Schema[8.0].define(version: 2026_08_25_071844) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -107,6 +107,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_07_30_055752) do t.boolean "show_stopwatch" t.boolean "organizer_form" t.integer "event_id" + t.boolean "missing_pieces" t.index ["event_id"], name: "index_contests_on_event_id" t.index ["slug"], name: "index_contests_on_slug", unique: true t.index ["user_id"], name: "index_contests_on_user_id" diff --git a/spec/factories/contests.rb b/spec/factories/contests.rb index a8541a8..3a30814 100644 --- a/spec/factories/contests.rb +++ b/spec/factories/contests.rb @@ -8,6 +8,7 @@ # duration :string # duration_seconds :integer # lang :string default("en") +# missing_pieces :boolean # name :string # offline_form :boolean default(FALSE) # organizer_form :boolean