Some improvements
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

This commit is contained in:
sto 2025-03-20 16:14:48 +01:00
parent a03907f756
commit ea7cdcf608
6 changed files with 51 additions and 13 deletions

View File

@ -4,7 +4,7 @@ class ContestantsController < ApplicationController
before_action :set_completions, only: %i[edit update ] before_action :set_completions, only: %i[edit update ]
def edit def edit
@title = "Edit contestant" @title = "Contestant"
end end
def new def new
@ -27,7 +27,7 @@ class ContestantsController < ApplicationController
if @contestant.update(contestant_params) if @contestant.update(contestant_params)
redirect_to @contest redirect_to @contest
else else
@title = "Edit contestant" @title = "Contestant"
render :edit, status: :unprocessable_entity render :edit, status: :unprocessable_entity
end end
end end
@ -47,8 +47,32 @@ class ContestantsController < ApplicationController
@contestant = Contestant.find(params[:id]) @contestant = Contestant.find(params[:id])
end end
def pad(n)
if n > 9
return n.to_s
end
"0" + n.to_s
end
def display_time(seconds)
if seconds > 3600
hours = seconds / 3600
return hours.to_s + ":" + display_time(seconds % 3600)
elsif seconds > 60
minutes = seconds / 60
return pad(minutes) + ":" + display_time(seconds % 60)
end
pad(seconds)
end
def set_completions def set_completions
@completions = @contestant.completions @completions = @contestant.completions.order(:time_seconds)
current_time_from_start = 0
@completions.each do |completion|
completion.display_time_from_start = display_time(completion.time_seconds)
completion.display_relative_time = display_time(completion.time_seconds - current_time_from_start)
current_time_from_start += completion.time_seconds
end
end end
def contestant_params def contestant_params

View File

@ -8,8 +8,8 @@ class ContestsController < ApplicationController
def show def show
@title = @contest.name @title = @contest.name
@contestants = @contest.contestants @contestants = @contest.contestants.order(:name)
@puzzles = @contest.puzzles @puzzles = @contest.puzzles.order(:id)
set_badges set_badges
end end

View File

@ -3,5 +3,7 @@ class Completion < ApplicationRecord
belongs_to :contestant belongs_to :contestant
belongs_to :puzzle belongs_to :puzzle
attr_accessor :display_time_from_start, :display_relative_time
validates :time_seconds, presence: true validates :time_seconds, presence: true
end end

View File

@ -29,15 +29,22 @@
tr tr
th scope="col" th scope="col"
| Time since start | Time since start
th scope="col"
| Relative time
th scope="col" th scope="col"
| Puzzle | Puzzle
tbody tbody
- @completions.each do |completion| - @completions.each do |completion|
tr scope="row" tr scope="row"
td td
= link_to completion.time_seconds, edit_contest_completion_path(@contest, completion, contestant.id) = completion.display_time_from_start
td td
= completion.puzzle.name = completion.display_relative_time
td
| #{completion.puzzle.name} - #{completion.puzzle.brand}
td
a.btn.btn-sm.btn-secondary href=edit_contest_completion_path(@contest, completion, contestant.id)
| Edit
.row .row
.col .col
a.btn.btn-primary href=new_contest_completion_path(@contest, contestant_id: contestant.id) a.btn.btn-primary href=new_contest_completion_path(@contest, contestant_id: contestant.id)

View File

@ -10,13 +10,13 @@
= form.check_box :team, class: "form-check-input" = form.check_box :team, class: "form-check-input"
= form.label :team = form.label :team
| Team contest | Team contest
.form-text For registration and UI display purposes .form-text For UI display purposes mainly
.row.mb-3 .row.mb-3
.col .col
.form-check.form-switch .form-check.form-switch
= form.check_box :allow_registration, class: "form-check-input" = form.check_box :allow_registration, class: "form-check-input"
= form.label :allow_registration = form.label :allow_registration
.form-text Generates a registration form for this contest .form-text Generates a shareable registration form for this contest
.row .row
.col .col
= form.submit submit_text, class: "btn btn-primary" = form.submit submit_text, class: "btn btn-primary"

View File

@ -11,7 +11,7 @@
| Edit contest | Edit contest
.row.mb-4 .row.mb-4
.col-8 .col-6
.row .row
.col .col
h4 h4
@ -33,7 +33,7 @@
.col .col
a.btn.btn-primary href=new_contest_puzzle_path(@contest) a.btn.btn-primary href=new_contest_puzzle_path(@contest)
| Add puzzle | Add puzzle
.col-4 .col-6
.row .row
.col .col
h4 h4
@ -49,10 +49,15 @@
- @contestants.each do |contestant| - @contestants.each do |contestant|
tr scope="row" tr scope="row"
td td
= link_to contestant.name, edit_contest_contestant_path(@contest, contestant) = contestant.name
td td
= contestant.completions.length = contestant.completions.length
.row td
a.btn.btn-sm.btn-secondary href=edit_contest_contestant_path(@contest, contestant)
| Open
a.btn.btn-sm.btn-secondary.ms-2 href=new_contest_completion_path(@contest, contestant_id: contestant.id)
| Add completion
.row.mt-4
.col .col
a.btn.btn-primary href=new_contest_contestant_path(@contest) a.btn.btn-primary href=new_contest_contestant_path(@contest)
| Add contestant | Add contestant