From cdf87e48f2b9fbe2258c0365b8496cfbfc931595 Mon Sep 17 00:00:00 2001 From: sto Date: Thu, 13 Nov 2025 18:21:31 +0100 Subject: [PATCH] Merge settings & core indexes into a single nav --- app/controllers/application_controller.rb | 9 +---- app/controllers/completions_controller.rb | 15 -------- app/controllers/contestants_controller.rb | 17 --------- app/controllers/contests_controller.rb | 36 ++++--------------- app/controllers/messages_controller.rb | 3 -- app/controllers/puzzles_controller.rb | 9 ----- app/controllers/users_controller.rb | 3 ++ app/views/application/_contest_nav.html.slim | 11 +++++- app/views/contestants/_form.html.slim | 6 +--- app/views/contestants/index.html.slim | 2 -- app/views/contestants/new.html.slim | 1 + app/views/contests/_settings_nav.html.slim | 12 ------- .../settings_categories_edit.html.slim | 2 -- .../contests/settings_general_edit.html.slim | 2 -- .../contests/settings_offline_edit.html.slim | 2 -- app/views/layouts/authenticated.html.slim | 14 +++++--- app/views/messages/index.html.slim | 2 -- app/views/puzzles/index.html.slim | 2 -- 18 files changed, 32 insertions(+), 116 deletions(-) delete mode 100644 app/views/contests/_settings_nav.html.slim diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d10746f..fa4d6c2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base include Authentication include Pundit::Authorization - before_action :set_title, :set_current_user, :set_lang + before_action :set_current_user, :set_lang after_action :verify_authorized # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. @@ -12,13 +12,6 @@ class ApplicationController < ActionController::Base private - def set_title - t_action_name = action_name - t_action_name = "new" if action_name == "create" - t_action_name = "edit" if action_name == "update" - @title = I18n.t("#{controller_name}.#{t_action_name}.title") - end - def set_current_user @current_user = current_user end diff --git a/app/controllers/completions_controller.rb b/app/controllers/completions_controller.rb index 6cf9f2e..86cb4c6 100644 --- a/app/controllers/completions_controller.rb +++ b/app/controllers/completions_controller.rb @@ -8,21 +8,11 @@ class CompletionsController < ApplicationController def edit authorize @contest - - if @contestant - @action_name = t("helpers.buttons.back_to_contestant") - @action_path = edit_contest_contestant_path(@contest, @contestant) - end end def new authorize @contest - if @contestant - @action_name = t("helpers.buttons.back_to_contestant") - @action_path = edit_contest_contestant_path(@contest, @contestant) - end - @completion = Completion.new @completion.completed = true if params[:contestant_id] @@ -47,11 +37,6 @@ class CompletionsController < ApplicationController else if params[:completion].key?(:message_id) @message = Message.find(params[:completion][:message_id]) - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) - elsif @contestant - @action_name = t("helpers.buttons.back_to_contestant") - @action_path = edit_contest_contestant_path(@contest, @contestant) end render :new, status: :unprocessable_entity end diff --git a/app/controllers/contestants_controller.rb b/app/controllers/contestants_controller.rb index 185d796..1cdd1ab 100644 --- a/app/controllers/contestants_controller.rb +++ b/app/controllers/contestants_controller.rb @@ -6,7 +6,6 @@ class ContestantsController < ApplicationController 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, @@ -18,17 +17,11 @@ class ContestantsController < ApplicationController def edit authorize @contest - - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) - @title = @contestant.name end def new authorize @contest - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) @contestant = Contestant.new end @@ -41,8 +34,6 @@ class ContestantsController < ApplicationController update_contestant_categories redirect_to contest_path(@contest), notice: t("contestants.new.notice") else - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) render :new, status: :unprocessable_entity end end @@ -54,8 +45,6 @@ class ContestantsController < ApplicationController update_contestant_categories redirect_to @contest, notice: t("contestants.edit.notice") else - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) render :edit, status: :unprocessable_entity end end @@ -83,8 +72,6 @@ class ContestantsController < ApplicationController if @csv_import.save redirect_to "/contests/#{@contest.id}/import/#{@csv_import.id}" else - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) render :import, status: :unprocessable_entity end end @@ -92,8 +79,6 @@ class ContestantsController < ApplicationController def convert_csv authorize @contest - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) @csv_import = CsvImport.find(params[:id]) @content = JSON.parse(@csv_import.content) @form = Forms::CsvConversionForm.new @@ -119,8 +104,6 @@ class ContestantsController < ApplicationController end redirect_to contest_path(@contest), notice: t("contestants.import.notice") else - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) render :convert_csv, status: :unprocessable_entity end end diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index c2c5102..d345990 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -1,7 +1,7 @@ class ContestsController < ApplicationController include CompletionsConcern - before_action :set_contest, only: %i[ destroy edit show update ] + before_action :set_contest, only: %i[ destroy 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 ] @@ -19,35 +19,16 @@ class ContestsController < ApplicationController redirect_to contest_contestants_path(@contest) end - def edit - authorize @contest - - @action_name = t("helpers.buttons.back") - @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 @@ -56,9 +37,6 @@ class ContestsController < ApplicationController 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 @@ -69,9 +47,6 @@ class ContestsController < ApplicationController 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 @@ -100,8 +75,6 @@ class ContestsController < ApplicationController if @contest.update(contest_params) redirect_to @contest, notice: t("contests.edit.notice") else - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) render :edit, status: :unprocessable_entity end end @@ -135,9 +108,12 @@ class ContestsController < ApplicationController @contestants = @contestants.select { |contestant| !contestant.offline.present? } end @puzzles = @contest.puzzles.order(:id) - @action_name = t("helpers.buttons.refresh") - if params.key?(:category) + if params.key?(:hide_offline) && params.key?(:category) + @action_path = "/public/#{@contest.friendly_id}?hide_offline=#{params[:hide_offline]}&category=#{params[:category]}" + elsif params.key?(:category) @action_path = "/public/#{@contest.friendly_id}?category=#{params[:category]}" + elsif params.key?(:hide_offline) + @action_path = "/public/#{@contest.friendly_id}?hide_offline=#{params[:hide_offline]}" else @action_path = "/public/#{@contest.friendly_id}" end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 916c807..0f2392d 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -79,9 +79,6 @@ class MessagesController < ApplicationController def convert authorize @contest - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) - @completion = Completion.new() @completion.display_time_from_start = @message.display_time @completion.completed = true diff --git a/app/controllers/puzzles_controller.rb b/app/controllers/puzzles_controller.rb index 1913ebc..dd27cc7 100644 --- a/app/controllers/puzzles_controller.rb +++ b/app/controllers/puzzles_controller.rb @@ -11,16 +11,11 @@ class PuzzlesController < ApplicationController def edit authorize @contest - - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) end def new authorize @contest - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) @puzzle = Puzzle.new end @@ -32,8 +27,6 @@ class PuzzlesController < ApplicationController if @puzzle.save redirect_to contest_path(@contest), notice: t("puzzles.new.notice") else - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) render :new, status: :unprocessable_entity end end @@ -44,8 +37,6 @@ class PuzzlesController < ApplicationController if @puzzle.update(puzzle_params) redirect_to @contest, notice: t("puzzles.edit.notice") else - @action_name = t("helpers.buttons.back") - @action_path = contest_path(@contest) render :edit, status: :unprocessable_entity end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e87b0e1..a35a439 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,11 +4,14 @@ class UsersController < ApplicationController def index authorize :user + @title = t("users.index.title") @users = User.all end def edit authorize @user + + @title = t("users.edit.title") end def update diff --git a/app/views/application/_contest_nav.html.slim b/app/views/application/_contest_nav.html.slim index 9534f86..bd2002d 100644 --- a/app/views/application/_contest_nav.html.slim +++ b/app/views/application/_contest_nav.html.slim @@ -41,4 +41,13 @@ javascript: = t("puzzles.plural").capitalize li.nav-item a.nav-link class=active_page(contest_messages_path(@contest)) href=contest_messages_path(@contest) - = t("messages.plural").capitalize \ No newline at end of file + = t("messages.plural").capitalize + li.nav-item + a.nav-link class=active_page("/contests/#{@contest.id}/settings/general") href="/contests/#{@contest.id}/settings/general" + = t("contests.form.general") + li.nav-item + a.nav-link class=active_page("/contests/#{@contest.id}/settings/offline") href="/contests/#{@contest.id}/settings/offline" + = t("contests.form.offline") + li.nav-item + a.nav-link class=active_page("/contests/#{@contest.id}/settings/categories") href="/contests/#{@contest.id}/settings/categories" + = t("contests.form.categories") \ No newline at end of file diff --git a/app/views/contestants/_form.html.slim b/app/views/contestants/_form.html.slim index c5fa0ac..e1a47d4 100644 --- a/app/views/contestants/_form.html.slim +++ b/app/views/contestants/_form.html.slim @@ -1,7 +1,3 @@ -.row - .col - h3 Informations - = form_with model: contestant, url: url, method: method do |form| .row.mb-3 .col @@ -15,7 +11,7 @@ = form.label :email .form-text = t("activerecord.attributes.contestant.email_description") - - if @contest.categories + - if @contest.categories && method == :patch .row.mt-4 .col - @contest.categories.each do |category| diff --git a/app/views/contestants/index.html.slim b/app/views/contestants/index.html.slim index 8d04bb8..068f916 100644 --- a/app/views/contestants/index.html.slim +++ b/app/views/contestants/index.html.slim @@ -1,5 +1,3 @@ -= render "contest_nav" - .row.mb-4 style="height: calc(100vh - 280px)" .col.d-flex.flex-column style="height: 100%" .row.mb-4 diff --git a/app/views/contestants/new.html.slim b/app/views/contestants/new.html.slim index e644b50..9478717 100644 --- a/app/views/contestants/new.html.slim +++ b/app/views/contestants/new.html.slim @@ -1 +1,2 @@ +h5.mb-3 = t("contestants.new.title") = render "form", contest: @contest, contestant: @contestant, submit_text: t("helpers.buttons.add"), method: :post, url: "/contests/#{@contest.id}/contestants" \ No newline at end of file diff --git a/app/views/contests/_settings_nav.html.slim b/app/views/contests/_settings_nav.html.slim deleted file mode 100644 index e9f4952..0000000 --- a/app/views/contests/_settings_nav.html.slim +++ /dev/null @@ -1,12 +0,0 @@ -.row - .col - ul.nav.nav-tabs.mb-4 - li.nav-item - a.nav-link class=active_page("/contests/#{@contest.id}/settings/general") href="/contests/#{@contest.id}/settings/general" - = t("contests.form.general") - li.nav-item - a.nav-link class=active_page("/contests/#{@contest.id}/settings/offline") href="/contests/#{@contest.id}/settings/offline" - = t("contests.form.offline") - li.nav-item - a.nav-link class=active_page("/contests/#{@contest.id}/settings/categories") href="/contests/#{@contest.id}/settings/categories" - = t("contests.form.categories") \ No newline at end of file diff --git a/app/views/contests/settings_categories_edit.html.slim b/app/views/contests/settings_categories_edit.html.slim index 142dbf3..c6953d2 100644 --- a/app/views/contests/settings_categories_edit.html.slim +++ b/app/views/contests/settings_categories_edit.html.slim @@ -1,5 +1,3 @@ -= render "settings_nav" - = form_with model: Category, url: "/contests/#{@contest.id}/categories" do |form| - if @contest.categories.size > 0 .row diff --git a/app/views/contests/settings_general_edit.html.slim b/app/views/contests/settings_general_edit.html.slim index 8511ea5..296b24e 100644 --- a/app/views/contests/settings_general_edit.html.slim +++ b/app/views/contests/settings_general_edit.html.slim @@ -1,5 +1,3 @@ -= render "settings_nav" - = form_with model: @contest, url: "/contests/#{@contest.id}/settings/general" do |form| .row.mt-2.mb-3 .col diff --git a/app/views/contests/settings_offline_edit.html.slim b/app/views/contests/settings_offline_edit.html.slim index c0f6ceb..5ce258f 100644 --- a/app/views/contests/settings_offline_edit.html.slim +++ b/app/views/contests/settings_offline_edit.html.slim @@ -1,5 +1,3 @@ -= render "settings_nav" - - if @contest.puzzles.length > 1 .row .col diff --git a/app/views/layouts/authenticated.html.slim b/app/views/layouts/authenticated.html.slim index 8019ed5..f66a069 100644 --- a/app/views/layouts/authenticated.html.slim +++ b/app/views/layouts/authenticated.html.slim @@ -44,9 +44,15 @@ html = msg h1.mb-4 - = @title - - if @action_path - a.ms-4.btn.btn-primary href=@action_path style="margin-top: -6px" - = @action_name + - if @contest + = @contest.name + - if active_page("/public") == "active" && @action_path + a.ms-4.btn.btn-primary href=@action_path style="margin-top: -6px" + = t("helpers.buttons.refresh") + - else + = @title + + - if @contest && active_page("/public") != "active" + = render "contest_nav" = yield \ No newline at end of file diff --git a/app/views/messages/index.html.slim b/app/views/messages/index.html.slim index 78b34e3..cd561f7 100644 --- a/app/views/messages/index.html.slim +++ b/app/views/messages/index.html.slim @@ -1,5 +1,3 @@ -= render "contest_nav" - .row.mb-4 style="height: calc(100vh - 280px)" .col.d-flex.flex-column style="height: 100%" diff --git a/app/views/puzzles/index.html.slim b/app/views/puzzles/index.html.slim index 6f8d55d..379d8bb 100644 --- a/app/views/puzzles/index.html.slim +++ b/app/views/puzzles/index.html.slim @@ -1,5 +1,3 @@ -= render "contest_nav" - .row.mb-4 style="height: calc(100vh - 280px)" .col.d-flex.flex-column style="height: 100%"