Events: kickstart shared scoreboard
Some checks failed
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-07-30 08:33:55 +02:00
parent b8a2e4b0b4
commit 4a4c79ad8a
13 changed files with 73 additions and 8 deletions

View File

@@ -0,0 +1,7 @@
module ContestsConcern
extend ActiveSupport::Concern
def active_page(path)
request.path.starts_with?(path) ? "active" : ""
end
end

View File

@@ -1,5 +1,6 @@
class ContestsController < ApplicationController
include CompletionsConcern
include ContestsConcern
include ContestantsConcern
before_action :set_contest, only: %i[ destroy show ]
@@ -168,10 +169,30 @@ class ContestsController < ApplicationController
end
def scoreboard
@contest = Contest.find_by(slug: params[:id])
unless @contest && @contest.public
skip_authorization
not_found and return
if active_page("/public/event")
@event = Event.find_by(slug: params[:id])
unless @event && @event.shared_scoreboard && !@event.contests.where(public: true).empty?
skip_authorization
not_found and return
end
if params.key?(:contest_id)
begin
@contest = Contest.find(params[:contest_id])
if @contest.event != @event
@contest = @event.contests.where(public: true).first
end
rescue
@contest = @event.contests.where(public: true).first
end
else
@contest = @event.contests.where(public: true).first
end
else
@contest = Contest.find_by(slug: params[:id])
unless @contest && @contest.public
skip_authorization
not_found and return
end
end
authorize @contest

View File

@@ -35,7 +35,7 @@ class EventsController < ApplicationController
def show
authorize @event
@contests = @event.contests
@contests = @event.contests.includes([ :contestants, :puzzles ])
@title = @event.name
end
@@ -65,11 +65,13 @@ class EventsController < ApplicationController
redirect_to events_path, notice: t("events.destroy.notice")
end
private
def set_event
@event = Event.find(params[:id])
end
def event_params
params.expect(event: [ :name, :shared_scoreboard ])
params.expect(event: [ :lang, :name, :shared_scoreboard ])
end
end

View File

@@ -6,6 +6,7 @@
# lang :string default("en")
# name :string
# shared_scoreboard :boolean
# slug :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :integer not null
@@ -19,8 +20,13 @@
# user_id (user_id => users.id)
#
class Event < ApplicationRecord
extend FriendlyId
belongs_to :user
has_many :contests, dependent: :destroy
friendly_id :name, use: :slugged
validates :name, presence: true
validates :lang, inclusion: { in: Languages::AVAILABLE_LANGUAGES.map { |lang| lang[:id] } }
end

View File

@@ -15,6 +15,13 @@
.alert.alert-primary role="alert"
= t("events.form.shared_scoreboard_message")
if method == :patch
.row.mb-3
.col
.form-floating
= form.select :lang, Languages::AVAILABLE_LANGUAGES.map { |lang| [ lang[:name], lang[:id] ] }, {}, class: "form-select"
= form.label :lang
.row.mt-4
.col
- if method == :patch

View File

@@ -8,7 +8,14 @@
a.mt-3.btn.btn-primary.mb-4 href=new_contest_path(event: @event.id)
= t("events.show.new_contest")
.row.row-cols-1.row-cols-md-3.g-4
- if @event.shared_scoreboard
a.btn.btn-success href="/public/event/#{@event.slug}" style="margin-top: -6px;"
= t("events.show.open_shared_scoreboard")
- else
a.btn.btn-success.disabled style="margin-top: -6px;"
= t("events.show.shared_scoreboard_disabled")
.mt-3.row.row-cols-1.row-cols-md-3.g-4
- @contests.each do |contest|
.col
css: