From 5b908fe37c2c946fe610e82c2d7e7f2a61ecdffb Mon Sep 17 00:00:00 2001 From: sto Date: Sat, 21 Jun 2025 09:59:18 +0200 Subject: [PATCH] Add notices --- app/controllers/completions_controller.rb | 12 ++-- app/controllers/contestants_controller.rb | 8 +-- app/controllers/contests_controller.rb | 7 ++- app/controllers/messages_controller.rb | 2 +- app/controllers/puzzles_controller.rb | 6 +- app/controllers/sessions_controller.rb | 2 +- app/controllers/users_controller.rb | 4 +- app/views/layouts/authenticated.html.slim | 27 +++++++++ config/locales/en.yml | 74 +++++++++++++++-------- config/locales/fr.yml | 72 ++++++++++++++-------- 10 files changed, 144 insertions(+), 70 deletions(-) diff --git a/app/controllers/completions_controller.rb b/app/controllers/completions_controller.rb index 4679402..8c68f38 100644 --- a/app/controllers/completions_controller.rb +++ b/app/controllers/completions_controller.rb @@ -37,9 +37,9 @@ class CompletionsController < ApplicationController if @completion.save extend_completions!(@completion.contestant) if @contestant && !params[:completion].key?(:message_id) - redirect_to edit_contest_contestant_path(@contest, @contestant) + redirect_to edit_contest_contestant_path(@contest, @contestant), notice: t("completions.new.notice") else - redirect_to @contest + redirect_to @contest, notice: t("completions.new.notice") end else if params[:completion].key?(:message_id) @@ -61,9 +61,9 @@ class CompletionsController < ApplicationController if @completion.update(completion_params) extend_completions!(@completion.contestant) if @contestant - redirect_to edit_contest_contestant_path(@contest, @contestant) + redirect_to edit_contest_contestant_path(@contest, @contestant), notice: t("completions.edit.notice") else - redirect_to @contest + redirect_to @contest, notice: t("completions.edit.notice") end else if @contestant @@ -79,9 +79,9 @@ class CompletionsController < ApplicationController @completion.destroy if params[:contestant_id] - redirect_to contest_contestant_path(@contest, params[:contestant_id]) + redirect_to contest_contestant_path(@contest, params[:contestant_id]), notice: t("completions.destroy.notice") else - redirect_to contest_path(@contest) + redirect_to contest_path(@contest), notice: t("completions.destroy.notice") end end diff --git a/app/controllers/contestants_controller.rb b/app/controllers/contestants_controller.rb index 2e763dc..82d2304 100644 --- a/app/controllers/contestants_controller.rb +++ b/app/controllers/contestants_controller.rb @@ -24,7 +24,7 @@ class ContestantsController < ApplicationController @contestant = Contestant.new(contestant_params) @contestant.contest_id = @contest.id if @contestant.save - redirect_to contest_path(@contest) + redirect_to contest_path(@contest), notice: t("contestants.new.notice") else @action_name = t("helpers.buttons.back") @action_path = contest_path(@contest) @@ -36,7 +36,7 @@ class ContestantsController < ApplicationController authorize @contest if @contestant.update(contestant_params) - redirect_to @contest + redirect_to @contest, notice: t("contestants.edit.notice") else @action_name = t("helpers.buttons.back") @action_path = contest_path(@contest) @@ -48,7 +48,7 @@ class ContestantsController < ApplicationController authorize @contest @contestant.destroy - redirect_to contest_path(@contest) + redirect_to contest_path(@contest), notice: t("contestants.destroy.notice") end def import @@ -101,7 +101,7 @@ class ContestantsController < ApplicationController end end end - redirect_to contest_path(@contest) + redirect_to contest_path(@contest), notice: t("contestants.import.notice") else @action_name = t("helpers.buttons.back") @action_path = contest_path(@contest) diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 505f38b..f5bf010 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -40,7 +40,7 @@ class ContestsController < ApplicationController @contest = Contest.new(contest_params) @contest.user_id = current_user.id if @contest.save - redirect_to @contest + redirect_to @contest, notice: t("contests.new.notice") else render :new, status: :unprocessable_entity end @@ -50,7 +50,7 @@ class ContestsController < ApplicationController authorize @contest if @contest.update(contest_params) - redirect_to @contest + redirect_to @contest, notice: t("contests.edit.notice") else @action_name = t("helpers.buttons.back") @action_path = contest_path(@contest) @@ -60,6 +60,9 @@ class ContestsController < ApplicationController def destroy authorize @contest + + @contest.destroy + redirect_to contests_path, notice: t("contests.destroy.notice") end def scoreboard diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 2901903..f0d5b72 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -65,7 +65,7 @@ class MessagesController < ApplicationController @message = Message.find(params[:id]) @message.destroy - redirect_to contest_path(@contest) + redirect_to contest_path(@contest), notice: t("messages.destroy.notice") end private diff --git a/app/controllers/puzzles_controller.rb b/app/controllers/puzzles_controller.rb index 6167abd..025029a 100644 --- a/app/controllers/puzzles_controller.rb +++ b/app/controllers/puzzles_controller.rb @@ -23,7 +23,7 @@ class PuzzlesController < ApplicationController @puzzle = Puzzle.new(puzzle_params) @puzzle.contest_id = @contest.id if @puzzle.save - redirect_to contest_path(@contest) + redirect_to contest_path(@contest), notice: t("puzzles.new.notice") else @action_name = t("helpers.buttons.back") @action_path = contest_path(@contest) @@ -35,7 +35,7 @@ class PuzzlesController < ApplicationController authorize @contest if @puzzle.update(puzzle_params) - redirect_to @contest + redirect_to @contest, notice: t("puzzles.edit.notice") else @action_name = t("helpers.buttons.back") @action_path = contest_path(@contest) @@ -47,7 +47,7 @@ class PuzzlesController < ApplicationController authorize @contest @puzzle.destroy - redirect_to contest_path(@contest) + redirect_to contest_path(@contest), notice: t("puzzles.destroy.notice") end private diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 95b8859..6a56fd7 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -9,7 +9,7 @@ class SessionsController < ApplicationController def create if user = User.authenticate_by(params.permit(:email_address, :password)) start_new_session_for user - redirect_to after_authentication_url + redirect_to after_authentication_url, notice: t("sessions.new.notice") else redirect_to new_session_path, alert: "Try another email address or password." end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bbdec6d..e87b0e1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -15,7 +15,7 @@ class UsersController < ApplicationController authorize @user if @user.update(user_params) - redirect_to contests_path + redirect_to contests_path, notice: t("users.edit.notice") else render :edit, status: :unprocessable_entity end @@ -38,7 +38,7 @@ class UsersController < ApplicationController @user = User.new(user_params) if @user.save - redirect_to users_path + redirect_to users_path, notice: t("users.new.notice") else render :new, status: :unprocessable_entity end diff --git a/app/views/layouts/authenticated.html.slim b/app/views/layouts/authenticated.html.slim index 7c968b0..a24c54a 100644 --- a/app/views/layouts/authenticated.html.slim +++ b/app/views/layouts/authenticated.html.slim @@ -16,6 +16,33 @@ html = t("nav.settings") = button_to t("nav.log_out"), session_path, method: :delete + css: + .toast { + opacity: 0; + animation: fadeInAndOut 6s linear; + } + @keyframes fadeInAndOut { + 0%, 5%, 100% { opacity: 0 } + 7%, 85% { opacity: 1 } + } + javascript: + function closeToast(event) { + event.target.parentElement.parentElement.style.display = 'none'; + } + + .toast-container.position-fixed.p-3 style="right: 30px; top: 100px" + - flash.each do |type, msg| + .toast role="alert" aria-live="assertive" aria-atomic="true" style="display: block" + .toast-header + strong.me-auto + i.bi-bell-fill.fs-6.text-primary + =< type.humanize + small.text-body-secondary + | Just now + button.btn-close type="button" data-bs-dismiss="toast" aria-label="Close" onclick="closeToast(event)" + .toast-body + = msg + h1.mb-4 = @title - if @action_path diff --git a/config/locales/en.yml b/config/locales/en.yml index a4a78f3..0c839f6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -111,52 +111,65 @@ en: username: blank: Your username cannot be empty completions: + destroy: + notice: Completion deleted edit: + notice: Completion updated title: Edit completion new: + notice: Completion added title: New completion singular: completion contests: + destroy: + notice: Contest deleted edit: - title: "Edit contest settings" + notice: Contest updated + title: Edit contest settings index: - title: "Welcome %{username}!" - manage_contests: "Manage my contests" - new_contest: "Create a new contest" + title: Welcome %{username}! + manage_contests: Manage my contests + new_contest: Create a new contest new: - title: "New jigsaw puzzle contest" + notice: Contest added + title: New jigsaw puzzle contest scoreboard: title: "%{name}" show: title: "%{name}" - add_participant: Add contestant + add_participant: Add participant add_puzzle: Add puzzle copy_extension_url: Copy the URL for connecting from the browser extension open_public_scoreboard: Open public scoreboard url_copied: URL copied to the clipboard contestants: convert_csv: - title: "Import participants" + title: Import participants + destroy: + notice: Participant deleted edit: - title: "Participant" - team_title: "Teams" + notice: Participant updated + title: Participant + team_title: Teams finalize_import: - title: "Import participants" + title: Import participants import: - email_column: "Participant email" - import_column: "Import?" - name_column: "Participant name" - title: "Import participants" + email_column: Participant email + import_column: Import? + name_column: Participant name + notice: Participants imported + title: Import participants new: - title: "New participant" - team_title: "New team" - singular: "participant" - plural: "participants" + notice: Participant added + title: New participant + team_title: New team + singular: participant + plural: participants teams: - singular: "team" - plural: "teams" + singular: team + plural: teams upload_csv: - title: "Import participants" + title: Import participants helpers: badges: registration: "registration" @@ -180,6 +193,8 @@ en: messages: convert: title: New completion + destroy: + notice: Message deleted plural: "messages" singular: "message" warning: "You first need to add a puzzle before converting messages to completions." @@ -189,24 +204,31 @@ en: settings: "Settings" log_out: "Log out" puzzles: + destroy: + notice: Puzzle deleted edit: - title: "Edit contest puzzle" + notice: Puzzle updated + title: Edit contest puzzle form: fake_data_recommendation: It is recommended to first enter a fake name and image, and to use the real ones only once the contest starts. - image_select: "Select an image" + image_select: Select an image new: - title: "New contest puzzle" - singular: "puzzle" - plural: "puzzles" + notice: Puzzle added + title: New contest puzzle + singular: puzzle + plural: puzzles sessions: new: + notice: Login successful title: "Login to the Public Scoreboard app" users: edit: + notice: Settings updated title: "My settings" general_section: "General settings" password_section: "Change password" index: title: "All users" new: + notice: User created title: "New user" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 6dd0323..2ec305b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -82,20 +82,28 @@ fr: username: blank: Le nom d'utilisateur.ice est obligatoire completions: + destroy: + notice: Complétion supprimée edit: + notice: Complétion modifiée title: Modifier la complétion new: + notice: Complétion ajoutée title: Ajout d'une complétion singular: complétion contests: + destroy: + notice: Concours supprimé edit: - title: "Paramètres du concours" + notice: Concours modifié + title: Paramètres du concours index: - title: "Bienvenue %{username} !" - manage_contests: "Mes concours de puzzle" - new_contest: "Créer un nouveau concours" + title: Bienvenue %{username} ! + manage_contests: Mes concours de puzzle + new_contest: Créer un nouveau concours new: - title: "Nouveau concours" + notice: Concours ajouté + title: Nouveau concours scoreboard: title: "%{name}" show: @@ -107,27 +115,32 @@ fr: url_copied: L’URL a été copiée dans le presse-papier contestants: convert_csv: - title: "Importer des participant.e.s" + title: Importer des participant.e.s + destroy: + notice: Participant.e supprimé.e edit: - title: "Participant.e" - team_title: "Équipe" + notice: Participant.e modifié.e + title: Participant.e + team_title: Équipe finalize_import: - title: "Importer des participant.e.s" + title: Importer des participant.e.s import: - email_column: "Email des participant.e.s" - import_column: "Importer ?" - name_column: "Noms des participant.e.s" - title: "Importer des participant.e.s" + email_column: Email des participant.e.s + import_column: Importer ? + name_column: Noms des participant.e.s + notice: Participant.e.s importé.e.s + title: Importer des participant.e.s new: - title: "Nouveau.elle participant.e" - team_title: "Nouvelle équipe" - singular: "participant.e" - plural: "participant.e.s" + notice: Participant.e ajouté.e + title: Nouveau.elle participant.e + team_title: Nouvelle équipe + singular: participant.e + plural: participant.e.s teams: - singular: "équipe" - plural: "équipes" + singular: équipe + plural: équipes upload_csv: - title: "Importer des participant.e.s" + title: Importer des participant.e.s helpers: badges: registration: "auto-inscription" @@ -151,6 +164,8 @@ fr: messages: convert: title: Ajout d'une complétion + destroy: + notice: Message supprimé plural: "messages" singular: "message" warning: "Au moins un puzzle doit être ajouté avant de pouvoir convertir des messages en complétions." @@ -160,24 +175,31 @@ fr: settings: "Paramètres" log_out: "Déconnexion" puzzles: + destroy: + notice: Puzzle supprimé edit: - title: "Modifier le puzzle" + notice: Puzzle modifié + title: Modifier le puzzle form: fake_data_recommendation: Il est recommendé d'entrer de faux noms et images, et de mettre les vrais uniquement quand le concours démarre. - image_select: "Choisis une image" + image_select: Choisis une image new: - title: "Nouveau puzzle" - singular: "puzzle" - plural: "puzzles" + notice: Puzzle ajouté + title: Nouveau puzzle + singular: puzzle + plural: puzzles sessions: new: + notice: Connection réussie title: "Se connecter à l'app Public Scoreboard" users: edit: + notice: Paramètres modifiés title: "Mes paramètres" general_section: "Paramètres globaux" password_section: "Modifier mon mot de passe" index: title: "Tous.tes les utilisateur.ices" new: + notice: Utilisateur.ice ajouté.e title: "Nouveau.elle utilisateur.ice"