Most basic management function of prelim definitions done. Need to add delete method and listener for logging next.
This commit is contained in:
parent
352897fa25
commit
b7b5d0fc94
|
|
@ -25,9 +25,11 @@ class PrelimDefinitionController extends Controller
|
|||
$auditions = Audition::doesntHave('prelimDefinition')->get();
|
||||
$rooms = Room::all();
|
||||
$guides = ScoringGuide::all();
|
||||
$action = 'create';
|
||||
$method = 'POST';
|
||||
$action = route('admin.prelim_definitions.store');
|
||||
$prelim = false;
|
||||
|
||||
return view('admin.prelim_definitions.createOrUpdate', compact('auditions', 'rooms', 'guides', 'action'));
|
||||
return view('admin.prelim_definitions.createOrUpdate', compact('auditions', 'rooms', 'guides', 'method', 'action', 'prelim'));
|
||||
}
|
||||
|
||||
public function store(PrelimDefinitionStoreOrUpdateRequest $request)
|
||||
|
|
@ -35,11 +37,27 @@ class PrelimDefinitionController extends Controller
|
|||
$validated = $request->validated();
|
||||
PrelimDefinition::create($validated);
|
||||
|
||||
return redirect()->route('admin.prelim_definitions.index');
|
||||
return redirect()->route('admin.prelim_definitions.index')->with('success', 'Prelim definition created');
|
||||
}
|
||||
|
||||
public function edit(PrelimDefinition $prelimDefinition)
|
||||
{
|
||||
$auditions = Audition::doesntHave('prelimDefinition')->get();
|
||||
$rooms = Room::all();
|
||||
$guides = ScoringGuide::all();
|
||||
$method = 'PATCH';
|
||||
$action = route('admin.prelim_definitions.update', $prelimDefinition);
|
||||
$prelim = $prelimDefinition;
|
||||
|
||||
return view('admin.prelim_definitions.createOrUpdate', compact('auditions', 'rooms', 'guides', 'method', 'action', 'prelim'));
|
||||
|
||||
}
|
||||
|
||||
public function update(PrelimDefinition $prelimDefinition, PrelimDefinitionStoreOrUpdateRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
$prelimDefinition->update($validated);
|
||||
|
||||
return redirect()->route('admin.prelim_definitions.index')->with('success', 'Prelim definition updated');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,28 @@
|
|||
<x-slot:page_title>Manage Prelim Auditions</x-slot:page_title>
|
||||
<div class="max-w-lg mx-auto">
|
||||
<x-card.card class="pb-5">
|
||||
<x-card.heading>Create Prelim Audition</x-card.heading>
|
||||
<x-card.heading>
|
||||
@if($prelim)
|
||||
Modify Prelim - {{ $prelim->audition->name }}
|
||||
@else
|
||||
Create Prelim Audition
|
||||
@endif
|
||||
</x-card.heading>
|
||||
|
||||
<x-form.form method="{{ $method }}" action="{{ $action }}"
|
||||
x-data="{ canSubmit: {{ ! $prelim ? 'false':'true' }} }">
|
||||
|
||||
<x-form.form method="POST" action="{{ route('admin.prelim_definitions.store') }}"
|
||||
x-data="{ canSubmit: false }">
|
||||
<x-form.select name="audition_id" @change="canSubmit = true">
|
||||
<x-slot:label>Audition</x-slot:label>
|
||||
@if($prelim)
|
||||
<option value="{{ $prelim->audition_id }}">{{ $prelim->audition->name }}</option>
|
||||
@else
|
||||
<option value="" :disabled="canSubmit">Choose Audition</option>
|
||||
@foreach($auditions as $audition)
|
||||
<option value="{{ $audition->id }}">{{ $audition->name }}</option>
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
</x-form.select>
|
||||
@error('audition_id')
|
||||
<div class="text-red-500 text-sm">{{ $message }}</div>
|
||||
|
|
@ -20,7 +32,7 @@
|
|||
<x-form.select name="room_id">
|
||||
<x-slot:label>Room</x-slot:label>
|
||||
@foreach($rooms as $room)
|
||||
<option value="{{ $room->id }}">{{ $room->name }}</option>
|
||||
<option value="{{ $room->id }}" @if($prelim && $prelim->room_id == $room->id) SELECTED @endif>{{ $room->name }}</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
@error('room_id')
|
||||
|
|
@ -30,16 +42,17 @@
|
|||
<x-form.select name="scoring_guide_id">
|
||||
<x-slot:label>Scoring Guide</x-slot:label>
|
||||
@foreach($guides as $guide)
|
||||
<option value="{{ $guide->id }}">{{ $guide->name }}</option>
|
||||
<option value="{{ $guide->id }}" @if($prelim && $prelim->scoring_guide_id == $guide->id) SELECTED @endif>{{ $guide->name }}</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
@error('scoring_guide_id')
|
||||
<div class="text-red-500 text-sm">{{ $message }}</div>
|
||||
@enderror
|
||||
|
||||
<x-form.field name="passing_score" type="number" max="100" min="0" step="0.1" value=60 label_text="Passing Score" />
|
||||
<x-form.field name="passing_score" type="number" max="100" min="0" step="0.1" :value=" $prelim ? $prelim->passing_score : 60"
|
||||
label_text="Passing Score"/>
|
||||
|
||||
<x-form.footer submit-button-text="Create Prelim Audition" x-show="canSubmit" x-cloak></x-form.footer>
|
||||
<x-form.footer submit-button-text="{{ ! $prelim ? 'Create Prelim Audition':'Modify Prelim Audition' }}" x-show="canSubmit" x-cloak></x-form.footer>
|
||||
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
|
|
|
|||
|
|
@ -211,6 +211,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
|||
Route::get('/new', 'create')->name('admin.prelim_definitions.create');
|
||||
Route::post('/', 'store')->name('admin.prelim_definitions.store');
|
||||
Route::get('/{prelimDefinition}', 'edit')->name('admin.prelim_definitions.edit');
|
||||
Route::patch('/{prelimDefinition}', 'update')->name('admin.prelim_definitions.update');
|
||||
Route::delete('/{prelimDefinition}', 'destroy')->name('admin.prelim_definitions.destroy');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -88,3 +88,61 @@ describe('PrelimDefinitionController::store', function () {
|
|||
->assertRedirect(route('admin.prelim_definitions.create'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('PrelimDefinitionController::edit', function () {
|
||||
beforeEach(function () {
|
||||
$this->audition = Audition::factory()->create();
|
||||
$this->prelim = PrelimDefinition::create([
|
||||
'audition_id' => $this->audition->id,
|
||||
'room_id' => 0,
|
||||
'scoring_guide_id' => 0,
|
||||
'passing_score' => 75,
|
||||
]);
|
||||
});
|
||||
it('denies access to a non-admin user', function () {
|
||||
$this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('home'));
|
||||
actAsNormal();
|
||||
$this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('dashboard'));
|
||||
actAsTab();
|
||||
$this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('dashboard'));
|
||||
});
|
||||
it('shows a form to edit a prelim definition', function () {
|
||||
actAsAdmin();
|
||||
$response = $this->get(route('admin.prelim_definitions.edit', $this->prelim))
|
||||
->assertViewIs('admin.prelim_definitions.createOrUpdate')
|
||||
->assertSee($this->audition->name)
|
||||
->assertSee('PATCH')
|
||||
->assertSee(route('admin.prelim_definitions.update', $this->prelim));
|
||||
});
|
||||
});
|
||||
|
||||
describe('PrelimDefinitionController::update', function () {
|
||||
beforeEach(function () {
|
||||
$this->audition = Audition::factory()->create();
|
||||
$this->prelim = PrelimDefinition::create([
|
||||
'audition_id' => $this->audition->id,
|
||||
'room_id' => 0,
|
||||
'scoring_guide_id' => 0,
|
||||
'passing_score' => 75,
|
||||
]);
|
||||
});
|
||||
it('denies access to a non-admin user', function () {
|
||||
$this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('home'));
|
||||
actAsNormal();
|
||||
$this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('dashboard'));
|
||||
actAsTab();
|
||||
$this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('dashboard'));
|
||||
});
|
||||
it('can update a prelim definition', function () {
|
||||
actAsAdmin();
|
||||
$response = $this->patch(route('admin.prelim_definitions.update', $this->prelim), [
|
||||
'audition_id' => $this->audition->id,
|
||||
'room_id' => 0,
|
||||
'scoring_guide_id' => 0,
|
||||
'passing_score' => 90,
|
||||
]);
|
||||
$response
|
||||
->assertRedirect(route('admin.prelim_definitions.index'));
|
||||
expect($this->prelim->fresh()->passing_score)->toEqual(90);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue