-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
315 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Divisions; | ||
|
||
use App\Livewire\Forms\DivisionForm; | ||
use App\Models\Competition; | ||
use App\Models\Division; | ||
use App\Models\Season; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Create extends Component | ||
{ | ||
public DivisionForm $form; | ||
|
||
public function mount(Division $division): void | ||
{ | ||
$this->form->setDivisionModel($division); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
$this->form->store(); | ||
|
||
$this->redirectRoute('divisions.index', navigate: true); | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
return view('livewire.division.create', [ | ||
'seasons' => Season::latest('year')->get(), | ||
'competitions' => Competition::all(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Divisions; | ||
|
||
use App\Livewire\Forms\DivisionForm; | ||
use App\Models\Division; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Edit extends Component | ||
{ | ||
public DivisionForm $form; | ||
|
||
public function mount(Division $division): void | ||
{ | ||
$this->form->setDivisionModel($division); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
$this->form->update(); | ||
|
||
$this->redirectRoute('divisions.index', navigate: true); | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
return view('livewire.division.edit'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Divisions; | ||
|
||
use App\Models\Division; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
class Index extends Component | ||
{ | ||
use WithPagination; | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
$divisions = Division::with(['competition', 'competition.season']) | ||
->oldest('display_order') | ||
->simplePaginate(10); | ||
|
||
return view('livewire.division.index', compact('divisions')) | ||
->with('i', $this->getPage() * $divisions->perPage()); | ||
} | ||
|
||
public function delete(Division $division): void | ||
{ | ||
$division->delete(); | ||
|
||
$this->redirectRoute('divisions.index', navigate: true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Divisions; | ||
|
||
use App\Livewire\Forms\DivisionForm; | ||
use App\Models\Division; | ||
use Illuminate\View\View; | ||
use Livewire\Attributes\Layout; | ||
use Livewire\Component; | ||
|
||
class Show extends Component | ||
{ | ||
public DivisionForm $form; | ||
|
||
public function mount(Division $division): void | ||
{ | ||
$this->form->setDivisionModel($division); | ||
} | ||
|
||
#[Layout('layouts.app')] | ||
public function render(): View | ||
{ | ||
return view('livewire.division.show', ['division' => $this->form->divisionModel]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Forms; | ||
|
||
use App\Models\Division; | ||
use Livewire\Form; | ||
|
||
class DivisionForm extends Form | ||
{ | ||
public ?Division $divisionModel; | ||
|
||
public ?string $competition_id; | ||
|
||
public ?string $name; | ||
|
||
public ?int $display_order; | ||
|
||
public ?string $seasonName; | ||
|
||
public ?string $competitionName; | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'competition_id' => 'required|uuid|exists:competitions,id', | ||
'name' => 'required|string', | ||
'display_order' => 'required|int|min:1', | ||
]; | ||
} | ||
|
||
public function messages(): array | ||
{ | ||
return [ | ||
'competition_id.required' => 'Please choose a competition.', | ||
'name.required' => 'The division\'s name is required.', | ||
'display_order.required' => 'Please choose a positive number.', | ||
]; | ||
} | ||
|
||
public function setDivisionModel(Division $divisionModel): void | ||
{ | ||
$this->divisionModel = $divisionModel; | ||
|
||
$this->competition_id = $this->divisionModel->competition_id; | ||
$this->name = $this->divisionModel->name; | ||
$this->display_order = $this->divisionModel->display_order; | ||
$this->seasonName = $this->divisionModel?->competition?->season?->name; | ||
$this->competitionName = $this->divisionModel?->competition?->name; | ||
|
||
} | ||
|
||
public function store(): void | ||
{ | ||
$this->divisionModel->create($this->validate()); | ||
|
||
$this->reset(); | ||
} | ||
|
||
public function update(): void | ||
{ | ||
$this->divisionModel->update($this->validate()); | ||
|
||
$this->reset(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<x-crud.header>Divisions</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="divisions.index">Create a new division</x-crud.subheader> | ||
|
||
<x-crud.content class="mt-8 max-w-xl"> | ||
<form method="POST" wire:submit="save" role="form" enctype="multipart/form-data"> | ||
@csrf | ||
@include('livewire.division.form') | ||
</form> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<x-crud.header>Division</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="divisions.index">Update the {{ $form->name }} division</x-crud.subheader> | ||
|
||
<x-crud.content class="mt-8 max-w-xl"> | ||
<form method="POST" wire:submit="save" role="form" enctype="multipart/form-data"> | ||
{{ method_field('PATCH') }} | ||
@csrf | ||
@include('livewire.division.form') | ||
</form> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<div class="space-y-6"> | ||
<div> | ||
<x-input-label for="season_id" value="Season" /> | ||
@empty($form->competition_id) | ||
<x-select-input wire:model="form.season_id" id="season_id" name="season_id" class="mt-1 block w-full" | ||
:options="$seasons" placeholder="Choose a season" /> | ||
@else | ||
<x-text-input wire:model="form.seasonName" id="season_id" name="season_id" type="text" | ||
class="mt-1 block w-full" disabled /> | ||
@endempty | ||
@error('form.season_id') | ||
<x-input-error class="mt-2" :messages="$message" /> | ||
@enderror | ||
</div> | ||
<div> | ||
<x-input-label for="competitions_id" value="Competition" /> | ||
@empty($form->competition_id) | ||
<x-select-input wire:model="form.competition_id" id="competition_id" name="competition_id" | ||
class="mt-1 block w-full" | ||
:options="$competitions" placeholder="Choose a competition" /> | ||
@else | ||
<x-text-input wire:model="form.competitionName" id="competition_id" name="competition_id" type="text" | ||
class="mt-1 block w-full" disabled /> | ||
@endempty | ||
@error('form.competition_id') | ||
<x-input-error class="mt-2" :messages="$message" /> | ||
@enderror | ||
</div> | ||
<div> | ||
<x-input-label for="name" value="Name" /> | ||
<x-text-input wire:model="form.name" id="name" name="name" type="text" class="mt-1 block w-full" | ||
autocomplete="name" placeholder="Name" /> | ||
@error('form.name') | ||
<x-input-error class="mt-2" :messages="$message" /> | ||
@enderror | ||
</div> | ||
<div> | ||
<x-input-label for="display_order" value="Display Order" /> | ||
<x-text-input wire:model="form.display_order" id="display_order" name="display_order" type="text" | ||
class="mt-1 block w-full" autocomplete="display_order" placeholder="Display Order" /> | ||
@error('form.display_order') | ||
<x-input-error class="mt-2" :messages="$message" /> | ||
@enderror | ||
</div> | ||
|
||
<div class="flex items-center gap-4"> | ||
<x-primary-button>Save</x-primary-button> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<x-crud.header>Divisions</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader add-route="divisions.create" class="mb-4"> | ||
A list of all the divisions in the system | ||
</x-crud.subheader> | ||
<x-crud.content> | ||
<x-crud.index.table columns="season,competition,name,display order"> | ||
@foreach ($divisions as $division) | ||
<x-crud.index.row row-key="{{ $division->getKey() }}"> | ||
<x-crud.index.cell>{{ $division->competition->season->name }}</x-crud.index.cell> | ||
<x-crud.index.cell>{{ $division->competition->name }}</x-crud.index.cell> | ||
<x-crud.index.cell>{{ $division->name }}</x-crud.index.cell> | ||
<x-crud.index.cell>{{ $division->display_order }}</x-crud.index.cell> | ||
<x-crud.index.cell class="flex gap-1 pl-2 pr-0 font-medium"> | ||
<x-crud.index.show-button route="divisions.show" :model="$division" /> | ||
<x-crud.index.edit-button route="divisions.edit" :model="$division" /> | ||
<x-crud.index.delete-button :model="$division"> | ||
Are you sure you want to delete the {{ $division->name }} divisions in the {{ $division->competition->name }} | ||
competition in the {{ $division->competition->season->name }} season? | ||
</x-crud.index.delete-button> | ||
</x-crud.index.cell> | ||
</x-crud.index.row> | ||
@endforeach | ||
</x-crud.index.table> | ||
|
||
<div class="mt-4 px-4"> | ||
{!! $divisions->withQueryString()->links() !!} | ||
</div> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<x-crud.header>Divisions</x-crud.header> | ||
|
||
<div class="w-full"> | ||
<x-crud.subheader back-route="divisions.index">Details of the {{ $division->name }} division</x-crud.subheader> | ||
<x-crud.content> | ||
<x-crud.show.table> | ||
<x-crud.show.model-field label="Season">{{ $division->competition->season->name }}</x-crud.show.model-field> | ||
<x-crud.show.model-field label="Competition">{{ $division->competition->name }}</x-crud.show.model-field> | ||
<x-crud.show.model-field label="Name">{{ $division->name }}</x-crud.show.model-field> | ||
<x-crud.show.model-field label="Display order">{{ $division->display_order }}</x-crud.show.model-field> | ||
</x-crud.show.table> | ||
</x-crud.content> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters