From a4882d3545026894664959e8287d0a3f7f7bf529 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Thu, 1 Jan 2026 17:40:47 -0600 Subject: [PATCH] Passing data to the form is working. --- .../Admin/AuditionEtudeGridController.php | 2 +- app/Models/Ensemble.php | 10 ++- app/Services/AuditionEtudeService.php | 31 ++++++- app/View/Components/Layout/Admin.php | 6 +- package-lock.json | 8 +- package.json | 2 +- .../views/admin/audition_etude/grid.blade.php | 83 ++++++++++++++++++- .../views/components/layout/admin.blade.php | 2 +- 8 files changed, 133 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Admin/AuditionEtudeGridController.php b/app/Http/Controllers/Admin/AuditionEtudeGridController.php index fbb1027..51777ea 100644 --- a/app/Http/Controllers/Admin/AuditionEtudeGridController.php +++ b/app/Http/Controllers/Admin/AuditionEtudeGridController.php @@ -10,7 +10,7 @@ class AuditionEtudeGridController extends Controller { public function index() { - $ensembles = Ensemble::all(); + $ensembles = Ensemble::with('etudes')->get(); $instruments = Instrument::orderBy('score_order')->get(); return view('admin.audition_etude.grid', compact('ensembles', 'instruments')); diff --git a/app/Models/Ensemble.php b/app/Models/Ensemble.php index 42665d0..b47be40 100644 --- a/app/Models/Ensemble.php +++ b/app/Models/Ensemble.php @@ -8,11 +8,19 @@ use Illuminate\Database\Eloquent\Relations\HasMany; class Ensemble extends Model { protected $fillable = [ - 'name', 'set_count', + 'name', 'set_count', 'abbreviation', ]; public function etudes(): HasMany { return $this->hasMany(AuditionEtude::class, 'ensemble_id'); } + + public function getEtude(Instrument $instrument, int $set): ?AuditionEtude + { + return $this->etudes + ->where('instrument_id', $instrument->id) + ->where('set', $set) + ->first(); + } } diff --git a/app/Services/AuditionEtudeService.php b/app/Services/AuditionEtudeService.php index d39959d..0ffe64c 100644 --- a/app/Services/AuditionEtudeService.php +++ b/app/Services/AuditionEtudeService.php @@ -2,15 +2,19 @@ namespace App\Services; +use App\Models\AuditionEtude; use App\Models\Ensemble; +use App\Models\Instrument; use Carbon\Carbon; -readonly class AuditionEtudeService +class AuditionEtudeService { protected int $startYear; protected int $changeoverMonth; + protected array $etudeCache = []; + public function __construct() { $this->startYear = config('siteData.etude_start_year'); @@ -77,4 +81,29 @@ readonly class AuditionEtudeService return ($yearDiff % $setCount) + 1; } + + /** + * Get the audition etude for a specific ensemble, instrument, and set combination. + * + * Results are cached in-memory for the duration of the request to avoid + * duplicate queries when called multiple times with the same parameters. + * + * @param Ensemble $ensemble The ensemble to get the etude for + * @param Instrument $instrument The instrument to get the etude for + * @param int $set The set number + * @return AuditionEtude|null The matching etude, or null if not found + */ + public function getEtude(Ensemble $ensemble, Instrument $instrument, int $set): ?AuditionEtude + { + $cacheKey = "{$ensemble->id}_{$instrument->id}_{$set}"; + + if (! isset($this->etudeCache[$cacheKey])) { + $this->etudeCache[$cacheKey] = AuditionEtude::where('instrument_id', $instrument->id) + ->where('ensemble_id', $ensemble->id) + ->where('set', $set) + ->first(); + } + + return $this->etudeCache[$cacheKey]; + } } diff --git a/app/View/Components/Layout/Admin.php b/app/View/Components/Layout/Admin.php index 0623231..8327d18 100644 --- a/app/View/Components/Layout/Admin.php +++ b/app/View/Components/Layout/Admin.php @@ -36,10 +36,14 @@ class Admin extends Component 'name' => 'Audition Etudes', 'link' => route('admin.etudes.index'), ], + [ + 'name' => 'Audition Etude Grid', + 'link' => route('admin.etude-grid'), + ], [ 'name' => 'News Stories', 'link' => route('admin.news.index'), - ] + ], ]; } diff --git a/package-lock.json b/package-lock.json index ac71814..700da6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "packages": { "": { "dependencies": { - "@tailwindplus/elements": "^1.0.20", + "@tailwindplus/elements": "^1.0.21", "alpinejs": "^3.15.3" }, "devDependencies": { @@ -1090,9 +1090,9 @@ } }, "node_modules/@tailwindplus/elements": { - "version": "1.0.20", - "resolved": "https://registry.npmjs.org/@tailwindplus/elements/-/elements-1.0.20.tgz", - "integrity": "sha512-ka/4LlqzXmKjcoyRsKu8eBotl3KaDrMhdTr2+YDpjLj5Sy21FTIgg0gniDBPYTVZMFj6L82Cw4aNh2BJkjuRoQ==", + "version": "1.0.21", + "resolved": "https://registry.npmjs.org/@tailwindplus/elements/-/elements-1.0.21.tgz", + "integrity": "sha512-CShPoilDolGpzT9J4MVTCexOijwURW+MHGNMoS5ijiD2FVNk1XHFvEuy6mTeKQ5dOAYNLGwK3VjMOQ8io42H+Q==", "license": "SEE LICENSE IN LICENSE.md" }, "node_modules/@types/estree": { diff --git a/package.json b/package.json index bc41eb4..6c9a0b3 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "vite": "^7.0.7" }, "dependencies": { - "@tailwindplus/elements": "^1.0.20", + "@tailwindplus/elements": "^1.0.21", "alpinejs": "^3.15.3" } } diff --git a/resources/views/admin/audition_etude/grid.blade.php b/resources/views/admin/audition_etude/grid.blade.php index c31a8bb..967fb0e 100644 --- a/resources/views/admin/audition_etude/grid.blade.php +++ b/resources/views/admin/audition_etude/grid.blade.php @@ -1,4 +1,50 @@ - + + + + + + +
+ + + + + +
+
+

+ Update Etude

+
+ + + +
+ +
+
+
+ +
+
+ +
+
+
+
+
+
+ + @foreach($ensembles as $ensemble) {{ $ensemble->name }} @@ -14,6 +60,41 @@ @foreach($instruments as $instrument) {{ $instrument->instrument }} + @for($n=1; $n<= $ensemble->set_count; $n++) + @if($ensemble->getEtude($instrument, $n)) + + + {{ $ensemble->abbreviation }} - {{ $instrument->instrument }} - Set {{ $n }} +
+
+
+ @else + + + No Etude + + + @endif + @endfor @endforeach diff --git a/resources/views/components/layout/admin.blade.php b/resources/views/components/layout/admin.blade.php index 76517fc..a95dd37 100644 --- a/resources/views/components/layout/admin.blade.php +++ b/resources/views/components/layout/admin.blade.php @@ -8,7 +8,7 @@ @vite(['resources/css/app.css', 'resources/js/app.js']) - +