redo-ensemble-table #1

Merged
matt merged 4 commits from redo-ensemble-table into main 2026-01-02 02:40:10 +00:00
8 changed files with 133 additions and 11 deletions
Showing only changes of commit a4882d3545 - Show all commits

View File

@ -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'));

View File

@ -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();
}
}

View File

@ -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];
}
}

View File

@ -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'),
]
],
];
}

8
package-lock.json generated
View File

@ -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": {

View File

@ -15,7 +15,7 @@
"vite": "^7.0.7"
},
"dependencies": {
"@tailwindplus/elements": "^1.0.20",
"@tailwindplus/elements": "^1.0.21",
"alpinejs": "^3.15.3"
}
}

View File

@ -1,4 +1,50 @@
<x-layout.admin>
<x-layout.admin x-data="{ ensemble: 'e', instrument: 'i', set: 's', ensemble_id: '', instrument_id: '' }">
<button command="show-modal" commandfor="etude-uploader"
class="rounded-md bg-gray-950/5 px-2.5 py-1.5 text-sm font-semibold text-gray-900 hover:bg-gray-950/10 dark:bg-white/10 dark:text-white dark:inset-ring dark:inset-ring-white/5 dark:hover:bg-white/20">
Open dialog
</button>
<el-dialog>
<dialog id="etude-uploader" aria-labelledby="Upload Etude"
class="fixed inset-0 size-auto max-h-none max-w-none overflow-y-auto bg-transparent backdrop:bg-transparent">
<el-dialog-backdrop
class="fixed inset-0 bg-gray-500/75 transition-opacity data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in dark:bg-gray-900/50"></el-dialog-backdrop>
<div tabindex="0"
class="flex min-h-full items-end justify-center p-2 text-center focus:outline-none sm:items-center sm:p-0">
<el-dialog-panel
class="relative transform overflow-hidden rounded-lg bg-white px-4 pt-5 pb-4 text-left shadow-xl transition-all data-closed:translate-y-4 data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in sm:my-8 sm:w-full sm:max-w-sm sm:p-6 data-closed:sm:translate-y-0 data-closed:sm:scale-95 dark:bg-gray-800 dark:outline dark:-outline-offset-1 dark:outline-white/10">
<x-form method="POST" action="#">
<input type="hidden" name="ensemble_id" x-model="ensemble_id"/>
<input type="hidden" name="instrument_id" x-model="instrument_id"/>
<input type="hidden" name="set" x-model="set"/>
<div>
<div class="mt-1 text-center sm:mt-3">
<h3 id="dialog-title" class="text-base font-semibold text-gray-900 dark:text-white">
Update Etude</h3>
<div class="mt-2 text-sm text-gray-500 dark:text-gray-400">
<span x-text="ensemble"></span>
<span x-text="instrument"></span>
<span x-text="`Set ${set}`"></span>
</div>
</div>
</div>
<div class="mt-3">
<x-form.input name="file_upload" type="file" label="Etude PDF"/>
</div>
<div class="mt-5 sm:mt-6">
<button type="button" command="close" commandfor="dialog"
class="inline-flex w-full justify-center rounded-md bg-brand-600 px-3 py-2 text-sm font-semibold text-white shadow-xs hover:bg-brand-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-600 dark:bg-brand-500 dark:shadow-none dark:hover:bg-brand-400 dark:focus-visible:outline-brand-500">
Save Etude
</button>
</div>
</x-form>
</el-dialog-panel>
</div>
</dialog>
</el-dialog>
@foreach($ensembles as $ensemble)
<x-card class="mb-5">
<x-slot:header class="bg-brand-600!">{{ $ensemble->name }}</x-slot:header>
@ -14,6 +60,41 @@
@foreach($instruments as $instrument)
<tr class="outline-1 outline-black/5 dark:outline-white/1">
<x-table.td>{{ $instrument->instrument }}</x-table.td>
@for($n=1; $n<= $ensemble->set_count; $n++)
@if($ensemble->getEtude($instrument, $n))
<x-table.td>
<x-form.button
command="show-modal"
commandfor="etude-uploader"
@click="
ensemble = '{{ $ensemble->name }}';
ensemble_id = '{{ $ensemble->id }}';
instrument = '{{ $instrument->instrument }}';
instrument_id = '{{ $instrument->id }}';
set = {{ $n }}"
>
{{ $ensemble->abbreviation }} - {{ $instrument->instrument }} - Set {{ $n }}
<br/>
</x-form.button>
</x-table.td>
@else
<x-table.td>
<x-form.button
command="show-modal"
commandfor="etude-uploader"
class="bg-red-600 hover:bg-red-500"
@click="
ensemble = '{{ $ensemble->name }}';
ensemble_id = '{{ $ensemble->id }}';
instrument = '{{ $instrument->instrument }}';
instrument_id = '{{ $instrument->id }}';
set = {{ $n }}"
>
No Etude
</x-form.button>
</x-table.td>
@endif
@endfor
</tr>
@endforeach
</tbody>

View File

@ -8,7 +8,7 @@
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="h-full">
<body class="h-full" {{ $attributes }}>
<!-- Include this script tag or install `@tailwindplus/elements` via npm: -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@tailwindplus/elements@1" type="module"></script> -->