Show offline contestants in dashboard
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class ContestsController < ApplicationController
|
||||
include CompletionsConcern
|
||||
|
||||
before_action :set_contest, only: %i[ destroy edit show update ]
|
||||
before_action :offline_setup, only: %i[ offline_new offline_create offline_edit offline_update offline_completed ]
|
||||
skip_before_action :require_authentication, only: %i[ scoreboard offline_new offline_create offline_edit offline_update offline_completed ]
|
||||
@@ -139,8 +141,18 @@ class ContestsController < ApplicationController
|
||||
end
|
||||
|
||||
@offline.completed = true
|
||||
@offline.end_time = Time.now()
|
||||
@offline.images.attach(params[:offline][:end_image])
|
||||
if @offline.save
|
||||
if @contest.puzzles.length > 0
|
||||
dp = display_time(@offline.end_time.to_i - @offline.start_time.to_i)
|
||||
contestant = Contestant.create(contest: @contest, name: @offline.name, offline: @offline)
|
||||
Completion.create(contest: @contest,
|
||||
contestant: contestant,
|
||||
puzzle: @contest.puzzles[0],
|
||||
display_time_from_start: dp)
|
||||
extend_completions!(contestant)
|
||||
end
|
||||
redirect_to "/public/#{@contest.friendly_id}/offline/#{@offline.generate_token_for(:token)}/completed"
|
||||
else
|
||||
render :offline_edit, status: :unprocessable_entity
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
class Contestant < ApplicationRecord
|
||||
belongs_to :contest
|
||||
has_many :completions, dependent: :destroy
|
||||
has_one :offline
|
||||
has_and_belongs_to_many :categories
|
||||
|
||||
before_validation :initialize_time_seconds_if_empty
|
||||
|
||||
@@ -2,25 +2,29 @@
|
||||
#
|
||||
# Table name: offlines
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# completed :boolean
|
||||
# end_time :datetime
|
||||
# name :string not null
|
||||
# start_time :datetime not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# contest_id :integer not null
|
||||
# id :integer not null, primary key
|
||||
# completed :boolean
|
||||
# end_time :datetime
|
||||
# name :string not null
|
||||
# start_time :datetime not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# contest_id :integer not null
|
||||
# contestant_id :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_offlines_on_contest_id (contest_id)
|
||||
# index_offlines_on_contest_id (contest_id)
|
||||
# index_offlines_on_contestant_id (contestant_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# contest_id (contest_id => contests.id)
|
||||
# contest_id (contest_id => contests.id)
|
||||
# contestant_id (contestant_id => contestants.id)
|
||||
#
|
||||
class Offline < ApplicationRecord
|
||||
belongs_to :contest
|
||||
belongs_to :contestant, optional: true
|
||||
|
||||
has_many_attached :images
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
displayTimeEl.innerHTML = `${hh < 10 ? `0${hh}` : hh}:${mm < 10 ? `0${mm}` : mm}:${ss < 10 ? `0${ss}` : ss}`;
|
||||
setTimeout(updateTime, 1000);
|
||||
}
|
||||
setTimeout(updateTime, 5);
|
||||
setTimeout(updateTime, 50);
|
||||
.row.mt-5.mb-3
|
||||
.col
|
||||
.form-text.mb-1
|
||||
|
||||
@@ -75,10 +75,10 @@ javascript:
|
||||
table.table.table-striped.table-hover
|
||||
thead
|
||||
tr
|
||||
th
|
||||
= t("helpers.rank")
|
||||
th
|
||||
= t("activerecord.attributes.contestant.name")
|
||||
th
|
||||
= t("activerecord.attributes.contestant.offline")
|
||||
th
|
||||
= t("activerecord.attributes.contestant.completions")
|
||||
th
|
||||
@@ -86,10 +86,14 @@ javascript:
|
||||
tbody
|
||||
- @contestants.each_with_index do |contestant, index|
|
||||
tr scope="row"
|
||||
td
|
||||
= index + 1
|
||||
td
|
||||
= contestant.name
|
||||
td
|
||||
- if contestant.offline.present?
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-square" viewBox="0 0 16 16">
|
||||
<path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/>
|
||||
<path d="M10.97 4.97a.75.75 0 0 1 1.071 1.05l-3.992 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"/>
|
||||
</svg>
|
||||
td
|
||||
= contestant.completions.where(remaining_pieces: nil).length
|
||||
td
|
||||
|
||||
Reference in New Issue
Block a user