Worlds Bets
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-09-06 10:07:47 +02:00
parent 49e49dc93d
commit dae86bd1ea
33 changed files with 1337 additions and 1 deletions
+135
View File
@@ -0,0 +1,135 @@
class WorldsController < ApplicationController
allow_unauthenticated_access
before_action :set_title
before_action :set_fr_lang
def set_title
@title = I18n.t("worlds.title")
@nonav = true
end
def set_fr_lang
I18n.locale = "fr"
end
def main
authorize :world_bet
@world_bets_w = WorldBet.all.order(world_score: :desc)
@world_bets_f = WorldBet.all.order(french_score: :desc)
end
def about
authorize :world_bet
end
def collab
authorize :world_bet
participant_ids = Set[]
@world_bets = WorldBet.all.each do |b|
b.bet.split(";", -1).first.split(",", -1).each do |participant_id|
participant_ids.add(participant_id)
end
b.bet.split(";", -1).last.split(",", -1).each do |participant_id|
participant_ids.add(participant_id)
end
end
@participants = WorldParticipant.includes([ :world_country ]).find(participant_ids.to_a).sort_by { |p| p.name }
end
def view
authorize :world_bet
@world_bet = WorldBet.find(params[:bet_id])
@french_participants = WorldParticipant.includes([ :world_country ]).find(@world_bet.bet.split(";", -1).last.split(",", -1).map { |x| Integer(x) })
@world_participants = WorldParticipant.includes([ :world_country ]).find(@world_bet.bet.split(";", -1).first.split(",", -1).map { |x| Integer(x) })
end
def new
authorize :world_bet
@world_bet = WorldBet.new
@world_participants = WorldParticipant.includes([ :world_country ]).all.order(:name)
france = WorldCountry.where(code: "FR").first
@french_participants = WorldParticipant.includes([ :world_country ]).where(world_country: france).order(:name)
end
def create
authorize :world_bet
@world_bet = WorldBet.new(world_bet_params)
@world_bet.score = 0
@world_bet.french_score = 0
@world_bet.world_score = 0
all_params = params.require(:world_bet)
w_set = Set[]
f_set = Set[]
@w_array = []
@f_array = []
(1..10).each do |i|
if all_params.key?("w_bet_#{i}")
p_id = all_params["w_bet_#{i}"]
w_set.add(p_id)
@w_array.push(p_id)
end
if all_params.key?("f_bet_#{i}")
p_id = all_params["f_bet_#{i}"]
f_set.add(p_id)
@f_array.push(p_id)
end
end
@world_bet.serialize_bet(@w_array, @f_array)
if w_set.length != 10 || f_set.length != 10
@world_bet.errors.add(:name, I18n.t("activerecord.errors.models.world_bet.attributes.bet.duplicate"))
end
if w_set.length == 10 && f_set.length == 10 && @world_bet.save
redirect_to "/wjpc_bets/main", notice: t("worlds.new.notice")
else
@world_participants = WorldParticipant.all.sort_by { |p| p.name }
france = WorldCountry.where(code: "FR").first
@french_participants = WorldParticipant.where(world_country: france).sort_by { |p| p.name }
render :new, status: :unprocessable_entity
end
end
def update
authorize :world_bet
@participant = WorldParticipant.find(params[:participant_id])
if @participant.update(world_participant_params)
participants_hash = {}
WorldParticipant.all.each do |p|
if p.score != nil
participants_hash[p.id] = p.score
end
end
WorldBet.all.each do |b|
old_score = b.score
b.compute_score(participants_hash)
if b.score != old_score
b.save
end
end
redirect_back(fallback_location: root_path, notice: t("worlds.collab.notice"))
else
redirect_to "/wjpc_bets/collab", notice: t("worlds.collab.error")
end
end
private
def world_bet_params
params.expect(world_bet: [ :name ])
end
def world_participant_params
params.expect(world_participant: [ :qualifier_result, :semifinal_result, :final_result ])
end
end
+2
View File
@@ -0,0 +1,2 @@
module WorldsHelper
end
+261
View File
@@ -0,0 +1,261 @@
module Flags
FLAGS = {
AD: "🇦🇩",
AE: "🇦🇪",
AF: "🇦🇫",
AG: "🇦🇬",
AI: "🇦🇮",
AL: "🇦🇱",
AM: "🇦🇲",
AO: "🇦🇴",
AQ: "🇦🇶",
AR: "🇦🇷",
AS: "🇦🇸",
AT: "🇦🇹",
AU: "🇦🇺",
AW: "🇦🇼",
AX: "🇦🇽",
AZ: "🇦🇿",
BA: "🇧🇦",
BB: "🇧🇧",
BD: "🇧🇩",
BE: "🇧🇪",
BF: "🇧🇫",
BG: "🇧🇬",
BH: "🇧🇭",
BI: "🇧🇮",
BJ: "🇧🇯",
BL: "🇧🇱",
BM: "🇧🇲",
BN: "🇧🇳",
BO: "🇧🇴",
BQ: "🇧🇶",
BR: "🇧🇷",
BS: "🇧🇸",
BT: "🇧🇹",
BV: "🇧🇻",
BW: "🇧🇼",
BY: "🇧🇾",
BZ: "🇧🇿",
CA: "🇨🇦",
CC: "🇨🇨",
CD: "🇨🇩",
CF: "🇨🇫",
CG: "🇨🇬",
CH: "🇨🇭",
CI: "🇨🇮",
CK: "🇨🇰",
CL: "🇨🇱",
CM: "🇨🇲",
CN: "🇨🇳",
CO: "🇨🇴",
CR: "🇨🇷",
CU: "🇨🇺",
CV: "🇨🇻",
CW: "🇨🇼",
CX: "🇨🇽",
CY: "🇨🇾",
CZ: "🇨🇿",
DE: "🇩🇪",
DJ: "🇩🇯",
DK: "🇩🇰",
DM: "🇩🇲",
DO: "🇩🇴",
DZ: "🇩🇿",
EC: "🇪🇨",
EE: "🇪🇪",
EG: "🇪🇬",
EH: "🇪🇭",
ER: "🇪🇷",
ES: "🇪🇸",
ET: "🇪🇹",
FI: "🇫🇮",
FJ: "🇫🇯",
FK: "🇫🇰",
FM: "🇫🇲",
FO: "🇫🇴",
FR: "🇫🇷",
GA: "🇬🇦",
GB: "🇬🇧",
GD: "🇬🇩",
GE: "🇬🇪",
GF: "🇬🇫",
GG: "🇬🇬",
GH: "🇬🇭",
GI: "🇬🇮",
GL: "🇬🇱",
GM: "🇬🇲",
GN: "🇬🇳",
GP: "🇬🇵",
GQ: "🇬🇶",
GR: "🇬🇷",
GS: "🇬🇸",
GT: "🇬🇹",
GU: "🇬🇺",
GW: "🇬🇼",
GY: "🇬🇾",
HK: "🇭🇰",
HM: "🇭🇲",
HN: "🇭🇳",
HR: "🇭🇷",
HT: "🇭🇹",
HU: "🇭🇺",
ID: "🇮🇩",
IE: "🇮🇪",
IL: "🇮🇱",
IM: "🇮🇲",
IN: "🇮🇳",
IO: "🇮🇴",
IQ: "🇮🇶",
IR: "🇮🇷",
IS: "🇮🇸",
IT: "🇮🇹",
JE: "🇯🇪",
JM: "🇯🇲",
JO: "🇯🇴",
JP: "🇯🇵",
KE: "🇰🇪",
KG: "🇰🇬",
KH: "🇰🇭",
KI: "🇰🇮",
KM: "🇰🇲",
KN: "🇰🇳",
KP: "🇰🇵",
KR: "🇰🇷",
KW: "🇰🇼",
KY: "🇰🇾",
KZ: "🇰🇿",
LA: "🇱🇦",
LB: "🇱🇧",
LC: "🇱🇨",
LI: "🇱🇮",
LK: "🇱🇰",
LR: "🇱🇷",
LS: "🇱🇸",
LT: "🇱🇹",
LU: "🇱🇺",
LV: "🇱🇻",
LY: "🇱🇾",
MA: "🇲🇦",
MC: "🇲🇨",
MD: "🇲🇩",
ME: "🇲🇪",
MF: "🇲🇫",
MG: "🇲🇬",
MH: "🇲🇭",
MK: "🇲🇰",
ML: "🇲🇱",
MM: "🇲🇲",
MN: "🇲🇳",
MO: "🇲🇴",
MP: "🇲🇵",
MQ: "🇲🇶",
MR: "🇲🇷",
MS: "🇲🇸",
MT: "🇲🇹",
MU: "🇲🇺",
MV: "🇲🇻",
MW: "🇲🇼",
MX: "🇲🇽",
MY: "🇲🇾",
MZ: "🇲🇿",
NA: "🇳🇦",
NC: "🇳🇨",
NE: "🇳🇪",
NF: "🇳🇫",
NG: "🇳🇬",
NI: "🇳🇮",
NL: "🇳🇱",
NO: "🇳🇴",
NP: "🇳🇵",
NR: "🇳🇷",
NU: "🇳🇺",
NZ: "🇳🇿",
OM: "🇴🇲",
PA: "🇵🇦",
PE: "🇵🇪",
PF: "🇵🇫",
PG: "🇵🇬",
PH: "🇵🇭",
PK: "🇵🇰",
PL: "🇵🇱",
PM: "🇵🇲",
PN: "🇵🇳",
PR: "🇵🇷",
PS: "🇵🇸",
PT: "🇵🇹",
PW: "🇵🇼",
PY: "🇵🇾",
QA: "🇶🇦",
RE: "🇷🇪",
RO: "🇷🇴",
RS: "🇷🇸",
RU: "🇷🇺",
RW: "🇷🇼",
SA: "🇸🇦",
SB: "🇸🇧",
SC: "🇸🇨",
SD: "🇸🇩",
SE: "🇸🇪",
SG: "🇸🇬",
SH: "🇸🇭",
SI: "🇸🇮",
SJ: "🇸🇯",
SK: "🇸🇰",
SL: "🇸🇱",
SM: "🇸🇲",
SN: "🇸🇳",
SO: "🇸🇴",
SR: "🇸🇷",
SS: "🇸🇸",
ST: "🇸🇹",
SV: "🇸🇻",
SX: "🇸🇽",
SY: "🇸🇾",
SZ: "🇸🇿",
TC: "🇹🇨",
TD: "🇹🇩",
TF: "🇹🇫",
TG: "🇹🇬",
TH: "🇹🇭",
TJ: "🇹🇯",
TK: "🇹🇰",
TL: "🇹🇱",
TM: "🇹🇲",
TN: "🇹🇳",
TO: "🇹🇴",
TR: "🇹🇷",
TT: "🇹🇹",
TV: "🇹🇻",
TW: "🇹🇼",
TZ: "🇹🇿",
UA: "🇺🇦",
UG: "🇺🇬",
UM: "🇺🇲",
US: "🇺🇸",
UY: "🇺🇾",
UZ: "🇺🇿",
VA: "🇻🇦",
VC: "🇻🇨",
VE: "🇻🇪",
VG: "🇻🇬",
VI: "🇻🇮",
VN: "🇻🇳",
VU: "🇻🇺",
WF: "🇼🇫",
WS: "🇼🇸",
YE: "🇾🇪",
YT: "🇾🇹",
ZA: "🇿🇦",
ZM: "🇿🇲",
ZW: "🇿🇼"
}
def self.get_flag(code)
sym_code = code.to_sym
if FLAGS.has_key?(sym_code)
return FLAGS[sym_code]
end
""
end
end
+93
View File
@@ -0,0 +1,93 @@
# == Schema Information
#
# Table name: world_bets
#
# id :integer not null, primary key
# bet :string
# french_score :integer
# name :string
# score :integer
# world_score :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class WorldBet < ApplicationRecord
validates :name, presence: true, uniqueness: true
validates :score, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :french_score, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :world_score, presence: true, numericality: { greater_than_or_equal_to: 0 }
@@multiplier_array = [ 20, 15, 12, 10, 8, 6, 4, 3, 2, 1 ]
@@points_array = [ 100, 70, 50, 40, 30, 26, 23, 20, 17, 15 ]
def self.multiplier(i)
if i < 0 or i > 9
return 0
end
@@multiplier_array[i]
end
def self.points(i)
if !i || i < 1
return 0
end
if i <= 10
return @@points_array[i - 1]
end
if i <= 20
return 12
end
if i <= 30
return 10
end
if i <= 40
return 8
end
if i <= 50
return 7
end
if i <= 60
return 6
end
if i <= 70
return 5
end
if i <= 80
return 4
end
if i <= 90
return 3
end
if i <= 100
return 2
end
if i <= 150
return 1
end
0
end
def serialize_bet(w, f)
self.bet = "#{w.join(',')};#{f.join(',')}"
end
def compute_score(participant_scores)
self.score = 0
self.french_score = 0
self.world_score = 0
w = self.bet.split(";", -1).first.split(",", -1)
w.each_with_index do |participant_id, i|
if participant_scores.has_key?(Integer(participant_id))
self.score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
self.world_score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
end
end
f = self.bet.split(";", -1).last.split(",", -1)
f.each_with_index do |participant_id, i|
if participant_scores.has_key?(Integer(participant_id))
self.score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
self.french_score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
end
end
end
end
+24
View File
@@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: world_countries
#
# id :integer not null, primary key
# code :string not null
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class WorldCountry < ApplicationRecord
has_many :world_participants
validates :code, presence: true, uniqueness: true
validates :name, presence: true, uniqueness: true
def self.add_countries(str)
str.split(";", -1).each do |c|
name = c.split(",", -1).first
code = c.split(",", -1).last
WorldCountry.create(name: name, code: code)
end
end
end
+56
View File
@@ -0,0 +1,56 @@
# == Schema Information
#
# Table name: world_participants
#
# id :integer not null, primary key
# final_result :integer
# name :string not null
# qualifier_result :integer
# round :string not null
# score :integer
# semifinal_result :integer
# username :string not null
# created_at :datetime not null
# updated_at :datetime not null
# world_country_id :integer not null
#
# Indexes
#
# index_world_participants_on_world_country_id (world_country_id)
#
# Foreign Keys
#
# world_country_id (world_country_id => world_countries.id)
#
class WorldParticipant < ApplicationRecord
belongs_to :world_country
validates :name, presence: true
validates :username, presence: true
validates :round, inclusion: { in: %w[a b c d], message: "%{value} is not a valid round" }
validates :qualifier_result, numericality: { greater_than_or_equal_to: 1 }, if: -> { qualifier_result.present? }
validates :semifinal_result, numericality: { greater_than_or_equal_to: 1 }, if: -> { semifinal_result.present? }
validates :final_result, numericality: { greater_than_or_equal_to: 1 }, if: -> { final_result.present? }
before_save :compute_score
def compute_score
self.score = WorldBet.points(qualifier_result) + WorldBet.points(semifinal_result) * 2 + WorldBet.points(final_result) * 4
end
def self.add_participants(str)
str.split(";", -1).each do |c|
cs = c.split(",", -1)
if cs.length >= 4
name = cs.first
username = cs[1]
country_code = cs[2]
round = cs.last
country = WorldCountry.where(code: country_code).first
if country
WorldParticipant.create(name: name, username: username, world_country: country, round: round)
end
end
end
end
end
+29
View File
@@ -0,0 +1,29 @@
class WorldBetPolicy < ApplicationPolicy
def main?
true
end
def about?
true
end
def new?
true
end
def create?
true
end
def collab?
true
end
def update?
true
end
def view?
true
end
end
@@ -0,0 +1,15 @@
.row
.col
ul.nav.nav-tabs.mb-4
li.nav-item
a.nav-link class=active_page("/wjpc_bets/main") href="/wjpc_bets/main"
= t("worlds.main.tab")
li.nav-item
a.nav-link class=active_page("/wjpc_bets/about") href="/wjpc_bets/about"
= t("worlds.about.tab")
li.nav-item
a.nav-link class=active_page("/wjpc_bets/collaborative_filling") href="/wjpc_bets/collaborative_filling"
= t("worlds.collab.tab")
li.nav-item
a.nav-link class=active_page("/wjpc_bets/new") href="/wjpc_bets/new"
= t("worlds.new.tab")
+83
View File
@@ -0,0 +1,83 @@
= render "worlds_nav"
.alert.alert-warning role="alert"
= t("worlds.about.one_bet_message")
.alert.alert-primary role="alert"
= t("worlds.about.details_message")
.mt-3
= t("worlds.about.two_rankings_message")
.mt-3
= t("worlds.about.collaborative_filling_message")
.row.mt-4
.col
table.table.table-striped.table-hover
thead
tr
th = t("worlds.about.ranking")
th = t("worlds.about.qualifier_round")
th = t("worlds.about.semifinal_round")
th = t("worlds.about.finals_round")
tbody
- (1..10).each do |i|
tr
td #{i}
td #{WorldBet.points(i)}
td #{WorldBet.points(i) * 2}
td #{WorldBet.points(i) * 4}
tr
td 11-20
td #{WorldBet.points(20)}
td #{WorldBet.points(20) * 2}
td #{WorldBet.points(20) * 4}
tr
td 21-30
td #{WorldBet.points(30)}
td #{WorldBet.points(30) * 2}
td #{WorldBet.points(30) * 4}
tr
td 31-40
td #{WorldBet.points(40)}
td #{WorldBet.points(40) * 2}
td #{WorldBet.points(40) * 4}
tr
td 41-50
td #{WorldBet.points(50)}
td #{WorldBet.points(50) * 2}
td #{WorldBet.points(50) * 4}
tr
td 51-60
td #{WorldBet.points(60)}
td #{WorldBet.points(60) * 2}
td #{WorldBet.points(60) * 4}
tr
td 61-70
td #{WorldBet.points(70)}
td #{WorldBet.points(70) * 2}
td #{WorldBet.points(70) * 4}
tr
td 71-80
td #{WorldBet.points(80)}
td #{WorldBet.points(80) * 2}
td #{WorldBet.points(80) * 4}
tr
td 81-90
td #{WorldBet.points(90)}
td #{WorldBet.points(90) * 2}
td #{WorldBet.points(90) * 4}
tr
td 91-100
td #{WorldBet.points(100)}
td #{WorldBet.points(100) * 2}
td #{WorldBet.points(100) * 4}
tr
td 101-150
td #{WorldBet.points(150)}
td #{WorldBet.points(150) * 2}
td #{WorldBet.points(150) * 4}
tr
td 151+
td #{WorldBet.points(151)}
td #{WorldBet.points(151) * 2}
td #{WorldBet.points(151) * 4}
+131
View File
@@ -0,0 +1,131 @@
= render "worlds_nav"
.alert.alert-primary role="alert"
= t("worlds.collab.details_message")
.mt-3
= t("worlds.collab.error_message")
.alert.alert-warning role="alert"
= t("worlds.collab.rank_message")
h4.mt-4 Round A
- @participants.each do |p|
- if p.round == 'a'
.row.mt-3
.col
= form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form|
.input-group
.input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name}
.input-group-text = t("worlds.main.rank")
= form.text_field :qualifier_result, value: p.qualifier_result, autocomplete: "off", class: "form-control", style: "color: orange; max-width: 60px;"
.input-group-text = t("worlds.main.points")
.input-group-text style="color: green; width: 60px;" #{WorldBet.points(p.qualifier_result)}
= form.submit t("helpers.buttons.validate"), class: "btn btn-primary", onclick: "updateScrollPos()"
javascript:
function updateScrollPos() {
wsy = window.scrollY;
setTimeout(() => window.scrollTo(0, wsy), 25);
setTimeout(() => window.scrollTo(0, wsy), 50);
setTimeout(() => window.scrollTo(0, wsy), 75);
setTimeout(() => window.scrollTo(0, wsy), 100);
setTimeout(() => window.scrollTo(0, wsy), 125);
setTimeout(() => window.scrollTo(0, wsy), 150);
setTimeout(() => window.scrollTo(0, wsy), 175);
setTimeout(() => window.scrollTo(0, wsy), 200);
setTimeout(() => window.scrollTo(0, wsy), 225);
setTimeout(() => window.scrollTo(0, wsy), 250);
}
h4.mt-5 Round B
- @participants.each do |p|
- if p.round == 'b'
.row.mt-3
.col
= form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form|
.input-group
.input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name}
.input-group-text = t("worlds.main.rank")
= form.text_field :qualifier_result, value: p.qualifier_result, autocomplete: "off", class: "form-control", style: "color: orange; max-width: 60px;"
.input-group-text = t("worlds.main.points")
.input-group-text style="color: green; width: 60px;" #{WorldBet.points(p.qualifier_result)}
= form.submit t("helpers.buttons.validate"), class: "btn btn-primary", onclick: "updateScrollPos()"
h4.mt-5 Round C
- @participants.each do |p|
- if p.round == 'c'
.row.mt-3
.col
= form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form|
.input-group
.input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name}
.input-group-text = t("worlds.main.rank")
= form.text_field :qualifier_result, value: p.qualifier_result, autocomplete: "off", class: "form-control", style: "color: orange; max-width: 60px;"
.input-group-text = t("worlds.main.points")
.input-group-text style="color: green; width: 60px;" #{WorldBet.points(p.qualifier_result)}
= form.submit t("helpers.buttons.validate"), class: "btn btn-primary", onclick: "updateScrollPos()"
h4.mt-5 Round D
- @participants.each do |p|
- if p.round == 'd'
.row.mt-3
.col
= form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form|
.input-group
.input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name}
.input-group-text = t("worlds.main.rank")
= form.text_field :qualifier_result, value: p.qualifier_result, autocomplete: "off", class: "form-control", style: "color: orange; max-width: 60px;"
.input-group-text = t("worlds.main.points")
.input-group-text style="color: green; width: 60px;" #{WorldBet.points(p.qualifier_result)}
= form.submit t("helpers.buttons.validate"), class: "btn btn-primary", onclick: "updateScrollPos()"
h4.mt-5 = "#{t("worlds.collab.semifinal")} 1"
- @participants.each do |p|
- if p.round == 'a' || p.round == 'b'
.row.mt-3
.col
= form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form|
.input-group
.input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name}
.input-group-text = t("worlds.main.rank")
= form.text_field :semifinal_result, value: p.semifinal_result, autocomplete: "off", class: "form-control", style: "color: orange; max-width: 60px;"
.input-group-text = t("worlds.main.points")
.input-group-text style="color: green; width: 60px;" #{WorldBet.points(p.semifinal_result) * 2}
= form.submit t("helpers.buttons.validate"), class: "btn btn-primary", onclick: "updateScrollPos()"
h4.mt-5 = "#{t("worlds.collab.semifinal")} 2"
- @participants.each do |p|
- if p.round == 'c' || p.round == 'd'
.row.mt-3
.col
= form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form|
.input-group
.input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name}
.input-group-text = t("worlds.main.rank")
= form.text_field :semifinal_result, value: p.semifinal_result, autocomplete: "off", class: "form-control", style: "color: orange; max-width: 60px;"
.input-group-text = t("worlds.main.points")
.input-group-text style="color: green; width: 60px;" #{WorldBet.points(p.semifinal_result) * 2}
= form.submit t("helpers.buttons.validate"), class: "btn btn-primary", onclick: "updateScrollPos()"
h4.mt-5 = "#{t("worlds.collab.final")}"
- @participants.each do |p|
.row.mt-3
.col
= form_with model: WorldParticipant, url: "/wjpc_bets/update/#{p.id}", method: :patch do |form|
.input-group
.input-group-text style="width: 350px;" #{Flags.get_flag(p.world_country.code) + " " + p.name}
.input-group-text = t("worlds.main.rank")
= form.text_field :final_result, value: p.final_result, autocomplete: "off", class: "form-control", style: "color: orange; max-width: 60px;"
.input-group-text = t("worlds.main.points")
.input-group-text style="color: green; width: 60px;" #{WorldBet.points(p.final_result) * 4}
= form.submit t("helpers.buttons.validate"), class: "btn btn-primary", onclick: "updateScrollPos()"
.mb-5
+52
View File
@@ -0,0 +1,52 @@
= render "worlds_nav"
.row.mt-3
.col-6
h4 = t("worlds.main.world_participants")
table.table.table-striped.table-hover
thead
tr
th = t("worlds.main.rank")
th = t("worlds.main.name")
th = t("worlds.main.score")
tbody
- @world_bets_w.each_with_index do |b, i|
tr
- if i == 0
td 🥇
- elsif i == 1
td 🥈
- elsif i == 2
td 🥉
- else
td #{i + 1}
td #{b.name}
td #{b.world_score}
td
a.btn.btn-sm.btn-secondary href="/wjpc_bets/view/#{b.id}"
= t("worlds.main.view_bet")
.col-6
h4 = t("worlds.main.french_participants")
table.table.table-striped.table-hover
thead
tr
th = t("worlds.main.rank")
th = t("worlds.main.name")
th = t("worlds.main.score")
tbody
- @world_bets_f.each_with_index do |b, i|
tr
- if i == 0
td 🥇
- elsif i == 1
td 🥈
- elsif i == 2
td 🥉
- else
td #{i + 1}
td #{b.name}
td #{b.french_score}
td
a.btn.btn-sm.btn-secondary href="/wjpc_bets/view/#{b.id}"
= t("worlds.main.view_bet")
+45
View File
@@ -0,0 +1,45 @@
= render "worlds_nav"
= form_with model: @world_bet, url: "/wjpc_bets/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
.col
.input-group
.input-group-text ##{i} <i class="ms-2" style="color: cadetblue;">(x#{WorldBet.multiplier(i - 1)})</i>
= 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
.col
h4 = t("worlds.new.french_section")
- (1..10).each do |i|
.row.mt-3
.col
.input-group
.input-group-text ##{i} <i class="ms-2" style="color: cadetblue;">(x#{WorldBet.multiplier(i - 1)})</i>
= 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"
+49
View File
@@ -0,0 +1,49 @@
= render "worlds_nav"
h4.mt-3 = t("worlds.view.subtitle", name: @world_bet.name).html_safe
.row.mt-3
.col
h5 = t("worlds.view.world_participants")
table.table.table-striped.table-hover
thead
tr
th = t("worlds.view.participant")
th = t("worlds.view.multiplier")
th Q
th S
th F
th = t("worlds.view.total")
tbody
- @world_participants.each_with_index do |p, i|
tr
td = Flags.get_flag(p.world_country.code) + " " + p.name
td style="color: cadetblue;"
= "x#{WorldBet.multiplier(i)}"
td = "<span style='color: orange'>#{p.qualifier_result || "?"}</span> > <span style='color: green'>#{WorldBet.points(p.qualifier_result)}p</span>".html_safe
td = "<span style='color: orange'>#{p.semifinal_result || "?"}</span> > <span style='color: green'>#{WorldBet.points(p.semifinal_result) * 2}p</span>".html_safe
td = "<span style='color: orange'>#{p.final_result || "?"}</span> > <span style='color: green'>#{WorldBet.points(p.final_result) * 4}p</span>".html_safe
td = "<span style='color: green'>#{p.score || 0}</span> x <span style='color: cadetblue'>#{WorldBet.multiplier(i)}</span> = <span style='color: green'>#{(p.score || 0) * WorldBet.multiplier(i)}p</span>".html_safe
.row.mt-3
.col
h5 = t("worlds.view.french_participants")
table.table.table-striped.table-hover
thead
tr
th = t("worlds.view.participant")
th = t("worlds.view.multiplier")
th Q
th S
th F
th = t("worlds.view.total")
tbody
- @french_participants.each_with_index do |p, i|
tr
td = Flags.get_flag(p.world_country.code) + " " + p.name
td style="color: cadetblue;"
= "x#{WorldBet.multiplier(i)}"
td = "<span style='color: orange'>#{p.qualifier_result || "?"}</span> > <span style='color: green'>#{WorldBet.points(p.qualifier_result)}p</span>".html_safe
td = "<span style='color: orange'>#{p.semifinal_result || "?"}</span> > <span style='color: green'>#{WorldBet.points(p.semifinal_result) * 2}p</span>".html_safe
td = "<span style='color: orange'>#{p.final_result || "?"}</span> > <span style='color: green'>#{WorldBet.points(p.final_result) * 4}p</span>".html_safe
td = "<span style='color: green'>#{p.score || 0}</span> x <span style='color: cadetblue'>#{WorldBet.multiplier(i)}</span> = <span style='color: green'>#{(p.score || 0) * WorldBet.multiplier(i)}p</span>".html_safe