diff --git a/app/Http/Controllers/Tabulation/EntryFlagController.php b/app/Http/Controllers/Tabulation/EntryFlagController.php index 0c3ef77..14189e2 100644 --- a/app/Http/Controllers/Tabulation/EntryFlagController.php +++ b/app/Http/Controllers/Tabulation/EntryFlagController.php @@ -21,21 +21,42 @@ class EntryFlagController extends Controller $validData = $request->validate([ 'entry_id' => 'required|exists:entries,id', ]); - $entry = Entry::with('flags')->find($validData['entry_id']); - + $entry = Entry::with('flags')->withCount('scoreSheets')->find($validData['entry_id']); if ($entry->hasFlag('no_show')) { $formId = 'no-show-cancellation-form'; $buttonName = 'Remove No Show'; - $submitRouteName = 'entry-flags.enterNoShow'; - $cardHeading = 'Undo No Show'; + $submitRouteName = 'entry-flags.undoNoShow'; + $cardHeading = 'Undo No-Show'; + $method = 'DELETE'; } else { $formId = 'no-show-confirmation-form'; $buttonName = 'Confirm No Show'; $submitRouteName = 'entry-flags.enterNoShow'; - $cardHeading = 'Confirm No Show'; + $cardHeading = 'Confirm No-Show'; + $method = 'POST'; + } + $scores = []; + if($entry->score_sheets_count > 0) { + $scores = $entry->scoreSheets; + $scores->load('judge'); } - return view('tabulation.no_show_confirm', - compact('entry', 'formId', 'buttonName', 'submitRouteName', 'cardHeading')); + compact('entry', + 'formId', + 'buttonName', + 'submitRouteName', + 'cardHeading', + 'method', + 'scores')); + } + + public function enterNoShow(Entry $entry) + { + // + } + + public function undoNoShow(Entry $entry) + { + // } } diff --git a/database/seeders/ScoreAllAuditions.php b/database/seeders/ScoreAllAuditions.php index 230199d..9a9f569 100644 --- a/database/seeders/ScoreAllAuditions.php +++ b/database/seeders/ScoreAllAuditions.php @@ -4,7 +4,6 @@ namespace Database\Seeders; use App\Models\ScoreSheet; use App\Models\User; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; class ScoreAllAuditions extends Seeder @@ -16,23 +15,23 @@ class ScoreAllAuditions extends Seeder { $judges = User::all(); foreach ($judges as $judge) { - foreach( $judge->rooms as $room) { - foreach ($room->auditions as $audition){ + foreach ($judge->rooms as $room) { + foreach ($room->auditions as $audition) { $scoringGuide = $audition->scoringGuide; $subscores = $scoringGuide->subscores; - foreach ($audition->entries as $entry){ + foreach ($audition->entries as $entry) { $scoreArray = []; foreach ($subscores as $subscore) { $scoreArray[$subscore->id] = [ - 'score' => mt_rand(0,100), + 'score' => mt_rand(0, 100), 'subscore_id' => $subscore->id, - 'subscore_name' => $subscore->name + 'subscore_name' => $subscore->name, ]; } ScoreSheet::create([ 'user_id' => $judge->id, 'entry_id' => $entry->id, - 'subscores' => $scoreArray + 'subscores' => $scoreArray, ]); } } diff --git a/resources/views/components/form/toggle-checkbox.blade.php b/resources/views/components/form/toggle-checkbox.blade.php index 3d6086a..1e88ebf 100644 --- a/resources/views/components/form/toggle-checkbox.blade.php +++ b/resources/views/components/form/toggle-checkbox.blade.php @@ -2,7 +2,7 @@
@error($name) diff --git a/resources/views/tabulation/no_show_confirm.blade.php b/resources/views/tabulation/no_show_confirm.blade.php index 95becb9..0608e60 100644 --- a/resources/views/tabulation/no_show_confirm.blade.php +++ b/resources/views/tabulation/no_show_confirm.blade.php @@ -1,5 +1,30 @@ - - + + @if($scores) + + + WARNING: Entry has existing scores + +
+ @foreach($scores as $score) +
+
{{ $score->judge->full_name() }}
+
    + @foreach($score->subscores as $subscore) +
    + {{ $subscore['subscore_name'] }} + {{ $subscore['score'] }} +
    + @endforeach +
+
+ @endforeach +
+
+ I understand that marking this entry as a no-show will delete existing scores. The scores cannot be recovered. +
+
+ @endif + {{ $cardHeading }} @@ -11,8 +36,8 @@ - - {{ $buttonName }} + + {{ $buttonName }} diff --git a/resources/views/tabulation/no_show_confirm_score_switch.blade.php b/resources/views/tabulation/no_show_confirm_score_switch.blade.php new file mode 100644 index 0000000..e2d6a3d --- /dev/null +++ b/resources/views/tabulation/no_show_confirm_score_switch.blade.php @@ -0,0 +1,6 @@ +
+ diff --git a/routes/tabulation.php b/routes/tabulation.php index c9d6e18..956ddde 100644 --- a/routes/tabulation.php +++ b/routes/tabulation.php @@ -19,6 +19,7 @@ Route::middleware(['auth', 'verified', CheckIfCanTab::class])->group(function () Route::get('/choose_no_show', 'noShowSelect')->name('entry-flags.noShowSelect'); Route::get('/propose-no-show', 'noShowConfirm')->name('entry-flags.confirmNoShow'); Route::post('/no-show/{entry}', 'enterNoShow')->name('entry-flags.enterNoShow'); + Route::delete('/no-show/{entry}', 'undoNoShow')->name('entry-flags.undoNoShow'); }); // Generic Tabulation Routes diff --git a/tests/Feature/Pages/Tabulation/noShowConfirmTest.php b/tests/Feature/Pages/Tabulation/noShowConfirmTest.php index 4bfb895..4e09a6f 100644 --- a/tests/Feature/Pages/Tabulation/noShowConfirmTest.php +++ b/tests/Feature/Pages/Tabulation/noShowConfirmTest.php @@ -1,7 +1,13 @@ hasCSRF(); }); }); +it('shows a box with scores if the entry is scored', function () { + // Arrange + $judges = User::factory()->count(3)->create(); + $room = Room::factory()->create(); + $judges->each(fn ($judge) => $room->addJudge($judge->id)); + $scoringGuide = ScoringGuide::factory()->create(); + SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $scoringGuide->id]); + $audition = Audition::factory()->create(['room_id' => $room->id, 'scoring_guide_id' => $scoringGuide->id]); + $entry = Entry::factory()->create(['audition_id' => $audition->id]); + // Run the ScoreAllAuditions seeder + Artisan::call('db:seed', ['--class' => 'ScoreAllAuditions']); + // Act & Assert + actAsTab(); + $response = get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])); + $response->assertOk() + ->assertSee('WARNING') + ->assertSee('existing scores'); + $judges->each(fn ($judge) => $response->assertSee($judge->full_name())); + +});