Admin entries pages working with advancment options
This commit is contained in:
parent
42b7837541
commit
97c15c4fef
|
|
@ -9,82 +9,95 @@ use App\Models\School;
|
|||
use App\Models\Student;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use function compact;
|
||||
|
||||
class EntryController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
$filters = session('adminEntryFilters') ?? null;
|
||||
$minGrade = Audition::min('minimum_grade');
|
||||
$maxGrade = Audition::max('maximum_grade');
|
||||
$auditions = Audition::orderBy('score_order')->get();
|
||||
$schools = School::orderBy('name')->get();
|
||||
|
||||
|
||||
$entries = Entry::with(['student.school','audition']);
|
||||
$entries->orderBy('updated_at','DESC');
|
||||
if($filters) {
|
||||
if($filters['id']) {
|
||||
$entries = Entry::with(['student.school', 'audition']);
|
||||
$entries->orderBy('updated_at', 'DESC');
|
||||
if ($filters) {
|
||||
if ($filters['id']) {
|
||||
$entries->where('id', $filters['id']);
|
||||
}
|
||||
|
||||
if($filters['audition']) {
|
||||
if ($filters['audition']) {
|
||||
$entries->where('audition_id', $filters['audition']);
|
||||
}
|
||||
if($filters['school']) {
|
||||
$entries->whereHas('student', function($query) use ($filters) {
|
||||
if ($filters['school']) {
|
||||
$entries->whereHas('student', function ($query) use ($filters) {
|
||||
$query->where('school_id', '=', $filters['school']);
|
||||
});
|
||||
}
|
||||
if($filters['grade']) {
|
||||
$entries->whereHas('student', function($query) use ($filters) {
|
||||
if ($filters['grade']) {
|
||||
$entries->whereHas('student', function ($query) use ($filters) {
|
||||
$query->where('grade', $filters['grade']);
|
||||
});
|
||||
}
|
||||
|
||||
if($filters['first_name']) {
|
||||
$entries->whereHas('student', function($query) use ($filters) {
|
||||
$query->where('first_name', 'like', '%' . $filters['first_name'] . '%');
|
||||
if ($filters['first_name']) {
|
||||
$entries->whereHas('student', function ($query) use ($filters) {
|
||||
$query->where('first_name', 'like', '%'.$filters['first_name'].'%');
|
||||
});
|
||||
}
|
||||
|
||||
if($filters['last_name']) {
|
||||
$entries->whereHas('student', function($query) use ($filters) {
|
||||
$query->where('last_name', 'like', '%' . $filters['last_name'] . '%');
|
||||
if ($filters['last_name']) {
|
||||
$entries->whereHas('student', function ($query) use ($filters) {
|
||||
$query->where('last_name', 'like', '%'.$filters['last_name'].'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$entries = $entries->paginate(10);
|
||||
|
||||
return view('admin.entries.index', ['entries' => $entries,
|
||||
'auditions' => $auditions,
|
||||
'schools'=> $schools,
|
||||
'minGrade' => $minGrade,
|
||||
'maxGrade' => $maxGrade,
|
||||
'filters' => $filters] );
|
||||
'auditions' => $auditions,
|
||||
'schools' => $schools,
|
||||
'minGrade' => $minGrade,
|
||||
'maxGrade' => $maxGrade,
|
||||
'filters' => $filters]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
||||
$auditions = Audition::orderBy('score_order')->get();
|
||||
|
||||
return view('admin.entries.create', ['students' => $students, 'auditions' => $auditions]);
|
||||
}
|
||||
|
||||
public function store()
|
||||
public function store(Request $request)
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
request()->validate([
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
$validData = request()->validate([
|
||||
'student_id' => ['required', 'exists:students,id'],
|
||||
'audition_id' => ['required', 'exists:auditions,id'],
|
||||
]);
|
||||
|
||||
$validData['for_seating'] = $request->get('for_seating') ? 1 : 0;
|
||||
$validData['for_advancement'] = $request->get('for_advancement') ? 1 : 0;
|
||||
|
||||
Entry::create([
|
||||
'student_id' => request('student_id'),
|
||||
'audition_id' => request('audition_id'),
|
||||
'student_id' => $validData['student_id'],
|
||||
'audition_id' => $validData['audition_id'],
|
||||
'for_seating' => $validData['for_seating'],
|
||||
'for_advancement' => $validData['for_advancement'],
|
||||
]);
|
||||
|
||||
return redirect('/admin/entries');
|
||||
|
|
@ -92,29 +105,37 @@ class EntryController extends Controller
|
|||
|
||||
public function edit(Entry $entry)
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
||||
$auditions = Audition::orderBy('score_order')->get();
|
||||
$scores = $entry->scoreSheets()->get();
|
||||
// return view('admin.entries.edit', ['entry' => $entry, 'students' => $students, 'auditions' => $auditions]);
|
||||
return view('admin.entries.edit', compact('entry', 'students', 'auditions','scores'));
|
||||
|
||||
// return view('admin.entries.edit', ['entry' => $entry, 'students' => $students, 'auditions' => $auditions]);
|
||||
return view('admin.entries.edit', compact('entry', 'students', 'auditions', 'scores'));
|
||||
}
|
||||
|
||||
public function update(Entry $entry)
|
||||
public function update(Request $request, Entry $entry)
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
request()->validate([
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
$validData = request()->validate([
|
||||
'student_id' => ['required', 'exists:students,id'],
|
||||
'audition_id' => ['required', 'exists:auditions,id'],
|
||||
]);
|
||||
|
||||
$validData['for_seating'] = $request->get('for_seating') ? 1 : 0;
|
||||
$validData['for_advancement'] = $request->get('for_advancement') ? 1 : 0;
|
||||
|
||||
$entry->update([
|
||||
'student_id' => request('student_id'),
|
||||
'audition_id' => request('audition_id'),
|
||||
'student_id' => $validData['student_id'],
|
||||
'audition_id' => $validData['audition_id'],
|
||||
'for_seating' => $validData['for_seating'],
|
||||
'for_advancement' => $validData['for_advancement'],
|
||||
]);
|
||||
|
||||
return redirect('/admin/entries');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,21 @@
|
|||
<option value="{{ $audition->id }}"> {{ $audition->name }}</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
|
||||
@if(auditionSetting('advanceTo'))
|
||||
<div class="col-span-3 align-top">
|
||||
<x-form.checkbox name="for_seating"
|
||||
label="Enter for {{ auditionSetting('auditionAbbreviation') }}"
|
||||
checked />
|
||||
</div>
|
||||
<div class="col-span-3 align-top">
|
||||
<x-form.checkbox name="for_advancement"
|
||||
label="Enter for {{ auditionSetting('advanceTo') }}"
|
||||
checked />
|
||||
</div>
|
||||
@else
|
||||
<input type="hidden" name="for_seating" value="on">
|
||||
@endif
|
||||
</x-form.body-grid>
|
||||
<x-form.footer>
|
||||
<x-form.button>Create Entry</x-form.button>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
<x-card.card class="mx-auto max-w-2xl">
|
||||
<x-card.heading>Edit Entry #{{ $entry->id }}</x-card.heading>
|
||||
<x-form.form method="PATCH" action="/admin/entries/{{ $entry->id }}">
|
||||
<x-form.body-grid columns="3">
|
||||
<x-form.body-grid columns="6">
|
||||
|
||||
<x-form.select name="student_id" colspan="2">
|
||||
<x-form.select name="student_id" colspan="4">
|
||||
<x-slot:label>Student</x-slot:label>
|
||||
@foreach ($students as $student)
|
||||
|
||||
|
|
@ -14,16 +14,31 @@
|
|||
|
||||
@endforeach
|
||||
|
||||
</x-form.select><x-form.select name="audition_id" colspan="1">
|
||||
</x-form.select><x-form.select name="audition_id" colspan="2">
|
||||
<x-slot:label>Audition</x-slot:label>
|
||||
@foreach ($auditions as $audition)
|
||||
|
||||
<option value="{{ $audition->id }}" {{ ($audition->id == $entry->audition_id ? 'selected':'') }}>
|
||||
{{ $audition->name }}
|
||||
</option>
|
||||
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
|
||||
@if(auditionSetting('advanceTo'))
|
||||
<div class="col-span-6 align-top">
|
||||
<x-form.checkbox name="for_seating"
|
||||
label="Enter for {{ auditionSetting('auditionAbbreviation') }}"
|
||||
:checked="$entry->for_seating" />
|
||||
</div>
|
||||
<div class="col-span-6 align-top">
|
||||
<x-form.checkbox name="for_advancement"
|
||||
label="Enter for {{ auditionSetting('advanceTo') }}"
|
||||
:checked="$entry->for_advancement" />
|
||||
</div>
|
||||
@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>
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
<x-card.card class="mt-4">
|
||||
<x-table.table with_title_area>
|
||||
<x-slot:title class="ml-3">Entries</x-slot:title>
|
||||
<x-slot:subtitle class="ml-3">Click id to edit</x-slot:subtitle>
|
||||
<x-slot:subtitle class="ml-3">Double click row to edit</x-slot:subtitle>
|
||||
<x-slot:title_block_right class="mr-3">
|
||||
<x-form.button href="/admin/entries/create">New Entry</x-form.button>
|
||||
</x-slot:title_block_right>
|
||||
|
|
@ -62,17 +62,37 @@
|
|||
<x-table.th>Student</x-table.th>
|
||||
<x-table.th>Grade</x-table.th>
|
||||
<x-table.th>School</x-table.th>
|
||||
@if(auditionSetting('advanceTo'))
|
||||
<x-table.th>{{ auditionSetting('auditionAbbreviation') }}</x-table.th>
|
||||
<x-table.th>{{ auditionSetting('advanceTo') }}</x-table.th>
|
||||
@endif
|
||||
<x-table.th>Entry Date</x-table.th>
|
||||
</tr>
|
||||
</thead>
|
||||
<x-table.body>
|
||||
@foreach($entries as $entry)
|
||||
<tr>
|
||||
<tr @dblclick="window.location.href='{{ route('admin.entries.edit',['entry' => $entry->id]) }}'">
|
||||
<x-table.td><a href="/admin/entries/{{ $entry->id }}/edit"> {{ $entry->id }} </a></x-table.td>
|
||||
<x-table.td>{{ $entry->audition->name }}</x-table.td>
|
||||
<x-table.td>{{ $entry->student->full_name() }}</x-table.td>
|
||||
<x-table.td>{{ $entry->student->grade }}</x-table.td>
|
||||
<x-table.td>{{ $entry->student->school->name }}</x-table.td>
|
||||
@if(auditionSetting('advanceTo'))
|
||||
<x-table.td>
|
||||
@if($entry->for_seating)
|
||||
<x-icons.checkmark color="green" />
|
||||
@else
|
||||
<x-icons.circle-slash-no color="red" />
|
||||
@endif
|
||||
</x-table.td>
|
||||
<x-table.td>
|
||||
@if($entry->for_advancement)
|
||||
<x-icons.checkmark color="green" />
|
||||
@else
|
||||
<x-icons.circle-slash-no color="red" />
|
||||
@endif
|
||||
</x-table.td>
|
||||
@endif
|
||||
<x-table.td>{{ $entry->created_at->format('m/d/Y g:i A') }}</x-table.td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
</x-form.select>
|
||||
</x-form.body-grid>
|
||||
<x-form.footer>
|
||||
<x-form.button>Ecit Student</x-form.button>
|
||||
<x-form.footer class="mb-4">
|
||||
<x-form.button>Edit Student</x-form.button>
|
||||
</x-form.footer>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
|||
Route::get('/', 'index');
|
||||
Route::get('/create', 'create');
|
||||
Route::post('/', 'store');
|
||||
Route::get('/{entry}/edit', 'edit');
|
||||
Route::get('/{entry}/edit', 'edit')->name('admin.entries.edit');
|
||||
Route::patch('/{entry}', 'update');
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue