diff --git a/app/controllers/contestants_controller.rb b/app/controllers/contestants_controller.rb index 9ff677d..2e763dc 100644 --- a/app/controllers/contestants_controller.rb +++ b/app/controllers/contestants_controller.rb @@ -76,6 +76,8 @@ 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 @@ -92,15 +94,17 @@ class ContestantsController < ApplicationController @content.each_with_index do |row, i| if all_params["row_#{i}".to_sym] == "1" if @form.email_column == -1 - Contestant.create(name: row[@form.name_column], contest: @contest, time_seconds: 0) + Contestant.create(name: row[@form.name_column], contest: @contest) else logger.info("Email") - Contestant.create(name: row[@form.name_column], email: row[@form.email_column], contest: @contest, time_seconds: 0) + Contestant.create(name: row[@form.name_column], email: row[@form.email_column], contest: @contest) end end end redirect_to contest_path(@contest) 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 b2f7a1b..6f51a3e 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -52,6 +52,8 @@ class ContestsController < ApplicationController if @contest.update(contest_params) redirect_to @contest else + @action_name = t("helpers.buttons.back") + @action_path = contest_path(@contest) render :edit, status: :unprocessable_entity end end diff --git a/app/models/contestant.rb b/app/models/contestant.rb index 140bc99..d682344 100644 --- a/app/models/contestant.rb +++ b/app/models/contestant.rb @@ -23,14 +23,16 @@ class Contestant < ApplicationRecord belongs_to :contest has_many :completions, dependent: :destroy - before_create :initialize_time_seconds + before_validation :initialize_time_seconds_if_empty validates :name, presence: true validates :time_seconds, presence: true private - def initialize_time_seconds - self.time_seconds = 0 + def initialize_time_seconds_if_empty + if !self.time_seconds + self.time_seconds = 0 + end end end diff --git a/app/models/puzzle.rb b/app/models/puzzle.rb index 5246fe7..2fad557 100644 --- a/app/models/puzzle.rb +++ b/app/models/puzzle.rb @@ -24,5 +24,4 @@ class Puzzle < ApplicationRecord has_one_attached :image validates :name, presence: true - validates :brand, presence: true end diff --git a/app/views/completions/edit.html.slim b/app/views/completions/edit.html.slim index db56b82..e132bae 100644 --- a/app/views/completions/edit.html.slim +++ b/app/views/completions/edit.html.slim @@ -1 +1 @@ -= render "form", contest: @contest, completion: @completion, submit_text: "Save", method: :patch, url: "/contests/#{@contest.id}/completions/#{@completion.id}" \ No newline at end of file += render "form", contest: @contest, completion: @completion, submit_text: t("helpers.buttons.save"), method: :patch, url: "/contests/#{@contest.id}/completions/#{@completion.id}" \ No newline at end of file diff --git a/app/views/completions/new.html.slim b/app/views/completions/new.html.slim index e51a104..17044f4 100644 --- a/app/views/completions/new.html.slim +++ b/app/views/completions/new.html.slim @@ -1 +1 @@ -= render "form", completion: @completion, submit_text: "Create", method: :post, url: "/contests/#{@contest.id}/completions" \ No newline at end of file += render "form", completion: @completion, submit_text: t("helpers.buttons.create"), method: :post, url: "/contests/#{@contest.id}/completions" \ No newline at end of file diff --git a/app/views/contestants/_form.html.slim b/app/views/contestants/_form.html.slim index 93e4524..0ab529b 100644 --- a/app/views/contestants/_form.html.slim +++ b/app/views/contestants/_form.html.slim @@ -13,11 +13,12 @@ .form-floating = form.text_field :email, autocomplete: "off", class: "form-control" = form.label :email - .form-text Optional. Fill this only if you intend to send emails through this app. + .form-text + = t("activerecord.attributes.contestant.email_description") .row.mt-4 .col - if method == :patch - = link_to "Delete", contest_contestant_path(contest, contestant), data: { turbo_method: :delete }, class: "btn btn-danger me-2" + = link_to t("helpers.buttons.delete"), contest_contestant_path(contest, contestant), data: { turbo_method: :delete }, class: "btn btn-danger me-2" = form.submit submit_text, class: "btn btn-primary" - if method == :patch @@ -27,27 +28,35 @@ table.table.table-striped.table-hover thead tr + - if @contest.puzzles.size > 1 + th scope="col" + = t("activerecord.attributes.completion.display_time_from_start") + th scope="col" + = t("activerecord.attributes.completion.display_relative_time") + - else + th scope="col" + = t("activerecord.attributes.completion.display_time") th scope="col" - | Time since start - th scope="col" - | Relative time - th scope="col" - | Puzzle + = t("activerecord.attributes.completion.puzzle") tbody - @completions.each do |completion| tr scope="row" td - = completion.display_time_from_start + = completion.display_time_from_start + - if @contest.puzzles.size > 1 + td + = completion.display_relative_time td - = completion.display_relative_time - td - | #{completion.puzzle.name} - #{completion.puzzle.brand} + - if !completion.puzzle.brand.blank? + | #{completion.puzzle.name} - #{completion.puzzle.brand} + - else + | #{completion.puzzle.name} td a.btn.btn-sm.btn-secondary.me-2 href=edit_contest_completion_path(@contest, completion, contestant_id: contestant.id) - | Edit - = link_to "Delete", contest_completion_path(contest, completion, contestant_id: contestant.id), + = t("helpers.buttons.edit") + = link_to t("helpers.buttons.delete"), contest_completion_path(contest, completion, contestant_id: contestant.id), data: { turbo_method: :delete }, class: "btn btn-sm btn-secondary" .row .col a.btn.btn-primary href=new_contest_completion_path(@contest, contestant_id: contestant.id) - | Add completion + = t("helpers.buttons.add") diff --git a/app/views/contestants/convert_csv.html.slim b/app/views/contestants/convert_csv.html.slim index e07ab41..a3cce80 100644 --- a/app/views/contestants/convert_csv.html.slim +++ b/app/views/contestants/convert_csv.html.slim @@ -26,7 +26,7 @@ - @content[0].each_with_index do |_, i| th scope="col" = t("helpers.field") + "_#{i}" - th scope="col" + th scope="col" style="white-space: nowrap" = t("contestants.import.import_column") tbody - @content.each_with_index do |row, i| diff --git a/app/views/contestants/edit.html.slim b/app/views/contestants/edit.html.slim index fd4680d..e310242 100644 --- a/app/views/contestants/edit.html.slim +++ b/app/views/contestants/edit.html.slim @@ -1 +1 @@ -= render "form", contest: @contest, contestant: @contestant, submit_text: "Save", method: :patch, url: "/contests/#{@contest.id}/contestants/#{@contestant.id}" \ No newline at end of file += render "form", contest: @contest, contestant: @contestant, submit_text: t("helpers.buttons.save"), method: :patch, url: "/contests/#{@contest.id}/contestants/#{@contestant.id}" \ No newline at end of file diff --git a/app/views/contestants/new.html.slim b/app/views/contestants/new.html.slim index a9410a2..e644b50 100644 --- a/app/views/contestants/new.html.slim +++ b/app/views/contestants/new.html.slim @@ -1 +1 @@ -= render "form", contest: @contest, contestant: @contestant, submit_text: "Add", method: :post, url: "/contests/#{@contest.id}/contestants" \ No newline at end of file += 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/show.html.slim b/app/views/contests/show.html.slim index 711bf09..e6a74ae 100644 --- a/app/views/contests/show.html.slim +++ b/app/views/contests/show.html.slim @@ -103,7 +103,7 @@ thead tr th scope="col" - | Rank + = t("helpers.rank") th scope="col" = t("activerecord.attributes.contestant.name") th scope="col" diff --git a/config/locales/en.yml b/config/locales/en.yml index fb4ad11..007b480 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -38,6 +38,12 @@ en: greater_than: "Participant names are required" activerecord: attributes: + completion: + contestant: Participant + display_time: Time + display_time_from_start: Time since start + display_relative_time: Time for this puzzle + puzzle: Puzzle contest: name: "Name" team: "Team contest" @@ -45,7 +51,14 @@ en: allow_registration: "Allow registration" allow_registration_description: "Generates a shareable registration form for this contest" contestant: + completions: completions + display_time: Time + email: "Email" name: "Name" + email_description: "Optional. Used for sending emails through this app, or for identifying participants whose gmeet handle doesn't match their registered name." + csv_import: + file: File + separator: Separator message: author: "Author" processed: "Processed?" @@ -65,15 +78,28 @@ en: completion: attributes: display_time_from_start: + blank: Mandatory invalid: "Allowed formats: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx" puzzle_id: taken: "This contestant has already completed this puzzle" + contest: + attributes: + name: + blank: The contest name cannot be empty + contestant: + attributes: + name: + blank: The participant name cannot be empty csv_import: attributes: file: blank: "No file selected" empty: "This file is empty" not_a_csv_file: "it must be a CSV file" + puzzle: + attributes: + name: + blank: The puzzle name cannot be empty completions: edit: title: "Edit completion" @@ -132,9 +158,12 @@ en: create: "Create" delete: "Delete" edit: "Edit" - import: "CSV Import" - save: "Save" - field: "Field" + import: CSV Import + open: Open + save: Save + field: Field + none: No field selected + rank: Rank messages: convert: title: "New completion" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index f283d23..452b26b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -9,6 +9,12 @@ fr: greater_than: "Choisir une colonne pour les noms des participant.e.s est nécessaire" activerecord: attributes: + completion: + contestant_id: Participant.e + display_time: Temps + display_time_from_start: Temps depuis le début + display_relative_time: Temps pour ce puzzle + puzzle: Puzzle contest: name: "Nom" team: "Concours par équipes" @@ -16,7 +22,14 @@ fr: allow_registration: "Autoriser l'inscription via l'interface" allow_registration_description: "Génère un formulaire d'inscription pour ce concours" contestant: + completions: Complétions + display_time: Temps + email: "Email" name: "Nom" + email_description: "Optionnel. Utile pour envoyer des emails aux participant.e.s depuis cette app, ou pour reconnaître les pseudos gmeet quand ils ne correspondent pas au nom préalablement entré." + csv_import: + file: Fichier + separator: Délimiteur message: author: "Auteur.ice" processed: "Traité ?" @@ -36,15 +49,28 @@ fr: completion: attributes: display_time_from_start: + blank: Obligatoire invalid: "Formats autorisés: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx" puzzle_id: taken: "Ce.tte participant.e a déjà complété ce puzzle" + contest: + attributes: + name: + blank: Le nom du concours ne peut pas être vide + contestant: + attributes: + name: + blank: Le nom du ou de la participant.e ne peut pas être vide csv_import: attributes: file: blank: "Aucun fichier sélectionné" empty: "Ce fichier est vide" not_a_csv_file: "Le fichier doit être au format CSV" + puzzle: + attributes: + name: + blank: Le nom du puzzle est obligatoire completions: edit: title: "Modifier la complétion" @@ -103,9 +129,12 @@ fr: create: "Créer" delete: "Supprimer" edit: "Modifier" - import: "Importer un CSV" - save: "Modifier" - field: "Champ" + import: Importer un CSV + open: Détails + save: Modifier + field: Champ + none: Aucun champ sélectionné + rank: Rang messages: convert: title: "Ajout d'une complétion"