Offline participation form: ask for missing/remaining pieces
This commit is contained in:
@@ -35,7 +35,9 @@ class CompletionsController < ApplicationController
|
||||
@completion = Completion.new(completion_params)
|
||||
@completion.contest_id = @contest.id
|
||||
if @completion.save
|
||||
if @completion.display_time_from_start.present?
|
||||
extend_completions!(@completion.contestant)
|
||||
end
|
||||
if @contestant && !params[:completion].key?(:message_id)
|
||||
redirect_to edit_contest_contestant_path(@contest, @contestant), notice: t("completions.new.notice")
|
||||
else
|
||||
|
||||
@@ -147,6 +147,8 @@ class ContestsController < ApplicationController
|
||||
@offline.completed = true
|
||||
@offline.end_time = Time.now()
|
||||
@offline.images.attach(params[:offline][:end_image])
|
||||
@offline.missing_pieces = params[:offline][:missing_pieces]
|
||||
@offline.remaining_pieces = params[:offline][:remaining_pieces]
|
||||
if @offline.save
|
||||
if @contest.puzzles.length > 0
|
||||
dp = display_time(@offline.end_time.to_i - @offline.start_time.to_i)
|
||||
@@ -209,6 +211,6 @@ class ContestsController < ApplicationController
|
||||
end
|
||||
|
||||
def offline_end_params
|
||||
params.expect(offline: [ :completed, :end_image ])
|
||||
params.expect(offline: [ :completed, :end_image, :remaining_pieces, :missing_pieces ])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,16 +34,17 @@ class Completion < ApplicationRecord
|
||||
belongs_to :puzzle
|
||||
belongs_to :message, optional: true
|
||||
|
||||
before_save :add_time_seconds
|
||||
before_save :add_time_seconds, if: -> { display_time_from_start.present? }
|
||||
before_save :nullify_display_time
|
||||
|
||||
validates :display_time_from_start, presence: true, format: { with: /\A(((\d\d|\d):\d\d|\d\d|\d):\d\d|\d\d|\d)\z/ }, if: -> { remaining_pieces == nil }
|
||||
validates :contestant_id, uniqueness: { scope: :puzzle }, if: -> { contest.puzzles.size == 1 }
|
||||
validates :puzzle_id, uniqueness: { scope: :contestant }, if: -> { contest.puzzles.size > 1 }
|
||||
validate :remaining_pieces_is_correct
|
||||
validates :remaining_pieces, numericality: { only_integer: true }, if: -> { remaining_pieces.present? }
|
||||
validate :remaining_pieces_is_correct, if: -> { remaining_pieces.present? }
|
||||
|
||||
def remaining_pieces_is_correct
|
||||
if self.remaining_pieces && self.remaining_pieces > self.puzzle.pieces
|
||||
if self.remaining_pieces > self.puzzle.pieces
|
||||
errors.add(:remaining_pieces, "Cannot be greater than the number of pieces for this puzzle")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
# id :integer not null, primary key
|
||||
# completed :boolean
|
||||
# end_time :datetime
|
||||
# missing_pieces :integer
|
||||
# name :string not null
|
||||
# remaining_pieces :integer
|
||||
# start_time :datetime not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
@@ -36,7 +38,27 @@ class Offline < ApplicationRecord
|
||||
validate :end_image_is_present
|
||||
validate :start_image_is_present
|
||||
|
||||
validates :missing_pieces, numericality: { only_integer: true }, if: -> { missing_pieces.present? }
|
||||
validates :remaining_pieces, numericality: { only_integer: true }, if: -> { remaining_pieces.present? }
|
||||
validate :missing_pieces_is_correct, if: -> { missing_pieces.present? }
|
||||
validate :remaining_pieces_is_correct, if: -> { remaining_pieces.present? }
|
||||
|
||||
def missing_pieces_is_correct
|
||||
if self.contest.puzzles.length > 0 && self.missing_pieces > self.contest.puzzles[0].pieces
|
||||
errors.add(:remaining_pieces, "Cannot be greater than the number of pieces for this puzzle")
|
||||
end
|
||||
end
|
||||
|
||||
def remaining_pieces_is_correct
|
||||
if self.contest.puzzles.length > 0 && self.remaining_pieces > self.contest.puzzles[0].pieces
|
||||
errors.add(:remaining_pieces, "Cannot be greater than the number of pieces for this puzzle")
|
||||
end
|
||||
end
|
||||
|
||||
def end_image_is_present
|
||||
logger = Logger.new(STDOUT)
|
||||
logger.info(self.missing_pieces)
|
||||
logger.info(self.missing_pieces.present?)
|
||||
if self.completed && self.images.length < 2
|
||||
errors.add(:end_image, I18n.t("activerecord.errors.models.offline.attributes.end_image.blank"))
|
||||
end
|
||||
|
||||
@@ -35,6 +35,20 @@
|
||||
}
|
||||
|
||||
setMaxUploadSize();
|
||||
.row.mt-4.mb-3
|
||||
.col
|
||||
.form-floating
|
||||
= form.text_field :missing_pieces, autocomplete: "off", class: "form-control"
|
||||
= form.label :missing_pieces
|
||||
.form-text
|
||||
= t("offlines.form.missing_pieces")
|
||||
.row.mb-3
|
||||
.col
|
||||
.form-floating
|
||||
= form.text_field :remaining_pieces, autocomplete: "off", class: "form-control"
|
||||
= form.label :remaining_pieces
|
||||
.form-text
|
||||
= t("offlines.form.remaining_pieces")
|
||||
.row.mt-4
|
||||
.col
|
||||
= form.submit t("helpers.buttons.end"), class: "btn btn-primary"
|
||||
@@ -78,6 +78,8 @@ en:
|
||||
time: Time
|
||||
offline:
|
||||
name: Your name
|
||||
missing_pieces: Missing pieces
|
||||
remaining_pieces: Remaining pieces
|
||||
puzzle:
|
||||
brand: Brand
|
||||
image: Image
|
||||
@@ -102,6 +104,9 @@ en:
|
||||
invalid: "Allowed formats: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx"
|
||||
puzzle_id:
|
||||
taken: "This contestant has already completed this puzzle"
|
||||
remaining_pieces:
|
||||
not_an_integer: This is not an integer
|
||||
not_a_number: This is not an integer
|
||||
contest:
|
||||
attributes:
|
||||
name:
|
||||
@@ -120,8 +125,14 @@ en:
|
||||
attributes:
|
||||
end_image:
|
||||
blank: Please upload an image
|
||||
missing_pieces:
|
||||
not_an_integer: This is not an integer
|
||||
not_a_number: This is not an integer
|
||||
name:
|
||||
blank: Please enter a name for your participation
|
||||
remaining_pieces:
|
||||
not_an_integer: This is not an integer
|
||||
not_a_number: This is not an integer
|
||||
start_image:
|
||||
blank: Please upload an image
|
||||
puzzle:
|
||||
@@ -256,7 +267,9 @@ en:
|
||||
form:
|
||||
already_submitted: You have already completed the puzzle
|
||||
completed_message: Thanks for your participation!
|
||||
end_image_select: Take a photo of your completed puzzle
|
||||
end_image_select: Take a photo of your completed puzzle, or on the state it is if you decide to give up
|
||||
missing_pieces: If completed, indicate the number of missing pieces, if any
|
||||
remaining_pieces: If your puzzle isn't complete, indicate here the number of remaining pieces to assemble
|
||||
start_image_select: Take a photo of the puzzle with the provided code written on a paper before starting it
|
||||
start_message: Let's go!
|
||||
puzzles:
|
||||
|
||||
@@ -49,6 +49,8 @@ fr:
|
||||
time: Temps
|
||||
offline:
|
||||
name: Ton nom ou pseudo
|
||||
missing_pieces: Pièces manquantes
|
||||
remaining_pieces: Pièces restantes
|
||||
puzzle:
|
||||
brand: Marque
|
||||
image: Image
|
||||
@@ -73,6 +75,9 @@ fr:
|
||||
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"
|
||||
remaining_pieces:
|
||||
not_an_integer: Ce n'est pas un nombre entier
|
||||
not_a_number: Ce n'est pas un nombre entier
|
||||
contest:
|
||||
attributes:
|
||||
name:
|
||||
@@ -91,8 +96,14 @@ fr:
|
||||
attributes:
|
||||
end_image:
|
||||
blank: Tu dois inclure cette image pour pouvoir valider ton puzzle complété
|
||||
missing_pieces:
|
||||
not_an_integer: Ce n'est pas un entier
|
||||
not_a_number: Ce n'est pas un entier
|
||||
name:
|
||||
blank: Tu dois entrer un nom pour pouvoir participer
|
||||
remaining_pieces:
|
||||
not_an_integer: Ce n'est pas un entier
|
||||
not_a_number: Ce n'est pas un entier
|
||||
start_image:
|
||||
blank: Tu dois inclure cette image pour pouvoir participer
|
||||
puzzle:
|
||||
@@ -227,7 +238,9 @@ fr:
|
||||
form:
|
||||
already_submitted: Tu as déjà complété ton puzzle
|
||||
completed_message: Merci pour ta participation !
|
||||
end_image_select: Prends une photo du puzzle une fois complété
|
||||
end_image_select: Prends une photo du puzzle une fois complété, ou de l'état actuel si tu choisis de t'arrêter là
|
||||
missing_pieces: Si complété, indique le nombre de pièces manquantes s'il y en a
|
||||
remaining_pieces: Si tu as choisis de t'arrêter avant la fin du puzzle, indique ici le nombre de pièces restantes à assembler
|
||||
start_image_select: Prends une photo du puzzle avant de le commencer, avec le code donné par l'organisateur.ice écrit sur du papier
|
||||
start_message: C'est parti !
|
||||
puzzles:
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddMissingPiecesToOffline < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :offlines, :missing_pieces, :integer
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddRemainingPiecesToOffline < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :offlines, :remaining_pieces, :integer
|
||||
end
|
||||
end
|
||||
4
db/schema.rb
generated
4
db/schema.rb
generated
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_11_05_153647) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_11_08_082751) do
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
@@ -135,6 +135,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_11_05_153647) do
|
||||
t.string "name", null: false
|
||||
t.boolean "completed"
|
||||
t.integer "contestant_id"
|
||||
t.integer "missing_pieces"
|
||||
t.integer "remaining_pieces"
|
||||
t.index ["contest_id"], name: "index_offlines_on_contest_id"
|
||||
t.index ["contestant_id"], name: "index_offlines_on_contestant_id"
|
||||
end
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
# id :integer not null, primary key
|
||||
# completed :boolean
|
||||
# end_time :datetime
|
||||
# missing_pieces :integer
|
||||
# name :string not null
|
||||
# remaining_pieces :integer
|
||||
# start_time :datetime not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
# id :integer not null, primary key
|
||||
# completed :boolean
|
||||
# end_time :datetime
|
||||
# missing_pieces :integer
|
||||
# name :string not null
|
||||
# remaining_pieces :integer
|
||||
# start_time :datetime not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
||||
Reference in New Issue
Block a user