Implement nomination reordering by users.
This commit is contained in:
parent
bbb0b68a8f
commit
a0b4ffe855
|
|
@ -147,7 +147,7 @@ class ScobdaNominationEnsembleEntryController extends Controller implements Nomi
|
||||||
*
|
*
|
||||||
* @var returnType = next|nominations
|
* @var returnType = next|nominations
|
||||||
*/
|
*/
|
||||||
private function collapseNominations(School $school, NominationEnsemble $ensemble, $returnType)
|
private function collapseNominations(School $school, NominationEnsemble $ensemble, $returnType = 'next')
|
||||||
{
|
{
|
||||||
$nominations = $school->nominations()->get()->where('nomination_ensemble_id',
|
$nominations = $school->nominations()->get()->where('nomination_ensemble_id',
|
||||||
$ensemble->id)->sortBy('data.rank');
|
$ensemble->id)->sortBy('data.rank');
|
||||||
|
|
@ -163,4 +163,28 @@ class ScobdaNominationEnsembleEntryController extends Controller implements Nomi
|
||||||
|
|
||||||
return $nominations;
|
return $nominations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function move()
|
||||||
|
{
|
||||||
|
|
||||||
|
// TODO: Verify the student being moved is from the users school
|
||||||
|
$validData = request()->validate([
|
||||||
|
'direction' => 'required|in:up,down',
|
||||||
|
'nominationId' => 'required|exists:App\Models\NominationEnsembleEntry,id',
|
||||||
|
]);
|
||||||
|
$direction = $validData['direction'];
|
||||||
|
$nomination = NominationEnsembleEntry::findOrFail($validData['nominationId']);
|
||||||
|
$data = $nomination->data;
|
||||||
|
if ($validData['direction'] == 'up') {
|
||||||
|
$data['rank'] = $nomination->data['rank'] - 1.5;
|
||||||
|
}
|
||||||
|
if ($validData['direction'] == 'down') {
|
||||||
|
$data['rank'] = $nomination->data['rank'] + 1.5;
|
||||||
|
}
|
||||||
|
$nomination->update(['data' => $data]);
|
||||||
|
$this->collapseNominations($nomination->student->school, $nomination->ensemble, 'next');
|
||||||
|
|
||||||
|
return redirect()->route('nomination.entry.index')->with('success', 'Nomination Moved');
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class NominationEnsembleEntry extends Model
|
||||||
|
|
||||||
protected function ensemble(): BelongsTo
|
protected function ensemble(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(NominationEnsemble::class);
|
return $this->belongsTo(NominationEnsemble::class, 'nomination_ensemble_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function student(): BelongsTo
|
protected function student(): BelongsTo
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||||
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19V5m0 14-4-4m4 4 4-4"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 296 B |
|
|
@ -0,0 +1,3 @@
|
||||||
|
<svg class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||||
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v13m0-13 4 4m-4-4-4 4"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 297 B |
|
|
@ -23,7 +23,7 @@
|
||||||
<x-table.td>{{ $nomination->data['rank'] }}</x-table.td>
|
<x-table.td>{{ $nomination->data['rank'] }}</x-table.td>
|
||||||
<x-table.td>{{ $nomination->student->full_name() }}</x-table.td>
|
<x-table.td>{{ $nomination->student->full_name() }}</x-table.td>
|
||||||
<x-table.td>{{ $nomination->data['instrument'] }}</x-table.td>
|
<x-table.td>{{ $nomination->data['instrument'] }}</x-table.td>
|
||||||
<x-table.td>
|
<x-table.td class="flex">
|
||||||
<x-delete-resource-modal
|
<x-delete-resource-modal
|
||||||
title="Delete Nomination"
|
title="Delete Nomination"
|
||||||
method="DELETE"
|
method="DELETE"
|
||||||
|
|
@ -31,6 +31,18 @@
|
||||||
Confirm you wish to delete the nomination of {{ $nomination->student->full_name() }}<br>
|
Confirm you wish to delete the nomination of {{ $nomination->student->full_name() }}<br>
|
||||||
for the {{ $ensemble->name }} ensemble.
|
for the {{ $ensemble->name }} ensemble.
|
||||||
</x-delete-resource-modal>
|
</x-delete-resource-modal>
|
||||||
|
<form method="POST" action="{{ route('nomination.entry.move') }}">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="direction" value="up">
|
||||||
|
<input type="hidden" name="nominationId" value="{{ $nomination->id }}">
|
||||||
|
<button class="ml-3" type="submit"><x-icons.up-arrow /></button>
|
||||||
|
</form>
|
||||||
|
<form method="POST" action="{{ route('nomination.entry.move') }}">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="direction" value="down">
|
||||||
|
<input type="hidden" name="nominationId" value="{{ $nomination->id }}">
|
||||||
|
<button class="ml-3" type="submit"><x-icons.down-arrow /></button>
|
||||||
|
</form>
|
||||||
</x-table.td>
|
</x-table.td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,6 @@ Route::middleware(['auth', 'verified'])->prefix('nominations/')->group(function
|
||||||
Route::get('/', 'index')->name('nomination.entry.index');
|
Route::get('/', 'index')->name('nomination.entry.index');
|
||||||
Route::post('/', 'store')->name('nomination.entry.store');
|
Route::post('/', 'store')->name('nomination.entry.store');
|
||||||
Route::delete('/{entry}', 'destroy')->name('nomination.entry.destroy');
|
Route::delete('/{entry}', 'destroy')->name('nomination.entry.destroy');
|
||||||
|
Route::post('/move', 'move')->name('nomination.entry.move');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue