Implement missing & remaining pieces propagation + cleaner forms
All checks were successful
CI / scan_ruby (push) Successful in 18s
CI / scan_js (push) Successful in 14s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 34s

This commit is contained in:
sto
2025-11-10 12:26:48 +01:00
parent 6549124c08
commit f4136ea58a
15 changed files with 175 additions and 38 deletions

View File

@@ -131,7 +131,7 @@ class ContestsController < ApplicationController
not_found and return
end
if @offline.images.length > 1
if @offline.submitted
render :offline_already_submitted and return
end
end
@@ -144,11 +144,15 @@ class ContestsController < ApplicationController
not_found and return
end
@offline.completed = true
@offline.submitted = true
@offline.completed = params[:offline][:completed]
@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.completed
@offline.missing_pieces = params[:offline][:missing_pieces]
else
@offline.remaining_pieces = params[:offline][:remaining_pieces]
end
if @offline.save
if @contest.puzzles.length > 0
dp = display_time(@offline.end_time.to_i - @offline.start_time.to_i)
@@ -156,7 +160,10 @@ class ContestsController < ApplicationController
Completion.create(contest: @contest,
contestant: contestant,
puzzle: @contest.puzzles[0],
display_time_from_start: dp)
completed: @offline.completed,
display_time_from_start: dp,
missing_pieces: @offline.missing_pieces,
remaining_pieces: @offline.remaining_pieces)
extend_completions!(contestant)
end
redirect_to "/public/#{@contest.friendly_id}/offline/#{@offline.generate_token_for(:token)}/completed"