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

@@ -42,7 +42,7 @@ class CompletionsController < ApplicationController
if @contestant && !params[:completion].key?(:message_id)
redirect_to edit_contest_contestant_path(@contest, @contestant), notice: t("completions.new.notice")
else
redirect_to @contest, notice: t("completions.new.notice")
redirect_to contest_messages_path(@contest), notice: t("completions.new.notice")
end
else
if params[:completion].key?(:message_id)

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

View File

@@ -16,19 +16,7 @@ class ContestsController < ApplicationController
def show
authorize @contest
@title = I18n.t("contests.show.title", name: @contest.name)
@action_name = t("helpers.buttons.settings")
@action_path = "/contests/#{@contest.id}/settings/general"
@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
@puzzles = @contest.puzzles.order(:id)
@messages = @contest.messages.order(:time_seconds)
set_badges
redirect_to contest_contestants_path(@contest)
end
def edit
@@ -240,12 +228,6 @@ class ContestsController < ApplicationController
@title = I18n.t("contests.scoreboard.title", name: @contest.name)
end
def set_badges
@badges = []
@badges.push(t("helpers.badges.team")) if @contest.team
@badges.push(t("helpers.badges.registration")) if @contest.allow_registration
end
def set_contest
@contest = Contest.find(params[:id])
end

View File

@@ -5,7 +5,7 @@ class MessagesController < ApplicationController
skip_before_action :require_authentication, only: %i[ create connect cors_preflight_check ]
before_action :cors_set_access_control_headers, only: %i[ create connect cors_preflight_check ]
before_action :set_contest, only: %i[ convert destroy ]
before_action :set_contest, only: %i[ convert destroy index ]
before_action :set_data, only: %i[ convert ]
def self.local_prefixes
@@ -68,6 +68,14 @@ class MessagesController < ApplicationController
end
end
def index
authorize @contest
@title = @contest.name
@messages = @contest.messages.order(:time_seconds)
@puzzles = @contest.puzzles
end
def convert
authorize @contest
@@ -76,6 +84,7 @@ class MessagesController < ApplicationController
@completion = Completion.new()
@completion.display_time_from_start = @message.display_time
@completion.completed = true
render "completions/new"
end

View File

@@ -2,6 +2,13 @@ class PuzzlesController < ApplicationController
before_action :set_contest
before_action :set_puzzle, only: %i[ destroy edit update]
def index
authorize @contest
@title = @contest.name
@puzzles = @contest.puzzles.order(:id)
end
def edit
authorize @contest