Complete add and delete functions on admin rooms page
This commit is contained in:
parent
0f88ae9573
commit
0ac9f67166
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Events\AuditionChange;
|
|
||||||
use App\Events\RoomJudgeChange;
|
use App\Events\RoomJudgeChange;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
|
|
@ -10,20 +9,27 @@ use App\Models\Room;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
use function redirect;
|
use function redirect;
|
||||||
|
|
||||||
class RoomController extends Controller
|
class RoomController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
if(! Auth::user()->is_admin) abort(403);
|
if (! Auth::user()->is_admin) {
|
||||||
#$unassignedAuditions = Audition::with('entries')->where('room_id','=','0')->orderBy('score_order')->get();
|
abort(403);
|
||||||
|
}
|
||||||
|
//$unassignedAuditions = Audition::with('entries')->where('room_id','=','0')->orderBy('score_order')->get();
|
||||||
$rooms = Room::with('auditions.entries')->orderBy('name')->get();
|
$rooms = Room::with('auditions.entries')->orderBy('name')->get();
|
||||||
|
|
||||||
return view('admin.rooms.index', ['rooms' => $rooms]);
|
return view('admin.rooms.index', ['rooms' => $rooms]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function judgingAssignment() // Show form for assigning judges
|
public function judgingAssignment() // Show form for assigning judges
|
||||||
{
|
{
|
||||||
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
$usersWithoutRooms = User::doesntHave('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
$usersWithoutRooms = User::doesntHave('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
||||||
$usersWithRooms = User::has('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
$usersWithRooms = User::has('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
||||||
$rooms = Room::with(['judges.school', 'auditions'])->get();
|
$rooms = Room::with(['judges.school', 'auditions'])->get();
|
||||||
|
|
@ -33,25 +39,70 @@ class RoomController extends Controller
|
||||||
|
|
||||||
public function updateJudgeAssignment(Request $request, Room $room)
|
public function updateJudgeAssignment(Request $request, Room $room)
|
||||||
{
|
{
|
||||||
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
$validData = $request->validate([
|
$validData = $request->validate([
|
||||||
'judge' => 'exists:users,id'
|
'judge' => 'exists:users,id',
|
||||||
]);
|
]);
|
||||||
$judge = User::find($validData['judge']);
|
$judge = User::find($validData['judge']);
|
||||||
|
|
||||||
if ($request->isMethod('post')) {
|
if ($request->isMethod('post')) {
|
||||||
// attach judge on post
|
// attach judge on post
|
||||||
$room->addJudge($judge->id);
|
$room->addJudge($judge->id);
|
||||||
$message = "Assigned " . $judge->full_name() . " to " . $room->name;
|
$message = 'Assigned '.$judge->full_name().' to '.$room->name;
|
||||||
} elseif ($request->isMethod('delete')) {
|
} elseif ($request->isMethod('delete')) {
|
||||||
// detach judge on delete
|
// detach judge on delete
|
||||||
$room->removeJudge($judge->id);
|
$room->removeJudge($judge->id);
|
||||||
$message = "Removed " . $judge->full_name() . " from " . $room->name;
|
$message = 'Removed '.$judge->full_name().' from '.$room->name;
|
||||||
} else {
|
} else {
|
||||||
return redirect('/admin/rooms/judging_assignments')->with('error', 'Invalid request method.');
|
return redirect('/admin/rooms/judging_assignments')->with('error', 'Invalid request method.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect('/admin/rooms/judging_assignments')->with('success', $message);
|
return redirect('/admin/rooms/judging_assignments')->with('success', $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.rooms.create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
$validData = $request->validate([
|
||||||
|
'name' => 'required',
|
||||||
|
'description' => 'nullable',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$room = new Room();
|
||||||
|
$room->name = $validData['name'];
|
||||||
|
$room->description = $validData['description'];
|
||||||
|
$room->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin.rooms.index')->with('success', 'Room created.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Request $request, Room $room)
|
||||||
|
{
|
||||||
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($room->auditions()->count() > 0) {
|
||||||
|
return redirect()->route('admin.rooms.index')->with('error', 'Cannot delete room with auditions. First move the auditions to unassigned or another room');
|
||||||
|
}
|
||||||
|
|
||||||
|
$room->delete();
|
||||||
|
|
||||||
|
return redirect()->route('admin.rooms.index')->with('success', 'Room deleted.');
|
||||||
|
}
|
||||||
|
|
||||||
// TODO need to be able to add new rooms. Dispatch RoomJudgeChange when we do.
|
// TODO need to be able to add new rooms. Dispatch RoomJudgeChange when we do.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<x-layout.app>
|
||||||
|
<x-slot:page_title>Create Room</x-slot:page_title>
|
||||||
|
<x-card.card class="mx-auto max-w-sm">
|
||||||
|
<x-card.heading>Create Room</x-card.heading>
|
||||||
|
<x-form.form method="POST" action="{{ route('admin.rooms.store') }}">
|
||||||
|
<x-form.field name="name" label_text="Room Name" />
|
||||||
|
<x-form.field name="description" label_text="Room Description" />
|
||||||
|
<x-form.footer class="mb-4">
|
||||||
|
<x-form.button>Save Room</x-form.button>
|
||||||
|
</x-form.footer>
|
||||||
|
</x-form.form>
|
||||||
|
</x-card.card>
|
||||||
|
</x-layout.app>
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
<div class="grid md:grid-cols-3 gap-3">
|
<div class="grid md:grid-cols-3 gap-3">
|
||||||
|
|
||||||
@foreach($rooms as $room)
|
@foreach($rooms as $room)
|
||||||
|
{{-- Room 0 should be at the end for unassigned auditions--}}
|
||||||
@if($room->id == '0')
|
@if($room->id == '0')
|
||||||
|
|
||||||
@push('noRoom')
|
@push('noRoom')
|
||||||
@endif
|
@endif
|
||||||
<x-card.card>
|
<x-card.card>
|
||||||
|
|
@ -16,7 +16,18 @@
|
||||||
{{ $room->name }}
|
{{ $room->name }}
|
||||||
<x-slot:subheading>{{ $room->description }}</x-slot:subheading>
|
<x-slot:subheading>{{ $room->description }}</x-slot:subheading>
|
||||||
<x-slot:right_side>
|
<x-slot:right_side>
|
||||||
|
@if($room->entries->count() === 0 and $room->id != '0')
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<x-form.form method="DELETE"
|
||||||
|
action="{{ route('admin.rooms.destroy', ['room'=>$room->id]) }}"
|
||||||
|
class="!px-0 -mr-6 -mt-2"
|
||||||
|
id="deleteResource">
|
||||||
|
<x-form.red-trash-button/>
|
||||||
|
</x-form.form>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
<x-badge_pill>{{ $room->entries->count() }}</x-badge_pill>
|
<x-badge_pill>{{ $room->entries->count() }}</x-badge_pill>
|
||||||
|
@endif
|
||||||
</x-slot:right_side>
|
</x-slot:right_side>
|
||||||
</x-card.heading>
|
</x-card.heading>
|
||||||
<x-card.list.body id="room-{{ $room->id }}" class="audition-list">
|
<x-card.list.body id="room-{{ $room->id }}" class="audition-list">
|
||||||
|
|
@ -28,7 +39,6 @@
|
||||||
</x-card.list.row>
|
</x-card.list.row>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
|
|
||||||
</x-card.list.body>
|
</x-card.list.body>
|
||||||
|
|
||||||
</x-card.card>
|
</x-card.card>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue