Some improvements
This commit is contained in:
parent
a03907f756
commit
ea7cdcf608
@ -4,7 +4,7 @@ class ContestantsController < ApplicationController
|
||||
before_action :set_completions, only: %i[edit update ]
|
||||
|
||||
def edit
|
||||
@title = "Edit contestant"
|
||||
@title = "Contestant"
|
||||
end
|
||||
|
||||
def new
|
||||
@ -27,7 +27,7 @@ class ContestantsController < ApplicationController
|
||||
if @contestant.update(contestant_params)
|
||||
redirect_to @contest
|
||||
else
|
||||
@title = "Edit contestant"
|
||||
@title = "Contestant"
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
@ -47,8 +47,32 @@ class ContestantsController < ApplicationController
|
||||
@contestant = Contestant.find(params[:id])
|
||||
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
|
||||
@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
|
||||
|
||||
def contestant_params
|
||||
|
@ -8,8 +8,8 @@ class ContestsController < ApplicationController
|
||||
|
||||
def show
|
||||
@title = @contest.name
|
||||
@contestants = @contest.contestants
|
||||
@puzzles = @contest.puzzles
|
||||
@contestants = @contest.contestants.order(:name)
|
||||
@puzzles = @contest.puzzles.order(:id)
|
||||
set_badges
|
||||
end
|
||||
|
||||
|
@ -3,5 +3,7 @@ class Completion < ApplicationRecord
|
||||
belongs_to :contestant
|
||||
belongs_to :puzzle
|
||||
|
||||
attr_accessor :display_time_from_start, :display_relative_time
|
||||
|
||||
validates :time_seconds, presence: true
|
||||
end
|
||||
|
@ -29,15 +29,22 @@
|
||||
tr
|
||||
th scope="col"
|
||||
| Time since start
|
||||
th scope="col"
|
||||
| Relative time
|
||||
th scope="col"
|
||||
| Puzzle
|
||||
tbody
|
||||
- @completions.each do |completion|
|
||||
tr scope="row"
|
||||
td
|
||||
= link_to completion.time_seconds, edit_contest_completion_path(@contest, completion, contestant.id)
|
||||
= completion.display_time_from_start
|
||||
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
|
||||
.col
|
||||
a.btn.btn-primary href=new_contest_completion_path(@contest, contestant_id: contestant.id)
|
||||
|
@ -10,13 +10,13 @@
|
||||
= form.check_box :team, class: "form-check-input"
|
||||
= form.label :team
|
||||
| Team contest
|
||||
.form-text For registration and UI display purposes
|
||||
.form-text For UI display purposes mainly
|
||||
.row.mb-3
|
||||
.col
|
||||
.form-check.form-switch
|
||||
= form.check_box :allow_registration, class: "form-check-input"
|
||||
= form.label :allow_registration
|
||||
.form-text Generates a registration form for this contest
|
||||
.form-text Generates a shareable registration form for this contest
|
||||
.row
|
||||
.col
|
||||
= form.submit submit_text, class: "btn btn-primary"
|
@ -11,7 +11,7 @@
|
||||
| Edit contest
|
||||
|
||||
.row.mb-4
|
||||
.col-8
|
||||
.col-6
|
||||
.row
|
||||
.col
|
||||
h4
|
||||
@ -33,7 +33,7 @@
|
||||
.col
|
||||
a.btn.btn-primary href=new_contest_puzzle_path(@contest)
|
||||
| Add puzzle
|
||||
.col-4
|
||||
.col-6
|
||||
.row
|
||||
.col
|
||||
h4
|
||||
@ -49,10 +49,15 @@
|
||||
- @contestants.each do |contestant|
|
||||
tr scope="row"
|
||||
td
|
||||
= link_to contestant.name, edit_contest_contestant_path(@contest, contestant)
|
||||
= contestant.name
|
||||
td
|
||||
= 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
|
||||
a.btn.btn-primary href=new_contest_contestant_path(@contest)
|
||||
| Add contestant
|
||||
|
Loading…
x
Reference in New Issue
Block a user