diff --git a/app/Http/Controllers/Tabulation/AdvancementController.php b/app/Http/Controllers/Tabulation/AdvancementController.php index 93eac92..e0abc34 100644 --- a/app/Http/Controllers/Tabulation/AdvancementController.php +++ b/app/Http/Controllers/Tabulation/AdvancementController.php @@ -5,23 +5,48 @@ namespace App\Http\Controllers\Tabulation; use App\Http\Controllers\Controller; use App\Models\Audition; use App\Models\Entry; -use App\Services\TabulationService; use Illuminate\Http\Request; class AdvancementController extends Controller { - protected TabulationService $tabulationService; - - public function __construct(TabulationService $tabulationService) + public function __construct() { - $this->tabulationService = $tabulationService; + } public function status() { - $auditions = $this->tabulationService->getAuditionsWithStatus('advancement'); + $auditions = Audition::forAdvancement() + ->with('flags') + ->withCount([ + 'entries' => function ($query) { + $query->where('for_advancement', 1); + }, + ]) + ->withCount([ + 'unscoredEntries' => function ($query) { + $query->where('for_advancement', 1); + }, + ]) + ->get(); + $auditionData = []; + $auditions->each(function ($audition) use (&$auditionData) { + $scoredPercent = ($audition->entries_count > 0) ? + round((($audition->entries_count - $audition->unscored_entries_count) / $audition->entries_count) * 100) + : 100; + $auditionData[] = [ + 'id' => $audition->id, + 'name' => $audition->name, + 'entries_count' => $audition->entries_count, + 'unscored_entries_count' => $audition->unscored_entries_count, + 'scored_entries_count' => $audition->entries_count - $audition->unscored_entries_count, + 'scored_percentage' => $scoredPercent, + 'scoring_complete' => $audition->unscored_entries_count == 0, + 'published' => $audition->hasFlag('advancement_published'), + ]; + }); - return view('tabulation.advancement.status', compact('auditions')); + return view('tabulation.advancement.status', compact('auditionData')); } public function ranking(Request $request, Audition $audition) @@ -29,7 +54,6 @@ class AdvancementController extends Controller $entries = $this->tabulationService->auditionEntries($audition->id, 'advancement'); $entries->load('advancementVotes'); - $scoringComplete = $entries->every(function ($entry) { return $entry->scoring_complete; }); @@ -47,7 +71,8 @@ class AdvancementController extends Controller $entry->addFlag('will_advance'); } - return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', 'Passers have been set successfully'); + return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', + 'Passers have been set successfully'); } public function clearAuditionPassers(Request $request, Audition $audition) @@ -57,6 +82,7 @@ class AdvancementController extends Controller $entry->removeFlag('will_advance'); } - return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', 'Passers have been cleared successfully'); + return redirect()->route('advancement.ranking', ['audition' => $audition->id])->with('success', + 'Passers have been cleared successfully'); } } diff --git a/resources/views/tabulation/advancement/status.blade.php b/resources/views/tabulation/advancement/status.blade.php index d2e269a..2385bef 100644 --- a/resources/views/tabulation/advancement/status.blade.php +++ b/resources/views/tabulation/advancement/status.blade.php @@ -13,33 +13,27 @@ - @foreach($auditions as $audition) - @php - $percent = 100; - if($audition->advancement_entries_count > 0) { - $percent = round(($audition->scored_entries_count / $audition->advancement_entries_count) * 100); - } - @endphp + @foreach($auditionData as $audition) - +
- {{ $audition->name }} - {{ $audition->scored_entries_count }} / {{ $audition->advancement_entries_count }} Scored + {{ $audition['name'] }} + {{ $audition['scored_entries_count'] }} / {{ $audition['entries_count'] }} Scored
-
+
- @if( $audition->scored_entries_count == $audition->advancement_entries_count) + @if( $audition['scoring_complete']) @endif - @if( $audition->hasFlag('advancement_published')) + @if( $audition['published']) @endif diff --git a/tests/Feature/Pages/Advancement/statusTest.php b/tests/Feature/Pages/Advancement/statusTest.php new file mode 100644 index 0000000..c83969e --- /dev/null +++ b/tests/Feature/Pages/Advancement/statusTest.php @@ -0,0 +1,41 @@ +assertRedirect(route('home')); + actingAs(User::factory()->create()); + get(route('advancement.status')) + ->assertRedirect(route('dashboard')) + ->assertSessionHas('error', 'You are not authorized to perform this action'); +}); +it('responds to an admin or tab user', function () { + actAsAdmin(); + get(route('advancement.status')) + ->assertOk(); + actAsTab(); + get(route('advancement.status')) + ->assertOk(); +}); +it('includes advancement auditions', function () { + $audition = Audition::factory()->create(); + actAsAdmin(); + get(route('advancement.status')) + ->assertOk() + ->assertSee($audition->name); +}); +it('does not include auditions not for advancement', function () { + $audition = Audition::factory()->seatingOnly()->create(); + actAsAdmin(); + get(route('advancement.status')) + ->assertOk() + ->assertDontSee($audition->name); +});