Revamp contest settings into tabs
This commit is contained in:
@@ -2,6 +2,7 @@ class ContestsController < ApplicationController
|
||||
include CompletionsConcern
|
||||
|
||||
before_action :set_contest, only: %i[ destroy edit show update ]
|
||||
before_action :set_settings_contest, only: %i[ settings_general_edit settings_general_update settings_offline_edit settings_offline_update settings_categories_edit ]
|
||||
before_action :offline_setup, only: %i[ offline_new offline_create offline_edit offline_update offline_completed ]
|
||||
skip_before_action :require_authentication, only: %i[ scoreboard offline_new offline_create offline_edit offline_update offline_completed ]
|
||||
|
||||
@@ -16,8 +17,8 @@ class ContestsController < ApplicationController
|
||||
authorize @contest
|
||||
|
||||
@title = I18n.t("contests.show.title", name: @contest.name)
|
||||
@action_name = t("helpers.buttons.edit")
|
||||
@action_path = edit_contest_path(@contest)
|
||||
@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,
|
||||
@@ -37,6 +38,56 @@ class ContestsController < ApplicationController
|
||||
@action_path = contest_path(@contest)
|
||||
end
|
||||
|
||||
def settings_general_edit
|
||||
authorize @contest
|
||||
|
||||
@action_name = t("helpers.buttons.back")
|
||||
@action_path = contest_path(@contest)
|
||||
@title = t("contests.edit.title")
|
||||
end
|
||||
|
||||
def settings_offline_edit
|
||||
authorize @contest
|
||||
|
||||
@action_name = t("helpers.buttons.back")
|
||||
@action_path = contest_path(@contest)
|
||||
@title = t("contests.edit.title")
|
||||
end
|
||||
|
||||
def settings_categories_edit
|
||||
authorize @contest
|
||||
|
||||
@action_name = t("helpers.buttons.back")
|
||||
@action_path = contest_path(@contest)
|
||||
@title = t("contests.edit.title")
|
||||
end
|
||||
|
||||
def settings_general_update
|
||||
authorize @contest
|
||||
|
||||
if @contest.update(settings_general_params)
|
||||
redirect_to "/contests/#{@contest.id}/settings/general", notice: t("contests.edit.notice")
|
||||
else
|
||||
@action_name = t("helpers.buttons.back")
|
||||
@action_path = contest_path(@contest)
|
||||
@title = t("contests.edit.title")
|
||||
render :settings_general_edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def settings_offline_update
|
||||
authorize @contest
|
||||
|
||||
if @contest.update(settings_offline_params)
|
||||
redirect_to "/contests/#{@contest.id}/settings/offline", notice: t("contests.edit.notice")
|
||||
else
|
||||
@action_name = t("helpers.buttons.back")
|
||||
@action_path = contest_path(@contest)
|
||||
@title = t("contests.edit.title")
|
||||
render :settings_offline_edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
authorize :contest
|
||||
|
||||
@@ -49,7 +100,7 @@ class ContestsController < ApplicationController
|
||||
@contest = Contest.new(contest_params)
|
||||
@contest.user_id = current_user.id
|
||||
if @contest.save
|
||||
redirect_to @contest, notice: t("contests.new.notice")
|
||||
redirect_to "/contests/#{@contest.id}/settings/general", notice: t("contests.new.notice")
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
@@ -199,10 +250,22 @@ class ContestsController < ApplicationController
|
||||
@contest = Contest.find(params[:id])
|
||||
end
|
||||
|
||||
def set_settings_contest
|
||||
@contest = Contest.find(params[:contest_id])
|
||||
end
|
||||
|
||||
def contest_params
|
||||
params.expect(contest: [ :lang, :name, :offline_form, :public, :team, :allow_registration ])
|
||||
end
|
||||
|
||||
def settings_general_params
|
||||
params.expect(contest: [ :lang, :name, :public, :team, :allow_registration ])
|
||||
end
|
||||
|
||||
def settings_offline_params
|
||||
params.expect(contest: [ :offline_form ])
|
||||
end
|
||||
|
||||
def filter_contestants_per_category
|
||||
if params.key?(:category) && params[:category] != "-1"
|
||||
if params[:category] == "-2"
|
||||
|
||||
Reference in New Issue
Block a user