Require contest durations, prefill end times for unfinished puzzles & allow to modify them
Some checks failed
CI / scan_ruby (push) Successful in 19s
CI / scan_js (push) Successful in 13s
CI / lint (push) Successful in 14s
CI / test (push) Failing after 44s

This commit is contained in:
sto
2025-11-18 11:46:02 +01:00
parent 63a88ea113
commit 3dd153d587
8 changed files with 19 additions and 18 deletions

View File

@@ -57,6 +57,7 @@ class ContestsController < ApplicationController
@contest = Contest.new
@title = I18n.t("contests.new.title")
@nonav = true
end
def create
@@ -69,6 +70,8 @@ class ContestsController < ApplicationController
if @contest.save
redirect_to "/contests/#{@contest.id}/settings/general", notice: t("contests.new.notice")
else
@title = I18n.t("contests.new.title")
@nonav = true
render :new, status: :unprocessable_entity
end
end
@@ -203,7 +206,7 @@ class ContestsController < ApplicationController
end
def new_contest_params
params.expect(contest: [ :name ])
params.expect(contest: [ :name, :duration ])
end
def settings_general_params

View File

@@ -68,11 +68,7 @@ class Completion < ApplicationRecord
self.time_seconds = arr[0].to_i
end
else
if self.contest.duration_seconds.present?
self.time_seconds = self.contest.duration_seconds
else
self.time_seconds = 2 * 3600
end
self.time_seconds = self.contest.duration_seconds
self.display_time_from_start = display_time(self.time_seconds)
end
end
@@ -82,9 +78,6 @@ class Completion < ApplicationRecord
self.remaining_pieces = nil
else
self.missing_pieces = nil
if !self.offline.present?
self.display_time_from_start = nil
end
end
end

View File

@@ -44,7 +44,7 @@ class Contest < ApplicationRecord
validates :name, presence: true
validates :lang, inclusion: { in: Languages::AVAILABLE_LANGUAGES.map { |lang| lang[:id] } }
validates :ranking_mode, inclusion: { in: Ranking::AVAILABLE_RANKING_MODES.map { |lang| lang[:id] } }
validates :duration, format: { with: /\A(\d\d:\d\d|\d:\d\d)\z/ }, if: -> { duration.present? }
validates :duration, presence: true, format: { with: /\A(\d\d:\d\d|\d:\d\d)\z/ }
generates_token_for :token

View File

@@ -43,19 +43,19 @@
const missingPiecesEl = document.getElementById('missing_pieces');
const remainingPiecesEl = document.getElementById('remaining_pieces');
if (e.target.checked) {
timeEl.style.display = 'block';
timeEl.value = '#{@completion.display_time_from_start}';
missingPiecesEl.style.display = 'block';
remainingPiecesEl.style.display = 'none';
} else {
timeEl.style.display = 'none';
timeEl.value = '#{display_time(@contest.duration_seconds)}';
missingPiecesEl.style.display = 'none';
remainingPiecesEl.style.display = 'block';
}
})
.row.mb-3 id="time"
.row.mb-3
.col
.form-floating
= form.text_field :display_time_from_start, autocomplete: "off", class: "form-control"
= form.text_field :display_time_from_start, autocomplete: "off", class: "form-control", id: "time"
= form.label :display_time_from_start, class: "required"
.row.mb-3 id="missing_pieces"
.col
@@ -69,15 +69,12 @@
= form.label :remaining_pieces
javascript:
completedEl = document.getElementById('completion_completed');
timeEl = document.getElementById('time');
missingPiecesEl = document.getElementById('missing_pieces');
remainingPiecesEl = document.getElementById('remaining_pieces');
if (completedEl.checked) {
timeEl.style.display = 'block';
missingPiecesEl.style.display = 'block';
remainingPiecesEl.style.display = 'none';
} else {
timeEl.style.display = 'none';
missingPiecesEl.style.display = 'none';
remainingPiecesEl.style.display = 'block';
}

View File

@@ -4,6 +4,12 @@
.form-floating
= form.text_field :name, autocomplete: "off", class: "form-control"
= form.label :name, class: "required"
.row.mb-3
.col
.form-floating
= form.text_field :duration, autocomplete: "off", class: "form-control"
= form.label :duration, class: "required"
.form-text = t("activerecord.attributes.contest.duration_description")
.row.mt-4
.col
= form.submit t("helpers.buttons.create"), class: "btn btn-primary"

View File

@@ -52,7 +52,7 @@ html
- else
= @title
- if @contest && active_page("/public") != "active" && active_page("/contests/new") != "active" && active_page("/contests/create") != "active" && active_page("/contests") == "active"
- if @contest && active_page("/contests") == "active" && !@nonav
= render "contest_nav"
= yield