Add category selectors on public scoreboards
All checks were successful
CI / scan_ruby (push) Successful in 16s
CI / scan_js (push) Successful in 14s
CI / lint (push) Successful in 14s
CI / test (push) Successful in 30s

This commit is contained in:
sto
2025-07-16 10:38:21 +02:00
parent b13ef30807
commit 4ca711f5aa
3 changed files with 36 additions and 15 deletions

View File

@@ -16,13 +16,7 @@ class ContestsController < ApplicationController
@action_name = t("helpers.buttons.edit")
@action_path = edit_contest_path(@contest)
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
if params.key?(:category) && params[:category] != "-1"
if params[:category] == "-2"
@contestants = @contestants.select { |contestant| contestant.categories.size == 0 }
else
@contestants = @contestants.select { |contestant| contestant.categories.where(id: params[:category]).any? }
end
end
filter_contestants_per_category
@puzzles = @contest.puzzles.order(:id)
@messages = @contest.messages.order(:time_seconds)
set_badges
@@ -84,6 +78,7 @@ class ContestsController < ApplicationController
@title = I18n.t("contests.scoreboard.title", name: @contest.name)
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
filter_contestants_per_category
@puzzles = @contest.puzzles.order(:id)
@action_name = t("helpers.buttons.refresh")
@action_path = "/public/#{@contest.friendly_id}"
@@ -105,4 +100,14 @@ class ContestsController < ApplicationController
def contest_params
params.expect(contest: [ :lang, :name, :public, :team, :allow_registration ])
end
def filter_contestants_per_category
if params.key?(:category) && params[:category] != "-1"
if params[:category] == "-2"
@contestants = @contestants.select { |contestant| contestant.categories.size == 0 }
else
@contestants = @contestants.select { |contestant| contestant.categories.where(id: params[:category]).any? }
end
end
end
end