Turn contest dashboard into tabs for easier navigation
Some checks failed
CI / scan_ruby (push) Successful in 20s
CI / scan_js (push) Successful in 14s
CI / lint (push) Successful in 13s
CI / test (push) Failing after 50s

This commit is contained in:
sto
2025-11-13 12:06:12 +01:00
parent 0f31265f7b
commit 97ea17b7c2
17 changed files with 265 additions and 239 deletions

View File

@@ -3,6 +3,19 @@ class ContestantsController < ApplicationController
before_action :set_contestant, only: %i[ destroy edit update]
before_action :set_completions, only: %i[edit update ]
def index
authorize @contest
@title = @contest.name
@contestants = @contest.contestants.sort_by { |contestant| [
-contestant.completions.where(remaining_pieces: nil).size,
(contestant.completions.where(remaining_pieces: nil).size == @contest.puzzles.length ? 1 : 0) * contestant.time_seconds,
contestant.completions.size > 0 && contestant.completions[-1].remaining_pieces ? contestant.completions[-1].remaining_pieces : 1000000,
contestant.time_seconds
] }
filter_contestants_per_category
end
def edit
authorize @contest
@@ -158,4 +171,14 @@ class ContestantsController < ApplicationController
end
@contestant.save
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