Cleanup on admin entries page. Do not allow a change to the student. Only show auditions for the students grade

This commit is contained in:
Matt Young 2024-06-27 23:40:15 -05:00
parent 06d722b706
commit feaf696e72
5 changed files with 91 additions and 49 deletions

View File

@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Models\Audition; use App\Models\Audition;
use App\Models\Entry; use App\Models\Entry;
use App\Models\School; use App\Models\School;
use App\Models\Seat;
use App\Models\Student; use App\Models\Student;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -138,4 +139,18 @@ class EntryController extends Controller
return redirect('/admin/entries'); return redirect('/admin/entries');
} }
public function destroy(Request $request, Entry $entry)
{
if (! Auth::user()->is_admin) {
abort(403);
}
if (Seat::where('entry_id', $entry->id)->exists()) {
return redirect()->route('admin.entries.index')->with('error', 'Cannot delete an entry that is seated');
}
$entry->delete();
return redirect()->route('admin.entries.index')->with('success', 'Entry Deleted');
}
} }

View File

@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Illuminate\Database\Eloquent\Relations\HasOneThrough;
class Entry extends Model class Entry extends Model
@ -94,4 +95,9 @@ class Entry extends Model
return $this->attributes['score_sheets_count']; return $this->attributes['score_sheets_count'];
} }
public function seat(): HasOne
{
return $this->hasOne(Seat::class);
}
} }

View File

@ -2,7 +2,6 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Illuminate\Database\Eloquent\Relations\HasOneThrough;
@ -12,7 +11,7 @@ class ScoreSheet extends Model
protected $fillable = [ protected $fillable = [
'user_id', 'user_id',
'entry_id', 'entry_id',
'subscores' 'subscores',
]; ];
protected $casts = ['subscores' => 'json']; protected $casts = ['subscores' => 'json'];
@ -44,11 +43,11 @@ class ScoreSheet extends Model
return $this->subscores[$id]['score'] ?? false; return $this->subscores[$id]['score'] ?? false;
} }
public function isValid() { public function isValid()
{
// TODO move to either TabulationService or a specific service for scoreValidation // TODO move to either TabulationService or a specific service for scoreValidation
$judges = $this->audition->judges(); $judges = $this->audition->judges;
return $judges->contains('id', $this->judge->id); return $judges->contains('id', $this->judge->id);
} }
} }

View File

@ -1,28 +1,50 @@
@php use App\Models\Seat; @endphp
<x-layout.app> <x-layout.app>
<x-card.card class="mx-auto max-w-2xl"> <x-card.card class="mx-auto max-w-2xl">
<x-card.heading>Edit Entry #{{ $entry->id }}</x-card.heading> <x-card.heading>
Edit Entry #{{ $entry->id }}
<x-slot:right_side>
@if(! Seat::where('entry_id', $entry->id)->exists())
<form method="POST" action="{{ route('admin.entries.destroy',['entry' => $entry->id]) }}">
@csrf
@method('DELETE')
<x-form.red-trash-button type="submit" />
</form>
@else
Seated: {{ $entry->seat->ensemble->name }} #{{ $entry->seat->seat }}
@endif
</x-slot:right_side>
</x-card.heading>
<x-form.form method="PATCH" action="/admin/entries/{{ $entry->id }}"> <x-form.form method="PATCH" action="/admin/entries/{{ $entry->id }}">
<x-form.body-grid columns="6"> <x-form.body-grid columns="6">
@if(! Seat::where('entry_id', $entry->id)->exists())
<x-form.select name="student_id" colspan="4" disabled>
<x-slot:label>Student</x-slot:label>
@php($student = $students->find($entry->student_id))
<x-form.select name="student_id" colspan="4"> <option value="{{ $student->id }}" {{ ($student->id == $entry->student_id ? 'selected':'') }}>
<x-slot:label>Student</x-slot:label> {{ $student->full_name(true) }} - {{ $student->school->name }} (Grade {{ $student->grade }})
@foreach ($students as $student) </option>
</x-form.select>
@else
<p class="col-span-3 mt-4 ">{{ $entry->student->full_name() }} - {{ $entry->student->school->name }}</p>
@endif
<option value="{{ $student->id }}" {{ ($student->id == $entry->student_id ? 'selected':'') }}> @if(! Seat::where('entry_id', $entry->id)->exists())
{{ $student->full_name(true) }} - {{ $student->school->name }} (Grade {{ $student->grade }}) <x-form.select name="audition_id" colspan="2">
</option> <x-slot:label>Audition</x-slot:label>
@foreach ($auditions as $audition)
@endforeach @continue($entry->student->grade < $audition->minimum_grade || $entry->student->grade > $audition->maximum_grade)
<option value="{{ $audition->id }}" {{ ($audition->id == $entry->audition_id ? 'selected':'') }}>
</x-form.select><x-form.select name="audition_id" colspan="2"> {{ $audition->name }}
<x-slot:label>Audition</x-slot:label> </option>
@foreach ($auditions as $audition) @endforeach
</x-form.select>
<option value="{{ $audition->id }}" {{ ($audition->id == $entry->audition_id ? 'selected':'') }}> @else
{{ $audition->name }} <p class="col-span-3 mt-4 ">{{ $entry->audition->name }}</p>
</option> @endif
@endforeach
</x-form.select>
@if(auditionSetting('advanceTo')) @if(auditionSetting('advanceTo'))
<div class="col-span-6 align-top"> <div class="col-span-6 align-top">
@ -38,7 +60,6 @@
@else @else
<input type="hidden" name="for_seating" value="on"> <input type="hidden" name="for_seating" value="on">
@endif @endif
{{-- TODO need to be able to delete an entry--}}
</x-form.body-grid> </x-form.body-grid>
<x-form.footer class="!py-5"> <x-form.footer class="!py-5">
<x-form.button>Edit Entry</x-form.button> <x-form.button>Edit Entry</x-form.button>
@ -46,31 +67,31 @@
</x-form.form> </x-form.form>
</x-card.card> </x-card.card>
<x-card.card class="mx-auto max-w-2xl mt-6"> <x-card.card class="mx-auto max-w-2xl mt-6">
<x-card.heading>Scores</x-card.heading> <x-card.heading>Scores</x-card.heading>
<x-card.list.body> <x-card.list.body>
@foreach($scores as $score) <div class="grid sm:grid-cols-3 space-3 m-3">
@php($score->isValid()) @foreach($scores as $score)
<x-card.list.row right_link_button_type="button" > @php($score->isValid())
<div>{{ $score->judge->full_name() }}</div> <div class="border p-3">
@foreach($score->subscores as $subscore) <p class="font-semibold border-b">{{ $score->judge->full_name() }}</p>
{{-- TODO make this look better--}} @foreach($score->subscores as $subscore)
<div> <p class="grid grid-cols-2 border-b">
<p>{{$subscore['subscore_name']}}</p> <span>{{$subscore['subscore_name'] }}</span>
<p>{{$subscore['score'] }}</p> <span class="text-right">{{$subscore['score']}}</span>
</div> </p>
@endforeach @endforeach
@if(! $score->isValid()) @if(! $score->isValid())
<form method="POST" action="{{ route('scores.destroy',['score'=>$score->id]) }}"> <form method="POST" action="{{ route('scores.destroy',['score'=>$score->id]) }}">
@csrf @csrf
@method('DELETE') @method('DELETE')
<x-slot:right_link_button class="bg-red-500 text-white">INVALID SCORE - DELETE</x-slot:right_link_button> <button type="submit" class="text-red-500 font-semibold pt-5">Invalid Score - Delete</button>
@endif @endif
</x-card.list.row> </div>
{{-- // TODO make the invalid prettier--}} @endforeach
@endforeach </div>
</x-card.list.body> </x-card.list.body>
</x-card.card> </x-card.card>
</x-layout.app> </x-layout.app>
{{--TODO apply javascript to only show appropriate auditions for the students grade--}}

View File

@ -74,11 +74,12 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
// Admin Entries Routes // Admin Entries Routes
Route::prefix('entries')->controller(\App\Http\Controllers\Admin\EntryController::class)->group(function () { Route::prefix('entries')->controller(\App\Http\Controllers\Admin\EntryController::class)->group(function () {
Route::get('/', 'index'); Route::get('/', 'index')->name('admin.entries.index');
Route::get('/create', 'create'); Route::get('/create', 'create');
Route::post('/', 'store'); Route::post('/', 'store');
Route::get('/{entry}/edit', 'edit')->name('admin.entries.edit'); Route::get('/{entry}/edit', 'edit')->name('admin.entries.edit');
Route::patch('/{entry}', 'update'); Route::patch('/{entry}', 'update');
Route::delete('/{entry}', 'destroy')->name('admin.entries.destroy');
}); });