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;
|
||||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Events\RoomJudgeChange;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Audition;
|
||||
|
|
@ -10,49 +9,101 @@ use App\Models\Room;
|
|||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use function redirect;
|
||||
|
||||
class RoomController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if(! Auth::user()->is_admin) abort(403);
|
||||
#$unassignedAuditions = Audition::with('entries')->where('room_id','=','0')->orderBy('score_order')->get();
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
//$unassignedAuditions = Audition::with('entries')->where('room_id','=','0')->orderBy('score_order')->get();
|
||||
$rooms = Room::with('auditions.entries')->orderBy('name')->get();
|
||||
|
||||
return view('admin.rooms.index', ['rooms' => $rooms]);
|
||||
}
|
||||
|
||||
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();
|
||||
$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();
|
||||
|
||||
return view('admin.rooms.judge_assignments', compact('usersWithoutRooms','usersWithRooms','rooms'));
|
||||
return view('admin.rooms.judge_assignments', compact('usersWithoutRooms', 'usersWithRooms', 'rooms'));
|
||||
}
|
||||
|
||||
public function updateJudgeAssignment(Request $request, Room $room)
|
||||
{
|
||||
if (! Auth::user()->is_admin) {
|
||||
abort(403);
|
||||
}
|
||||
$validData = $request->validate([
|
||||
'judge' => 'exists:users,id'
|
||||
'judge' => 'exists:users,id',
|
||||
]);
|
||||
$judge = User::find($validData['judge']);
|
||||
|
||||
if($request->isMethod('post')) {
|
||||
if ($request->isMethod('post')) {
|
||||
// attach judge on post
|
||||
$room->addJudge($judge->id);
|
||||
$message = "Assigned " . $judge->full_name() . " to " . $room->name;
|
||||
$message = 'Assigned '.$judge->full_name().' to '.$room->name;
|
||||
} elseif ($request->isMethod('delete')) {
|
||||
// detach judge on delete
|
||||
$room->removeJudge($judge->id);
|
||||
$message = "Removed " . $judge->full_name() . " from " . $room->name;
|
||||
$message = 'Removed '.$judge->full_name().' from '.$room->name;
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
// TODO need to be able to add new rooms. Dispatch RoomJudgeChange when we do.
|
||||
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.
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
||||
@foreach($rooms as $room)
|
||||
{{-- Room 0 should be at the end for unassigned auditions--}}
|
||||
@if($room->id == '0')
|
||||
|
||||
@push('noRoom')
|
||||
@endif
|
||||
<x-card.card>
|
||||
|
|
@ -16,7 +16,18 @@
|
|||
{{ $room->name }}
|
||||
<x-slot:subheading>{{ $room->description }}</x-slot:subheading>
|
||||
<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>
|
||||
@endif
|
||||
</x-slot:right_side>
|
||||
</x-card.heading>
|
||||
<x-card.list.body id="room-{{ $room->id }}" class="audition-list">
|
||||
|
|
@ -28,7 +39,6 @@
|
|||
</x-card.list.row>
|
||||
@endforeach
|
||||
|
||||
|
||||
</x-card.list.body>
|
||||
|
||||
</x-card.card>
|
||||
|
|
|
|||
Loading…
Reference in New Issue