Update school admin page

This commit is contained in:
Matt Young 2024-06-27 21:55:02 -05:00
parent 1a5efd8555
commit 9da091ba51
9 changed files with 135 additions and 30 deletions

View File

@ -7,6 +7,7 @@ use App\Models\School;
use App\Models\SchoolEmailDomain;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use function abort;
use function redirect;
use function request;
@ -15,20 +16,37 @@ class SchoolController extends Controller
{
public function index()
{
if (! Auth::user()->is_admin) abort(403);
$schools = School::with(['users','students','entries'])->orderBy('name')->get();
if (! Auth::user()->is_admin) {
abort(403);
}
$schools = School::with(['users', 'students', 'entries'])->orderBy('name')->get();
return view('admin.schools.index', ['schools' => $schools]);
}
public function show(Request $request, School $school)
{
if (! Auth::user()->is_admin) {
abort(403);
}
return view('admin.schools.show', ['school' => $school]);
}
public function edit(School $school)
{
if (! Auth::user()->is_admin) abort(403);
if (! Auth::user()->is_admin) {
abort(403);
}
return view('admin.schools.edit', ['school' => $school]);
}
public function update(School $school)
{
if (! Auth::user()->is_admin) abort(403);
if (! Auth::user()->is_admin) {
abort(403);
}
request()->validate([
'name' => ['required'],
@ -46,12 +64,15 @@ class SchoolController extends Controller
'zip' => request('zip'),
]);
return redirect('/admin/schools');
return redirect()->route('admin.schools.show', ['school' => $school->id])->with('success', 'School '.$school->name.' updated');
}
public function create()
{
if (! Auth::user()->is_admin) abort(403);
if (! Auth::user()->is_admin) {
abort(403);
}
return view('admin.schools.create');
}
@ -72,21 +93,24 @@ class SchoolController extends Controller
'state' => request('state'),
'zip' => request('zip'),
]);
return redirect('/admin/schools')->with('success','School ' . $school->name . ' created');
return redirect('/admin/schools')->with('success', 'School '.$school->name.' created');
}
public function add_domain(Request $request, School $school)
{
if (! Auth::user()->is_admin) abort(403);
if (! Auth::user()->is_admin) {
abort(403);
}
request()->validate([
// validate that the combination of school and domain is unique on the school_email_domains table
'domain' => ['required']
'domain' => ['required'],
]);
SchoolEmailDomain::updateOrInsert([
'school_id' => $school->id,
'domain' => request('domain')],[]);
'domain' => request('domain')], []);
return redirect('/admin/schools/' . $school->id . '/edit')->with('success','Domain Added');
return redirect('/admin/schools/'.$school->id.'/edit')->with('success', 'Domain Added');
}
@ -98,6 +122,4 @@ class SchoolController extends Controller
// return a redirect to the previous URL
return redirect()->back();
}
}

View File

@ -2,8 +2,6 @@
namespace App\Observers;
use App\Events\AuditionChange;
use App\Events\EntryChange;
use App\Models\School;
class SchoolObserver
@ -21,8 +19,7 @@ class SchoolObserver
*/
public function updated(School $school): void
{
AuditionChange::dispatch();
EntryChange::dispatch();
}
/**
@ -30,7 +27,6 @@ class SchoolObserver
*/
public function deleted(School $school): void
{
AuditionChange::dispatch();
}
/**

View File

@ -5,6 +5,3 @@
<x-school.school-domain-form :school="$school" />
</x-layout.app>
{{--TODO Show directors on school page--}}
{{--TODO make this a component in the main schoosl page and have a prop to set the form action since that's the only difference --}}

View File

@ -21,7 +21,7 @@
<x-table.body>
@foreach($schools as $school)
<tr>
<x-table.td><a href="/admin/schools/{{ $school->id }}/edit">{{ $school->name }}</a></x-table.td>
<x-table.td><a href="/admin/schools/{{ $school->id }}">{{ $school->name }}</a></x-table.td>
<x-table.td>{{ $school->users->count() }}</x-table.td>
<x-table.td>{{ $school->students->count() }}</x-table.td>
<x-table.td>{{ $school->entries->count() }}</x-table.td>

View File

@ -0,0 +1,25 @@
<x-card.card class="mx-auto max-w-sm mt-8">
<x-card.heading>Associated Domains</x-card.heading>
<x-card.list.body>
@foreach($school->emailDomains as $domain)
<x-card.list.row class="!py-1.5 align-middle">
<form method="POST" action="/admin/schools/domain/{{ $domain->id }}" id="deleteDomain{{$domain->id}}">
@csrf
@method('DELETE')
<button type="submit">
<svg class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24">
<path fill-rule="evenodd" d="M2 12C2 6.477 6.477 2 12 2s10 4.477 10 10-4.477 10-10 10S2 17.523 2 12Zm7.707-3.707a1 1 0 0 0-1.414 1.414L10.586 12l-2.293 2.293a1 1 0 1 0 1.414 1.414L12 13.414l2.293 2.293a1 1 0 0 0 1.414-1.414L13.414 12l2.293-2.293a1 1 0 0 0-1.414-1.414L12 10.586 9.707 8.293Z" clip-rule="evenodd"/>
</svg>
</button><span class="px-3">{{ $domain->domain }}</span>
</form>
</x-card.list.row>
@endforeach
<x-card.list.row class="!py-1.5">
<form method="POST" action="/admin/schools/{{ $school->id }}/add_domain" class="grid sm:grid-cols-2 gap-4">
@csrf
<x-form.field name="domain" label_text="Add Domain" /><x-form.button class="sm:mt-6">Add Domain</x-form.button>
</form>
</x-card.list.row>
</x-card.list.body>
</x-card.card>

View File

@ -0,0 +1,17 @@
<x-modal-body>
<x-card.card class="mx-auto max-w-xl">
<x-card.heading>Edit School Address</x-card.heading>
<x-form.form method="PATCH" action="{{ route('admin.schools.update',['school'=>$school->id]) }}">
<x-form.body-grid>
<x-form.field name="name" label_text="Name" colspan="6" value="{{ $school->name }}" />
<x-form.field name="address" label_text="Address" colspan="6" value="{{ $school->address }}" />
<x-form.field name="city" label_text="City" colspan="3" value="{{ $school->city }}" />
<x-form.field name="state" label_text="State" colspan="2" value="{{ $school->state }}" />
<x-form.field name="zip" label_text="Zip" colspan="1" value="{{ $school->zip }}" />
</x-form.body-grid>
<x-form.footer>
<x-form.button class="mb-5">Update School</x-form.button>
</x-form.footer>
</x-form.form>
</x-card.card>
</x-modal-body>

View File

@ -0,0 +1,45 @@
<x-layout.app>
<x-slot:page_title>School: {{ $school->name }}</x-slot:page_title>
<div class="grid md:grid-cols-4 gap-3">
<div x-data="{ showModal: false }">
<x-card.card >
<x-card.heading >
<x-slot:right_side class="text-xs" >
<span @click="showModal = ! showModal">[ edit ]</span>
</x-slot:right_side>
Address
</x-card.heading>
<div class="ml-6 mb-3">
<p>{{ $school->name }}</p>
<p>{{ $school->address }}</p>
<p>{{ $school->city }}, {{ $school->state }} {{ $school->zip }}</p>
</div>
</x-card.card>
@include('admin.schools.show-domain-form')
@include('admin.schools.show-edit-address')
</div>
<div class="col-span-3">
<x-card.card class="px-5">
<x-card.heading>Directors</x-card.heading>
</x-card.card>
<div class="grid md:grid-cols-3 gap-3 mt-3">
@foreach($school->directors as $director)
<x-card.card>
<x-card.heading>{{ $director->full_name() }}</x-card.heading>
<div class="ml-6">
<p class="py-2">{{ $director->cell_phone }}</p>
<p class="py-2">
<a href="mailto:{{ $director->email }}">
{{ $director->email }}
</a>
</p>
<p class="pt-2">Judging Preference:</p>
<p class="pb-3">{{ $director->judging_preference }}</p>
</div>
</x-card.card>
@endforeach
</div>
</div>
</div>
</x-layout.app>

View File

@ -16,7 +16,9 @@
<x-layout.app>
<x-slot:page_title>Test Page</x-slot:page_title>
@php
dump(Auth::user()->rooms->contains(1));
$schools = School::all();
}
@endphp

View File

@ -93,13 +93,14 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
// Admin School Routes
Route::prefix('schools')->controller(\App\Http\Controllers\Admin\SchoolController::class)->group(function () {
Route::post('/{school}/add_domain', 'add_domain');
Route::get('/', 'index');
Route::get('/create', 'create');
Route::get('/{school}/edit', 'edit');
Route::patch('/{school}', 'update');
Route::post('/', 'store');
Route::delete('/domain/{domain}', 'destroy_domain');
Route::post('/{school}/add_domain', 'add_domain')->name('admin.schools.add_domain');
Route::get('/', 'index')->name('admin.schools.index');
Route::get('/{school}', 'show')->name('admin.schools.show');
Route::get('/create', 'create')->name('admin.schools.create');
Route::get('/{school}/edit', 'edit')->name('admin.schools.edit');
Route::patch('/{school}', 'update')->name('admin.schools.update');
Route::post('/', 'store')->name('admin.schools.store');
Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain');
});