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:
parent
06d722b706
commit
feaf696e72
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use App\Models\School;
|
||||
use App\Models\Seat;
|
||||
use App\Models\Student;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
|
@ -138,4 +139,18 @@ class EntryController extends Controller
|
|||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
|
||||
class Entry extends Model
|
||||
|
|
@ -94,4 +95,9 @@ class Entry extends Model
|
|||
|
||||
return $this->attributes['score_sheets_count'];
|
||||
}
|
||||
|
||||
public function seat(): HasOne
|
||||
{
|
||||
return $this->hasOne(Seat::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
|
|
@ -12,7 +11,7 @@ class ScoreSheet extends Model
|
|||
protected $fillable = [
|
||||
'user_id',
|
||||
'entry_id',
|
||||
'subscores'
|
||||
'subscores',
|
||||
];
|
||||
|
||||
protected $casts = ['subscores' => 'json'];
|
||||
|
|
@ -44,11 +43,11 @@ class ScoreSheet extends Model
|
|||
return $this->subscores[$id]['score'] ?? false;
|
||||
}
|
||||
|
||||
public function isValid() {
|
||||
public function isValid()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,50 @@
|
|||
@php use App\Models\Seat; @endphp
|
||||
<x-layout.app>
|
||||
<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.body-grid columns="6">
|
||||
|
||||
<x-form.select name="student_id" colspan="4">
|
||||
@if(! Seat::where('entry_id', $entry->id)->exists())
|
||||
<x-form.select name="student_id" colspan="4" disabled>
|
||||
<x-slot:label>Student</x-slot:label>
|
||||
@foreach ($students as $student)
|
||||
@php($student = $students->find($entry->student_id))
|
||||
|
||||
<option value="{{ $student->id }}" {{ ($student->id == $entry->student_id ? 'selected':'') }}>
|
||||
{{ $student->full_name(true) }} - {{ $student->school->name }} (Grade {{ $student->grade }})
|
||||
</option>
|
||||
</x-form.select>
|
||||
@else
|
||||
<p class="col-span-3 mt-4 ">{{ $entry->student->full_name() }} - {{ $entry->student->school->name }}</p>
|
||||
@endif
|
||||
|
||||
@endforeach
|
||||
|
||||
</x-form.select><x-form.select name="audition_id" colspan="2">
|
||||
@if(! Seat::where('entry_id', $entry->id)->exists())
|
||||
<x-form.select name="audition_id" colspan="2">
|
||||
<x-slot:label>Audition</x-slot:label>
|
||||
@foreach ($auditions as $audition)
|
||||
|
||||
@continue($entry->student->grade < $audition->minimum_grade || $entry->student->grade > $audition->maximum_grade)
|
||||
<option value="{{ $audition->id }}" {{ ($audition->id == $entry->audition_id ? 'selected':'') }}>
|
||||
{{ $audition->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
@else
|
||||
<p class="col-span-3 mt-4 ">{{ $entry->audition->name }}</p>
|
||||
@endif
|
||||
|
||||
@if(auditionSetting('advanceTo'))
|
||||
<div class="col-span-6 align-top">
|
||||
|
|
@ -38,7 +60,6 @@
|
|||
@else
|
||||
<input type="hidden" name="for_seating" value="on">
|
||||
@endif
|
||||
{{-- TODO need to be able to delete an entry--}}
|
||||
</x-form.body-grid>
|
||||
<x-form.footer class="!py-5">
|
||||
<x-form.button>Edit Entry</x-form.button>
|
||||
|
|
@ -46,31 +67,31 @@
|
|||
</x-form.form>
|
||||
</x-card.card>
|
||||
|
||||
|
||||
<x-card.card class="mx-auto max-w-2xl mt-6">
|
||||
<x-card.heading>Scores</x-card.heading>
|
||||
<x-card.list.body>
|
||||
<div class="grid sm:grid-cols-3 space-3 m-3">
|
||||
@foreach($scores as $score)
|
||||
@php($score->isValid())
|
||||
<x-card.list.row right_link_button_type="button" >
|
||||
<div>{{ $score->judge->full_name() }}</div>
|
||||
<div class="border p-3">
|
||||
<p class="font-semibold border-b">{{ $score->judge->full_name() }}</p>
|
||||
@foreach($score->subscores as $subscore)
|
||||
{{-- TODO make this look better--}}
|
||||
<div>
|
||||
<p>{{$subscore['subscore_name']}}</p>
|
||||
<p>{{$subscore['score'] }}</p>
|
||||
</div>
|
||||
<p class="grid grid-cols-2 border-b">
|
||||
<span>{{$subscore['subscore_name'] }}</span>
|
||||
<span class="text-right">{{$subscore['score']}}</span>
|
||||
</p>
|
||||
@endforeach
|
||||
@if(! $score->isValid())
|
||||
<form method="POST" action="{{ route('scores.destroy',['score'=>$score->id]) }}">
|
||||
@csrf
|
||||
@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
|
||||
</x-card.list.row>
|
||||
{{-- // TODO make the invalid prettier--}}
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
|
||||
</x-card.list.body>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
||||
{{--TODO apply javascript to only show appropriate auditions for the students grade--}}
|
||||
|
|
|
|||
|
|
@ -74,11 +74,12 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
|||
|
||||
// Admin Entries Routes
|
||||
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::post('/', 'store');
|
||||
Route::get('/{entry}/edit', 'edit')->name('admin.entries.edit');
|
||||
Route::patch('/{entry}', 'update');
|
||||
Route::delete('/{entry}', 'destroy')->name('admin.entries.destroy');
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue