Fix error in judging dashboard
This commit is contained in:
parent
c4ea5be570
commit
856c254dd1
|
|
@ -41,6 +41,7 @@ class EntryController extends Controller
|
|||
|
||||
public function destroy(Request $request, Entry $entry)
|
||||
{
|
||||
if ($request->user()->cannot('delete', $entry)) abort(403);
|
||||
$entry->delete();
|
||||
return redirect('/entries')->with('success','The ' . $entry->audition->name . 'entry for ' . $entry->student->full_name(). 'has been deleted.');
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ class JudgingController extends Controller
|
|||
public function entryScoreSheet(Entry $entry)
|
||||
{
|
||||
// TODO verify user is assigned to judge this audition
|
||||
return view('judging.entry_score_sheet',compact('entry'));
|
||||
$oldSheet = ScoreSheet::where('user_id',Auth::id())->where('entry_id',$entry->id)->value('subscores') ?? null;
|
||||
return view('judging.entry_score_sheet',compact('entry','oldSheet'));
|
||||
}
|
||||
|
||||
public function saveScoreSheet(Request $request, Entry $entry)
|
||||
|
|
@ -64,5 +65,31 @@ class JudgingController extends Controller
|
|||
|
||||
}
|
||||
|
||||
public function updateScoreSheet(Request $request, Entry $entry)
|
||||
{
|
||||
$scoreSheet = ScoreSheet::where('user_id',Auth::id())->where('entry_id',$entry->id)->first();
|
||||
if (!$scoreSheet) return redirect()->back()->with('error','Attempt to edit non existent entry');
|
||||
Gate::authorize('update',$scoreSheet);
|
||||
|
||||
$scoringGuide = $entry->audition->scoringGuide()->with('subscores')->first();
|
||||
$scoreValidation = $scoringGuide->validateScores($request->input('score'));
|
||||
if ($scoreValidation != 'success') {
|
||||
return redirect(url()->previous())->with('error', $scoreValidation)->with('oldScores',$request->all());
|
||||
}
|
||||
$scoreSheetArray = [];
|
||||
foreach($scoringGuide->subscores as $subscore) {
|
||||
$scoreSheetArray[$subscore->id] = [
|
||||
'score' => $request->input('score')[$subscore->id],
|
||||
'subscore_id' => $subscore->id,
|
||||
'subscore_name' => $subscore->name
|
||||
];
|
||||
}
|
||||
|
||||
$scoreSheet->update([
|
||||
'subscores' => $scoreSheetArray
|
||||
]);
|
||||
return redirect('/judging/audition/' . $entry->audition_id)->with('success','Updated scores for ' . $entry->audition->name . ' ' . $entry->draw_number);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ class EntryPolicy
|
|||
public function delete(User $user, Entry $entry): bool
|
||||
{
|
||||
if($user->is_admin) return true;
|
||||
// Return false if $entry->audition->entry_deadline is in the past, continue if not
|
||||
if ($entry->audition->entry_deadline < now()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->school_id == $entry->student()->school_id;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ScoreSheetPolicy
|
|||
*/
|
||||
public function update(User $user, ScoreSheet $scoreSheet): bool
|
||||
{
|
||||
//
|
||||
return $user->id == $scoreSheet->user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
||||
<env name="BCRYPT_ROUNDS" value="4"/>
|
||||
<env name="CACHE_STORE" value="array"/>
|
||||
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
|
||||
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
|
||||
<env name="DB_CONNECTION" value="sqlite"/>
|
||||
<env name="DB_DATABASE" value=":memory:"/>
|
||||
<env name="MAIL_MAILER" value="array"/>
|
||||
<env name="PULSE_ENABLED" value="false"/>
|
||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
@foreach($users as $user)
|
||||
<tr>
|
||||
<x-table.td><a href="/admin/users/{{ $user->id }}/edit">{{ $user->full_name(true) }}</a></x-table.td>
|
||||
<x-table.td>{{ $user->has_school() ? $user->school->name : ' ' }}</x-table.td> {{-- TODO link to the school --}}
|
||||
<x-table.td>{{ $user->has_school() ? $user->school->name : ' ' }}</x-table.td>
|
||||
<x-table.td>{{ $user->email }}</x-table.td>
|
||||
<x-table.td>{{ $user->cell_phone }}</x-table.td>
|
||||
<x-table.td>{{ $user->judging_preference }}</x-table.td>
|
||||
|
|
|
|||
|
|
@ -56,16 +56,16 @@
|
|||
<x-table.td first>{{ $entry->student->full_name(true) }}</x-table.td>
|
||||
<x-table.td>{{ $entry->student->grade }}</x-table.td>
|
||||
<x-table.td>{{ $entry->audition->name }}</x-table.td>
|
||||
{{-- TODO block deletion of entries past the deadline--}}
|
||||
<x-table.td for_button>
|
||||
<form method="POST" action="/entries/{{ $entry->id }}" class="inline">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<x-table.button
|
||||
onclick="return confirm('Please confirm you would like to delete the {{ $entry->audition->name }} entry for {{ $entry->student->full_name() }}');"
|
||||
>Delete</x-table.button>
|
||||
</form>
|
||||
|
||||
@if( $entry->audition->entry_deadline >= now())
|
||||
<form method="POST" action="/entries/{{ $entry->id }}" class="inline">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<x-table.button
|
||||
onclick="return confirm('Please confirm you would like to delete the {{ $entry->audition->name }} entry for {{ $entry->student->full_name() }}');"
|
||||
>Delete</x-table.button>
|
||||
</form>
|
||||
@endif
|
||||
</x-table.td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
|
|
|||
|
|
@ -16,15 +16,27 @@
|
|||
</x-slot:subheading>
|
||||
</x-card.heading>
|
||||
<x-form.form metohd="POST" action="/judging/entry/{{$entry->id}}">
|
||||
@if($oldSheet) {{-- if there are existing sores, make this a patch request --}}
|
||||
@method('PATCH')
|
||||
@endif
|
||||
<x-card.list.body class="mt-1">
|
||||
@foreach($entry->audition->scoringGuide->subscores()->orderBy('display_order')->get() as $subscore)
|
||||
@php
|
||||
if($oldScores) {
|
||||
$value = $oldScores['score'][$subscore->id];
|
||||
} elseif ($oldSheet) {
|
||||
$value = $oldSheet[$subscore->id]['score'];
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
@endphp
|
||||
<li class="py-2">
|
||||
|
||||
<x-form.field
|
||||
name="score[{{$subscore->id}}]"
|
||||
type="number"
|
||||
placeholder="{{$subscore->name}}"
|
||||
:value="$oldScores ? $oldScores['score'][$subscore->id] : ''"
|
||||
:value="$value"
|
||||
max="{{ $subscore->max_score }}"
|
||||
required
|
||||
>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use Illuminate\Support\Facades\Auth;
|
|||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/test',[TestController::class,'flashTest'])->middleware('auth','verified');
|
||||
Route::view('/','welcome')->middleware('guest');
|
||||
Route::view('/','welcome')->middleware('guest')->name('home');
|
||||
|
||||
// Judging Routes
|
||||
Route::middleware(['auth','verified',CheckIfCanJudge::class])->prefix('judging')->controller(JudgingController::class)->group(function() {
|
||||
|
|
@ -25,6 +25,7 @@ Route::middleware(['auth','verified',CheckIfCanJudge::class])->prefix('judging')
|
|||
Route::get('/audition/{audition}','auditionEntryList');
|
||||
Route::get('/entry/{entry}','entryScoreSheet');
|
||||
Route::post('/entry/{entry}','saveScoreSheet');
|
||||
Route::patch('/entry/{entry}','updateScoreSheet');
|
||||
});
|
||||
|
||||
// Tabulation Routes
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
it('returns a successful response', function () {
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
use function Pest\Laravel\get;
|
||||
|
||||
it('returns a successful response', function () {
|
||||
// Act & Assert
|
||||
get(route('home'))
|
||||
->assertOk();
|
||||
});
|
||||
Loading…
Reference in New Issue