From 04d2741efcae029f2de50566a615b1b4f5fc1439 Mon Sep 17 00:00:00 2001 From: Baffour Adu Boampong Date: Fri, 6 Dec 2024 20:31:04 +0000 Subject: [PATCH] DTCE-76: Add search field and filters to Load Up > Zip Codes (#9) Co-authored-by: BaffourAdu --- .../models/cart-requirements/index.blade.php | 2 +- .../views/models/zip-codes/edit.blade.php | 9 -- .../views/models/zip-codes/index.blade.php | 89 +++++++++++-------- routes/backend.php | 6 +- src/GoLoadUpServiceProvider.php | 6 +- src/Http/Controllers/GoLoadUpController.php | 14 --- .../{ZipCodeForm.php => ZipCodes/Form.php} | 18 ++-- src/Http/Livewire/Models/ZipCodes/Index.php | 36 ++++++++ 8 files changed, 106 insertions(+), 74 deletions(-) delete mode 100644 resources/views/models/zip-codes/edit.blade.php rename src/Http/Livewire/Models/{ZipCodeForm.php => ZipCodes/Form.php} (63%) create mode 100644 src/Http/Livewire/Models/ZipCodes/Index.php diff --git a/resources/views/models/cart-requirements/index.blade.php b/resources/views/models/cart-requirements/index.blade.php index a407134..58b2b90 100644 --- a/resources/views/models/cart-requirements/index.blade.php +++ b/resources/views/models/cart-requirements/index.blade.php @@ -37,7 +37,7 @@ {{ $requirement->updated_at->toFormattedDateString() }} - @endisset + @endif Edit diff --git a/resources/views/models/zip-codes/edit.blade.php b/resources/views/models/zip-codes/edit.blade.php deleted file mode 100644 index bce6b13..0000000 --- a/resources/views/models/zip-codes/edit.blade.php +++ /dev/null @@ -1,9 +0,0 @@ -@extends('lego::layouts.lego') - -@push('styles') - -@endpush - -@section('content') - -@endsection diff --git a/resources/views/models/zip-codes/index.blade.php b/resources/views/models/zip-codes/index.blade.php index c38070e..f5d0d22 100644 --- a/resources/views/models/zip-codes/index.blade.php +++ b/resources/views/models/zip-codes/index.blade.php @@ -1,52 +1,63 @@ -@extends('lego::layouts.lego') - -@section('content') - - - Upload Zip Codes + + + Upload Zip Codes + + + @include('lego::models._includes.indexes.filters') + + + + @include('lego::models._includes.indexes.headers') + Edit - - - Zip - Name - Eligibility - Last updated - Edit - - - @foreach($zipCodes as $zipCode) - + @include('lego::models._includes.indexes.header-filters') + + + @foreach($models as $zipCode) + + @if($this->shouldShowColumn('zip')) {{ $zipCode->zip }} + @endif + + @if($this->shouldShowColumn('name')) {{ $zipCode->name }} + @endif + + @if($this->shouldShowColumn('is_eligible')) {{ $zipCode->isEligible() ? 'Eligible' : 'Ineligible' }} + @endif + + @if($this->shouldShowColumn('updated_at')) {{ $zipCode->updated_at->toFormattedDateString() }} - - Edit + align="right">{{ $zipCode->updated_at->toFormattedDateString() }} - - @endforeach - - -
- {{ $zipCodes->links() }} -
-
-@endsection - -@push('styles') - -@endpush + @endif + + + Edit + + + @endforeach + + + @include('lego::models._includes.indexes.pagination') + + @push('styles') + + @endpush +
+ diff --git a/routes/backend.php b/routes/backend.php index bc21448..39c796d 100644 --- a/routes/backend.php +++ b/routes/backend.php @@ -1,6 +1,6 @@ 'zip-codes.', 'prefix' => 'zip-codes' ], function () { - Route::get('/', [GoLoadUpController::class, 'index'])->name('index'); - Route::get('/{zipCode}/edit', [GoLoadUpController::class, 'edit'])->name('edit'); + Route::get('/', ZipCodes\Index::class)->name('index'); + Route::get('/{zipCode}/edit', ZipCodes\Form::class)->name('edit'); Route::get('/upload', \Astrogoat\GoLoadUp\Http\Livewire\Upload\CsvUploadForm::class)->name('upload'); }); diff --git a/src/GoLoadUpServiceProvider.php b/src/GoLoadUpServiceProvider.php index 0d1dd8f..2cde1e0 100644 --- a/src/GoLoadUpServiceProvider.php +++ b/src/GoLoadUpServiceProvider.php @@ -5,7 +5,8 @@ use Astrogoat\Cart\Events\CheckingOut; use Astrogoat\GoLoadUp\Http\Livewire\Models\CartRequirements; use Astrogoat\GoLoadUp\Http\Livewire\Models\Services; -use Astrogoat\GoLoadUp\Http\Livewire\Models\ZipCodeForm; +use Astrogoat\GoLoadUp\Http\Livewire\Models\ZipCodes\Form; +use Astrogoat\GoLoadUp\Http\Livewire\Models\ZipCodes\Index; use Astrogoat\GoLoadUp\Http\Livewire\Upload\CsvUploadForm; use Astrogoat\GoLoadUp\Models\ZipCode; use Astrogoat\GoLoadUp\Settings\GoLoadUpSettings; @@ -79,7 +80,8 @@ public function bootingPackage() } }); - Livewire::component('astrogoat.go-load-up.zip-codes.form', ZipCodeForm::class); + Livewire::component('astrogoat.go-load-up.http.livewire.models.zip-codes.form', Form::class); + Livewire::component('astrogoat.go-load-up.http.livewire.models.zip-codes.index', Index::class); Livewire::component('astrogoat.go-load-up.http.livewire.models.services.index', Services\Index::class); Livewire::component('astrogoat.go-load-up.http.livewire.models.cart-requirements.index', CartRequirements\Index::class); Livewire::component('astrogoat.go-load-up.http.livewire.models.cart-requirements.form', CartRequirements\Form::class); diff --git a/src/Http/Controllers/GoLoadUpController.php b/src/Http/Controllers/GoLoadUpController.php index e411c64..c70a1eb 100644 --- a/src/Http/Controllers/GoLoadUpController.php +++ b/src/Http/Controllers/GoLoadUpController.php @@ -3,18 +3,9 @@ namespace Astrogoat\GoLoadUp\Http\Controllers; use Astrogoat\GoLoadUp\Models\GoLoadUpProduct; -use Astrogoat\GoLoadUp\Models\ZipCode; class GoLoadUpController { - public function index() - { - $totalZipCodes = ZipCode::count(); - $zipCodes = ZipCode::paginate(10); - - return view('go-load-up::models.zip-codes.index', compact('totalZipCodes', 'zipCodes')); - } - public function defaultProductOptions() { $productVariants = GoLoadUpProduct::paginate(10); @@ -22,11 +13,6 @@ public function defaultProductOptions() return view('go-load-up::models.product-variants.index', compact('productVariants')); } - public function edit(ZipCode $zipCode) - { - return view('go-load-up::models.zip-codes.edit', compact('zipCode')); - } - public function createGoLoadUpProduct() { return view('go-load-up::models.product-variants.create'); diff --git a/src/Http/Livewire/Models/ZipCodeForm.php b/src/Http/Livewire/Models/ZipCodes/Form.php similarity index 63% rename from src/Http/Livewire/Models/ZipCodeForm.php rename to src/Http/Livewire/Models/ZipCodes/Form.php index d3c776a..ea89255 100644 --- a/src/Http/Livewire/Models/ZipCodeForm.php +++ b/src/Http/Livewire/Models/ZipCodes/Form.php @@ -1,13 +1,19 @@ setModel($zipCode); + } + public function rules() { return [ @@ -19,15 +25,15 @@ public function rules() ]; } - public function mount($zipCode) + public function model(): string { - $this->setModel($zipCode); + return ZipCode::class; } public function saved() { if ($this->model->wasRecentlyCreated) { - return redirect()->to(route('lego.go-load-up.zipcodes.edit', $this->model)); + return redirect()->to(route('lego.go-load-up.zip-codes.edit', $this->model)); } } diff --git a/src/Http/Livewire/Models/ZipCodes/Index.php b/src/Http/Livewire/Models/ZipCodes/Index.php new file mode 100644 index 0000000..a6d9bb2 --- /dev/null +++ b/src/Http/Livewire/Models/ZipCodes/Index.php @@ -0,0 +1,36 @@ + 'Zip', + 'name' => 'Name', + 'is_eligible' => 'Eligibility', + 'updated_at' => 'Last updated', + ]; + } + + public function mainSearchColumn(): string|false + { + return 'name'; + } + + public function render() + { + return view('go-load-up::models.zip-codes.index', [ + 'models' => $this->getModels(), + ])->extends('lego::layouts.lego')->section('content'); + } +}