From 3b433b8a9dcf2cdd4918e337cd1823d9c8bdb4ba Mon Sep 17 00:00:00 2001 From: sto Date: Sat, 12 Sep 2026 08:48:59 +0200 Subject: [PATCH] Worlds: stop bets at midnight before the start of the competition --- app/controllers/worlds_controller.rb | 3 + app/views/worlds/new.html.slim | 82 +++++++++++++++------------- config/locales/en.yml | 1 + config/locales/fr.yml | 1 + 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/app/controllers/worlds_controller.rb b/app/controllers/worlds_controller.rb index b7b0a5d..174d15d 100644 --- a/app/controllers/worlds_controller.rb +++ b/app/controllers/worlds_controller.rb @@ -66,6 +66,9 @@ class WorldsController < ApplicationController def create authorize :world_bet + if DateTime.now > Time.new(2026, 9, 16, 23, 59, 59, "+02:00") + redirect_to "/wjpc_bets/#{@lang}/new" and return + end @world_bet = WorldBet.new(world_bet_params) @world_bet.score = 0 diff --git a/app/views/worlds/new.html.slim b/app/views/worlds/new.html.slim index 6c0c465..5a7bd40 100644 --- a/app/views/worlds/new.html.slim +++ b/app/views/worlds/new.html.slim @@ -1,48 +1,52 @@ = render "worlds_nav" -.alert.alert-warning role="alert" - = t("worlds.about.one_bet_message") +- if DateTime.now > Time.new(2026, 9, 16, 23, 59, 59, "+02:00") + .alert.alert-warning role="alert" + = t("worlds.new.too_late_message") +- else + .alert.alert-warning role="alert" + = t("worlds.about.one_bet_message") -= form_with model: @world_bet, url: "/wjpc_bets/#{@lang}/new", method: :post do |form| - .alert.alert-primary role="alert" - = t("worlds.new.message") - - .row.mt-4 - .col - .form-floating - = form.text_field :name, autocomplete: "off", class: "form-control" - = form.label :name, class: "required" - - .row.mt-4 - .col - h4 = t("worlds.new.world_section") - - - (1..10).each do |i| - .row.mt-3 + = form_with model: @world_bet, url: "/wjpc_bets/#{@lang}/new", method: :post do |form| + .alert.alert-primary role="alert" + = t("worlds.new.message") + + .row.mt-4 .col - .input-group - .input-group-text ##{i} (x#{WorldBet.multiplier(i - 1)}) - = form.select "w_bet_#{i}", @world_participants.map { |p| [Flags.get_flag(p.world_country.code) + " " + p.name, p.id] }, {}, class: "form-select" + .form-floating + = form.text_field :name, autocomplete: "off", class: "form-control" + = form.label :name, class: "required" - .row.mt-4 - .col - h4 = t("worlds.new.french_section") - - - (1..10).each do |i| - .row.mt-3 + .row.mt-4 .col - .input-group - .input-group-text ##{i} (x#{WorldBet.multiplier(i - 1)}) - = form.select "f_bet_#{i}", @french_participants.map { |p| [Flags.get_flag(p.world_country.code) + " " + p.name, p.id] }, {}, class: "form-select" + h4 = t("worlds.new.world_section") - - if @w_array && @f_array - (1..10).each do |i| - javascript: - el = document.querySelector('select[name="world_bet[w_bet_#{i}]"]'); - el.value = "#{@w_array[i - 1]}" - el = document.querySelector('select[name="world_bet[f_bet_#{i}]"]'); - el.value = "#{@f_array[i - 1]}" + .row.mt-3 + .col + .input-group + .input-group-text ##{i} (x#{WorldBet.multiplier(i - 1)}) + = form.select "w_bet_#{i}", @world_participants.map { |p| [Flags.get_flag(p.world_country.code) + " " + p.name, p.id] }, {}, class: "form-select" - .row.mt-4.mb-5 - .col - = form.submit t("helpers.buttons.validate"), class: "btn btn-primary" \ No newline at end of file + .row.mt-4 + .col + h4 = t("worlds.new.french_section") + + - (1..10).each do |i| + .row.mt-3 + .col + .input-group + .input-group-text ##{i} (x#{WorldBet.multiplier(i - 1)}) + = form.select "f_bet_#{i}", @french_participants.map { |p| [Flags.get_flag(p.world_country.code) + " " + p.name, p.id] }, {}, class: "form-select" + + - if @w_array && @f_array + - (1..10).each do |i| + javascript: + el = document.querySelector('select[name="world_bet[w_bet_#{i}]"]'); + el.value = "#{@w_array[i - 1]}" + el = document.querySelector('select[name="world_bet[f_bet_#{i}]"]'); + el.value = "#{@f_array[i - 1]}" + + .row.mt-4.mb-5 + .col + = form.submit t("helpers.buttons.validate"), class: "btn btn-primary" \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 493d745..1cebbed 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -466,6 +466,7 @@ en: message: To make a bet, you have to provide two ordered lists of 10 participants, one among all participants, and the other one only among French participants. The order matters! A score multiplier will be applied to each selected contestant (in parenthesis below). You can't select a participant twice on a list, but of course you can totally put a French contestant in both lists ;) notice: The bet has been made! tab: Make a bet! + too_late_message: Bets are now closed! world_section: Bet over all participants title: WJPC bets view: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 5274a43..1d87276 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -439,6 +439,7 @@ fr: notice: Le pari est enregistré ! tab: Fais ton pari ! title: Nouveau pari + too_late_message: Les paris sont désormais fermés ! world_section: Pari sur l'ensemble des participant.e.s title: Les paris des WJPC view: