Passing data to the form is working.
This commit is contained in:
parent
b50148ff08
commit
a4882d3545
|
|
@ -10,7 +10,7 @@ class AuditionEtudeGridController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$ensembles = Ensemble::all();
|
$ensembles = Ensemble::with('etudes')->get();
|
||||||
$instruments = Instrument::orderBy('score_order')->get();
|
$instruments = Instrument::orderBy('score_order')->get();
|
||||||
|
|
||||||
return view('admin.audition_etude.grid', compact('ensembles', 'instruments'));
|
return view('admin.audition_etude.grid', compact('ensembles', 'instruments'));
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,19 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
class Ensemble extends Model
|
class Ensemble extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name', 'set_count',
|
'name', 'set_count', 'abbreviation',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function etudes(): HasMany
|
public function etudes(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(AuditionEtude::class, 'ensemble_id');
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,19 @@
|
||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\AuditionEtude;
|
||||||
use App\Models\Ensemble;
|
use App\Models\Ensemble;
|
||||||
|
use App\Models\Instrument;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
readonly class AuditionEtudeService
|
class AuditionEtudeService
|
||||||
{
|
{
|
||||||
protected int $startYear;
|
protected int $startYear;
|
||||||
|
|
||||||
protected int $changeoverMonth;
|
protected int $changeoverMonth;
|
||||||
|
|
||||||
|
protected array $etudeCache = [];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->startYear = config('siteData.etude_start_year');
|
$this->startYear = config('siteData.etude_start_year');
|
||||||
|
|
@ -77,4 +81,29 @@ readonly class AuditionEtudeService
|
||||||
|
|
||||||
return ($yearDiff % $setCount) + 1;
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,14 @@ class Admin extends Component
|
||||||
'name' => 'Audition Etudes',
|
'name' => 'Audition Etudes',
|
||||||
'link' => route('admin.etudes.index'),
|
'link' => route('admin.etudes.index'),
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Audition Etude Grid',
|
||||||
|
'link' => route('admin.etude-grid'),
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'name' => 'News Stories',
|
'name' => 'News Stories',
|
||||||
'link' => route('admin.news.index'),
|
'link' => route('admin.news.index'),
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindplus/elements": "^1.0.20",
|
"@tailwindplus/elements": "^1.0.21",
|
||||||
"alpinejs": "^3.15.3"
|
"alpinejs": "^3.15.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
@ -1090,9 +1090,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tailwindplus/elements": {
|
"node_modules/@tailwindplus/elements": {
|
||||||
"version": "1.0.20",
|
"version": "1.0.21",
|
||||||
"resolved": "https://registry.npmjs.org/@tailwindplus/elements/-/elements-1.0.20.tgz",
|
"resolved": "https://registry.npmjs.org/@tailwindplus/elements/-/elements-1.0.21.tgz",
|
||||||
"integrity": "sha512-ka/4LlqzXmKjcoyRsKu8eBotl3KaDrMhdTr2+YDpjLj5Sy21FTIgg0gniDBPYTVZMFj6L82Cw4aNh2BJkjuRoQ==",
|
"integrity": "sha512-CShPoilDolGpzT9J4MVTCexOijwURW+MHGNMoS5ijiD2FVNk1XHFvEuy6mTeKQ5dOAYNLGwK3VjMOQ8io42H+Q==",
|
||||||
"license": "SEE LICENSE IN LICENSE.md"
|
"license": "SEE LICENSE IN LICENSE.md"
|
||||||
},
|
},
|
||||||
"node_modules/@types/estree": {
|
"node_modules/@types/estree": {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
"vite": "^7.0.7"
|
"vite": "^7.0.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindplus/elements": "^1.0.20",
|
"@tailwindplus/elements": "^1.0.21",
|
||||||
"alpinejs": "^3.15.3"
|
"alpinejs": "^3.15.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
@foreach($ensembles as $ensemble)
|
||||||
<x-card class="mb-5">
|
<x-card class="mb-5">
|
||||||
<x-slot:header class="bg-brand-600!">{{ $ensemble->name }}</x-slot:header>
|
<x-slot:header class="bg-brand-600!">{{ $ensemble->name }}</x-slot:header>
|
||||||
|
|
@ -14,6 +60,41 @@
|
||||||
@foreach($instruments as $instrument)
|
@foreach($instruments as $instrument)
|
||||||
<tr class="outline-1 outline-black/5 dark:outline-white/1">
|
<tr class="outline-1 outline-black/5 dark:outline-white/1">
|
||||||
<x-table.td>{{ $instrument->instrument }}</x-table.td>
|
<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>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body class="h-full">
|
<body class="h-full" {{ $attributes }}>
|
||||||
|
|
||||||
<!-- Include this script tag or install `@tailwindplus/elements` via npm: -->
|
<!-- Include this script tag or install `@tailwindplus/elements` via npm: -->
|
||||||
<!-- <script src="https://cdn.jsdelivr.net/npm/@tailwindplus/elements@1" type="module"></script> -->
|
<!-- <script src="https://cdn.jsdelivr.net/npm/@tailwindplus/elements@1" type="module"></script> -->
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue