From 1b0112b73f630acd879f4e2aa9be8b4fee625edd Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 4 Jun 2024 15:48:34 -0500 Subject: [PATCH] Room assignments working for those with rooms. Need to implement for unassigned auditions --- .../Controllers/Admin/AuditionController.php | 15 +++ app/Http/Controllers/Admin/RoomController.php | 20 ++++ app/Models/Audition.php | 7 +- app/Models/Entry.php | 8 +- app/Models/Room.php | 30 ++++++ database/factories/RoomFactory.php | 23 +++++ ...24_05_31_004546_create_auditions_table.php | 2 +- .../2024_06_04_163530_create_rooms_table.php | 29 ++++++ ...48_add_room_columns_to_auditions_table.php | 31 +++++++ database/seeders/RoomSeeder.php | 17 ++++ resources/views/admin/rooms/index.blade.php | 91 +++++++++++++++++++ resources/views/admin/rooms/scratch.blade.php | 48 ++++++++++ .../views/components/card/heading.blade.php | 17 +++- .../views/components/card/list/body.blade.php | 2 +- .../views/components/layout/app.blade.php | 9 +- .../components/layout/navbar-admin.blade.php | 1 + .../components/layout/page-header.blade.php | 12 ++- routes/web.php | 12 +++ 18 files changed, 361 insertions(+), 13 deletions(-) create mode 100644 app/Http/Controllers/Admin/RoomController.php create mode 100644 app/Models/Room.php create mode 100644 database/factories/RoomFactory.php create mode 100644 database/migrations/2024_06_04_163530_create_rooms_table.php create mode 100644 database/migrations/2024_06_04_164348_add_room_columns_to_auditions_table.php create mode 100644 database/seeders/RoomSeeder.php create mode 100644 resources/views/admin/rooms/index.blade.php create mode 100644 resources/views/admin/rooms/scratch.blade.php diff --git a/app/Http/Controllers/Admin/AuditionController.php b/app/Http/Controllers/Admin/AuditionController.php index f91eee9..808fcfc 100644 --- a/app/Http/Controllers/Admin/AuditionController.php +++ b/app/Http/Controllers/Admin/AuditionController.php @@ -102,6 +102,21 @@ class AuditionController extends Controller return response()->json(['status' => 'success']); } + public function roomUpdate(Request $request) + { + $auditions = $request->all(); + + foreach ($auditions as $audition) { + Audition::where('id', $audition['id']) + ->update([ + 'room_id' => $audition['room_id'], + 'order_in_room' => $audition['room_order'] + ]); + } + + return response()->json(['status' => 'success']); + } + public function destroy(Audition $audition) { if(! Auth::user()->is_admin) abort(403); diff --git a/app/Http/Controllers/Admin/RoomController.php b/app/Http/Controllers/Admin/RoomController.php new file mode 100644 index 0000000..022ee9d --- /dev/null +++ b/app/Http/Controllers/Admin/RoomController.php @@ -0,0 +1,20 @@ +is_admin) abort(403); + $rooms = Room::with('auditions.entries')->orderBy('name')->get(); + $unassignedAuditions = Audition::with('entries')->whereNull('room_id')->orderBy('score_order')->get(); + return view('admin.rooms.index', ['rooms' => $rooms, 'unassignedAuditions' => $unassignedAuditions]); + } +} diff --git a/app/Models/Audition.php b/app/Models/Audition.php index f5af924..eac0da0 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -30,6 +30,11 @@ class Audition extends Model return $this->hasMany(Entry::class); } + public function room(): BelongsTo + { + return $this->belongsTo(Room::class); + } + public function dislpay_fee(): String { return '$' . number_format($this->entry_fee / 100, 2); @@ -39,5 +44,5 @@ class Audition extends Model -// TODO add order column to be able to sort in score order + } diff --git a/app/Models/Entry.php b/app/Models/Entry.php index fc889a7..fc6a7a5 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -24,6 +24,12 @@ class Entry extends Model public function school(): HasOneThrough { - return $this->hasOneThrough(School::class, Student::class, 'id', 'id', 'student_id', 'school_id'); + return $this->hasOneThrough( + School::class, + Student::class, + 'id', + 'id', + 'student_id', + 'school_id'); } } diff --git a/app/Models/Room.php b/app/Models/Room.php new file mode 100644 index 0000000..d5c6778 --- /dev/null +++ b/app/Models/Room.php @@ -0,0 +1,30 @@ +hasMany(Audition::class)->orderBy('order_in_room'); + } + + public function entries(): HasManyThrough + { + return $this->hasManyThrough( + Entry::class, + Audition::class, + 'room_id', // Foreign key on the auditions table + 'audition_id', //Foreign key on the Entries table + 'id', // Local key on the rooms table + 'id' // Local key on the Auditions table + ); + } +} diff --git a/database/factories/RoomFactory.php b/database/factories/RoomFactory.php new file mode 100644 index 0000000..86ea39c --- /dev/null +++ b/database/factories/RoomFactory.php @@ -0,0 +1,23 @@ + + */ +class RoomFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2024_05_31_004546_create_auditions_table.php b/database/migrations/2024_05_31_004546_create_auditions_table.php index cf6c4dc..ae8104e 100644 --- a/database/migrations/2024_05_31_004546_create_auditions_table.php +++ b/database/migrations/2024_05_31_004546_create_auditions_table.php @@ -16,7 +16,7 @@ return new class extends Migration $table->id(); $table->foreignIdFor(Event::class)->constrained()->cascadeOnUpdate()->restrictOnDelete(); $table->string('name')->unique(); - $table->integer('order')->nullable()->unique(); + $table->integer('order')->nullable(); $table->date(('entry_deadline')); $table->integer('entry_fee'); $table->integer('minimum_grade'); diff --git a/database/migrations/2024_06_04_163530_create_rooms_table.php b/database/migrations/2024_06_04_163530_create_rooms_table.php new file mode 100644 index 0000000..7515029 --- /dev/null +++ b/database/migrations/2024_06_04_163530_create_rooms_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('name')->unique(); + $table->text('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('rooms'); + } +}; diff --git a/database/migrations/2024_06_04_164348_add_room_columns_to_auditions_table.php b/database/migrations/2024_06_04_164348_add_room_columns_to_auditions_table.php new file mode 100644 index 0000000..b51b6c8 --- /dev/null +++ b/database/migrations/2024_06_04_164348_add_room_columns_to_auditions_table.php @@ -0,0 +1,31 @@ +foreignIdFor(Room::class)->nullable()->constrained()->cascadeOnUpdate()->nullOnDelete(); + $table->integer('order_in_room'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('auditions', function (Blueprint $table) { + $table->dropColumn('room_id'); + $table->dropColumn('order_in_room'); + }); + } +}; diff --git a/database/seeders/RoomSeeder.php b/database/seeders/RoomSeeder.php new file mode 100644 index 0000000..bdf439e --- /dev/null +++ b/database/seeders/RoomSeeder.php @@ -0,0 +1,17 @@ + + Rooms + New Room +
+
{{-- Unassigned Auditions --}} + + Unassigned Auditions + + + @foreach($unassignedAuditions as $audition) + + {{ $audition->entries->count() }} + + {{ $audition->name }} + + + @endforeach + + + +
+ +
{{-- Container for room cards --}} +
+ + @foreach($rooms as $room) + + + {{ $room->name }} + {{ $room->description }} + + {{ $room->entries->count() }} + + + + + @foreach($room->auditions as $audition) + + {{ $audition->entries->count() }} + {{ $audition->name }} + + @endforeach + + + + + + @endforeach() + + +
+
+
+ + + + diff --git a/resources/views/admin/rooms/scratch.blade.php b/resources/views/admin/rooms/scratch.blade.php new file mode 100644 index 0000000..ffa5a27 --- /dev/null +++ b/resources/views/admin/rooms/scratch.blade.php @@ -0,0 +1,48 @@ +
+ +
+ + diff --git a/resources/views/components/card/heading.blade.php b/resources/views/components/card/heading.blade.php index 4471909..a42fe2b 100644 --- a/resources/views/components/card/heading.blade.php +++ b/resources/views/components/card/heading.blade.php @@ -1,8 +1,15 @@ -@props(['subheading' => false]) +@props(['subheading' => false, 'right_side' => false]) -
-

merge(['class' => 'text-base font-semibold leading-7 text-gray-900']) }}>{{ $slot }}

- @if($subheading) -

attributes->merge(['class' => 'mt-.5 max-w-2xl text-sm leading-6 text-gray-500']) }}>{{ $subheading }}

+
+
+

merge(['class' => 'text-base font-semibold leading-7 text-gray-900']) }}>{{ $slot }}

+ @if($subheading) +

attributes->merge(['class' => 'mt-.5 max-w-2xl text-sm leading-6 text-gray-500']) }}>{{ $subheading }}

+ @endif +
+ @if($right_side) +
+ {{ $right_side }} +
@endif
diff --git a/resources/views/components/card/list/body.blade.php b/resources/views/components/card/list/body.blade.php index 7452a06..5f757be 100644 --- a/resources/views/components/card/list/body.blade.php +++ b/resources/views/components/card/list/body.blade.php @@ -1,6 +1,6 @@ @props(['view_all_href' => false])
-
    +
      merge(['role'=>'list','class'=>'divide-y divide-gray-100']) }}> {{ $slot }}
    @if($view_all_href) diff --git a/resources/views/components/layout/app.blade.php b/resources/views/components/layout/app.blade.php index 5e3d89f..8a28451 100644 --- a/resources/views/components/layout/app.blade.php +++ b/resources/views/components/layout/app.blade.php @@ -1,4 +1,4 @@ -@props(['page_title' => false]) +@props(['page_title' => false, 'title_bar_right' => false ]) @@ -26,7 +26,12 @@ @endif @if($page_title) - {{ $page_title }} + + {{ $page_title }} + @if($title_bar_right) + {{ $title_bar_right }} + @endif + @endif diff --git a/resources/views/components/layout/navbar-admin.blade.php b/resources/views/components/layout/navbar-admin.blade.php index 5605808..37f3a9e 100644 --- a/resources/views/components/layout/navbar-admin.blade.php +++ b/resources/views/components/layout/navbar-admin.blade.php @@ -37,6 +37,7 @@ Entries Auditions Scoring + Rooms {{-- Dashboard--}} {{-- Students--}} diff --git a/resources/views/components/layout/page-header.blade.php b/resources/views/components/layout/page-header.blade.php index 7a57466..ba51a59 100644 --- a/resources/views/components/layout/page-header.blade.php +++ b/resources/views/components/layout/page-header.blade.php @@ -1,5 +1,13 @@ +@props(['title_bar_right' => false])
    -
    -

    {{ $slot }}

    +
    +
    +

    {{ $slot }}

    +
    +
    + @if($title_bar_right) + {{ $title_bar_right }} + @endif +
    diff --git a/routes/web.php b/routes/web.php index 80bc1a8..b6bb377 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ middleware('guest'); // Admin Routes Route::middleware(['auth','verified',CheckIfAdmin::class])->prefix('admin/')->group(function() { Route::view('/','admin.dashboard'); + Route::post('/auditions/roomUpdate',[\App\Http\Controllers\Admin\AuditionController::class,'roomUpdate']); + + // Rooms + Route::prefix('rooms')->controller(\App\Http\Controllers\Admin\RoomController::class)->group(function() { + Route::get('/','index'); + Route::get('/create','create'); + Route::post('/','store'); + Route::post('/{room}/edit','edit'); + Route::patch('/{room}','update'); + Route::delete('/{room}','destroy'); + }); // Scoring Route::prefix('scoring')->controller(\App\Http\Controllers\Admin\ScoringGuideController::class)->group(function() {