Decline button works on doublers on seating page

This commit is contained in:
Matt Young 2024-06-21 11:36:49 -05:00
parent f9e936fd07
commit b21902fc9a
5 changed files with 168 additions and 118 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Tabulation;
use App\Http\Controllers\Controller;
use App\Models\Entry;
use App\Models\EntryFlag;
use App\Services\DoublerService;
class DoublerDecisionController extends Controller
{
protected $doublerService;
public function __construct(DoublerService $doublerService)
{
$this->doublerService = $doublerService;
}
public function accept(Entry $entry)
{
//
}
public function decline(Entry $entry)
{
if ($entry->hasFlag('declined')) {
return redirect()->back()->with('caution', 'Entry is already declined');
}
EntryFlag::create([
'entry_id' => $entry->id,
'flag_name' => 'declined',
]);
$this->doublerService->refreshDoublerCache();
$returnMessage = $entry->student->full_name().' declined seating in '.$entry->audition->name;
return redirect()->back()->with('success', $returnMessage);
}
}

View File

@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EntryFlag extends Model class EntryFlag extends Model
{ {
protected $guarded = [];
// Possible flags include // Possible flags include
// - declined: used if a doubler declines a seat in this audition. Checked by DoublerService // - declined: used if a doubler declines a seat in this audition. Checked by DoublerService
public function entry(): BelongsTo public function entry(): BelongsTo

View File

@ -48,10 +48,13 @@ class DoublerService
/** /**
* Returns an array of information about each entry for a specific doubler. Info for each entry includes * Returns an array of information about each entry for a specific doubler. Info for each entry includes
* entryID
* auditionID * auditionID
* auditionName * auditionName
* rank => This student's rank in the given audition * rank => This student's rank in the given audition
* unscored => How many entries remain to be scored in this audition * unscored => How many entries remain to be scored in this audition
* limits => acceptance limits for this audition
* status => accepted, declined, or undecided
* *
* @param int $studentId The ID of the doubler * @param int $studentId The ID of the doubler
*/ */
@ -87,6 +90,7 @@ class DoublerService
$status = 'undecided'; $status = 'undecided';
} }
$info[$entry->id] = [ $info[$entry->id] = [
'entryID' => $entry->id,
'auditionID' => $entry->audition_id, 'auditionID' => $entry->audition_id,
'auditionName' => $this->auditionCacheService->getAudition($entry->audition_id)->name, 'auditionName' => $this->auditionCacheService->getAudition($entry->audition_id)->name,
'rank' => $this->tabulationService->entryRank($entry), 'rank' => $this->tabulationService->entryRank($entry),

View File

@ -1,6 +1,6 @@
@props(['doublerEntryInfo']) @props(['doublerEntryInfo'])
@php($doublerButtonClasses = 'hidden rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:block')
<ul role="list" class="divide-y divide-gray-100"> <ul role="list" class="divide-y divide-gray-200">
@foreach($doublerEntryInfo as $info) @foreach($doublerEntryInfo as $info)
<li class="flex items-center justify-between gap-x-6 py-5"> <li class="flex items-center justify-between gap-x-6 py-5">
@ -31,8 +31,13 @@
<div class="flex items-center gap-x-4"> <div class="flex items-center gap-x-4">
<a href="#" class="hidden rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:block">Accept</a> @if ($info['status'] === 'undecided')
<a href="#" class="hidden rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:block">Decline</a> <button class="{{ $doublerButtonClasses }}">Accept</button>
<form method="POST" action="{{ route('doubler.decline',['entry'=>$info['entryID']]) }}">
@csrf
<button class="{{ $doublerButtonClasses }}">Decline</button>
</form>
@endif
</div> </div>
</li> </li>
@endforeach @endforeach

View File

@ -1,13 +1,12 @@
<?php <?php
use App\Http\Controllers\Admin\AuditionController;
use App\Http\Controllers\DashboardController; use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EntryController; use App\Http\Controllers\EntryController;
use App\Http\Controllers\FilterController; use App\Http\Controllers\FilterController;
use App\Http\Controllers\JudgingController; use App\Http\Controllers\JudgingController;
use App\Http\Controllers\SchoolController; use App\Http\Controllers\SchoolController;
use App\Http\Controllers\StudentController; use App\Http\Controllers\StudentController;
use App\Http\Controllers\Tabulation\TabulationController; use App\Http\Controllers\Tabulation\DoublerDecisionController;
use App\Http\Controllers\TestController; use App\Http\Controllers\TestController;
use App\Http\Controllers\UserController; use App\Http\Controllers\UserController;
use App\Http\Middleware\CheckIfAdmin; use App\Http\Middleware\CheckIfAdmin;
@ -15,6 +14,7 @@ use App\Http\Middleware\CheckIfCanJudge;
use App\Http\Middleware\CheckIfCanTab; use App\Http\Middleware\CheckIfCanTab;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('rediscli', function () { Route::get('rediscli', function () {
return \Illuminate\Support\Facades\Redis::ping(); return \Illuminate\Support\Facades\Redis::ping();
}); });
@ -47,14 +47,18 @@ Route::middleware(['auth','verified',CheckIfCanTab::class])->group(function() {
Route::get('/auditions/{audition}', 'auditionSeating'); Route::get('/auditions/{audition}', 'auditionSeating');
}); });
// Doubler decision routes
Route::prefix('doubler-decision')->controller(DoublerDecisionController::class)->group(function () {
Route::post('{entry}/accept', 'accept')->name('doubler.accept');
Route::post('{entry}/decline', 'decline')->name('doubler.decline');
}); });
});
// Admin Routes // Admin Routes
Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->group(function () { Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->group(function () {
Route::view('/', 'admin.dashboard'); Route::view('/', 'admin.dashboard');
Route::post('/auditions/roomUpdate', [\App\Http\Controllers\Admin\AuditionController::class, 'roomUpdate']); // Endpoint for JS assigning auditions to rooms Route::post('/auditions/roomUpdate', [\App\Http\Controllers\Admin\AuditionController::class, 'roomUpdate']); // Endpoint for JS assigning auditions to rooms
Route::post('/scoring/assign_guide_to_audition', [\App\Http\Controllers\Admin\AuditionController::class, 'scoringGuideUpdate']); // Endpoint for JS assigning scoring guides to auditions Route::post('/scoring/assign_guide_to_audition', [\App\Http\Controllers\Admin\AuditionController::class, 'scoringGuideUpdate']); // Endpoint for JS assigning scoring guides to auditions
@ -156,8 +160,6 @@ Route::middleware(['auth','verified',CheckIfAdmin::class])->prefix('admin/')->gr
}); });
}); });
// Dashboard Related Routes // Dashboard Related Routes
Route::middleware(['auth', 'verified'])->group(function () { Route::middleware(['auth', 'verified'])->group(function () {
Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard'); Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
@ -188,7 +190,6 @@ Route::middleware(['auth','verified','can:create,App\Models\Student'])->controll
Route::delete('/students/{student}', 'destroy'); Route::delete('/students/{student}', 'destroy');
}); });
// School Related Routes // School Related Routes
Route::middleware(['auth', 'verified'])->controller(SchoolController::class)->group(function () { Route::middleware(['auth', 'verified'])->controller(SchoolController::class)->group(function () {
Route::get('/schools/create', 'create'); Route::get('/schools/create', 'create');
@ -210,5 +211,3 @@ Route::prefix('filters')->middleware(['auth','verified'])->controller(FilterCont
//Route::get('/schools/{school}/edit', [SchoolController::class, 'edit'])->middleware('auth','verified'); //Route::get('/schools/{school}/edit', [SchoolController::class, 'edit'])->middleware('auth','verified');
//Route::get('/schools/{school}', [SchoolController::class, 'show'])->middleware('auth','verified'); //Route::get('/schools/{school}', [SchoolController::class, 'show'])->middleware('auth','verified');
//Route::patch('/schools/{school}', [SchoolController::class, 'update'])->middleware('auth','verified'); //Route::patch('/schools/{school}', [SchoolController::class, 'update'])->middleware('auth','verified');