Skip to content

Commit

Permalink
DTCE-76: Add search field and filters to Load Up > Zip Codes (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: BaffourAdu <[email protected]>
  • Loading branch information
BaffourAdu and BaffourAdu authored Dec 6, 2024
1 parent 3e35f24 commit 04d2741
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 74 deletions.
2 changes: 1 addition & 1 deletion resources/views/models/cart-requirements/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<x-fab::lists.table.column align="right">
{{ $requirement->updated_at->toFormattedDateString() }}
</x-fab::lists.table.column>
@endisset
@endif

<x-fab::lists.table.column align="right" slim>
<a href="{{ route('lego.go-load-up.cart-requirements.edit', $requirement) }}">Edit</a>
Expand Down
9 changes: 0 additions & 9 deletions resources/views/models/zip-codes/edit.blade.php

This file was deleted.

89 changes: 50 additions & 39 deletions resources/views/models/zip-codes/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
@extends('lego::layouts.lego')

@section('content')
<x-fab::layouts.page
title="Zip codes"
:breadcrumbs="[
['title' => 'Go Load Up'],
['title' => 'Zip codes', 'url' => route('lego.go-load-up.zip-codes.index')],
]"
>
<x-slot name="actions">
<x-fab::elements.button type="link" :url="route('lego.go-load-up.zip-codes.upload')">Upload Zip Codes</x-fab::elements.button>
<x-fab::layouts.page
title="Zip codes"
:breadcrumbs="[
['title' => 'Go Load Up'],
['title' => 'Zip codes', 'url' => route('lego.go-load-up.zip-codes.index')],
]"
x-data="{ showColumnFilters: false }"
>
<x-slot name="actions">
<x-fab::elements.button type="link" :url="route('lego.go-load-up.zip-codes.upload')">Upload Zip Codes</x-fab::elements.button>
</x-slot>

@include('lego::models._includes.indexes.filters')

<x-fab::lists.table class="mt-8">
<x-slot name="headers">
@include('lego::models._includes.indexes.headers')
<x-fab::lists.table.header :hidden="true">Edit</x-fab::lists.table.header>
</x-slot>

<x-fab::lists.table class="mt-8">
<x-slot name="headers">
<x-fab::lists.table.header>Zip</x-fab::lists.table.header>
<x-fab::lists.table.header>Name</x-fab::lists.table.header>
<x-fab::lists.table.header>Eligibility</x-fab::lists.table.header>
<x-fab::lists.table.header>Last updated</x-fab::lists.table.header>
<x-fab::lists.table.header :hidden="true">Edit</x-fab::lists.table.header>
</x-slot>

@foreach($zipCodes as $zipCode)
<x-fab::lists.table.row :odd="$loop->odd">
@include('lego::models._includes.indexes.header-filters')
<x-fab::lists.table.header x-show="showColumnFilters" x-cloak class="bg-gray-100" />

@foreach($models as $zipCode)
<x-fab::lists.table.row :odd="$loop->odd">
@if($this->shouldShowColumn('zip'))
<x-fab::lists.table.column full primary>
<a href="{{ route('lego.go-load-up.zip-codes.edit', $zipCode) }}">{{ $zipCode->zip }}</a>
</x-fab::lists.table.column>
@endif

@if($this->shouldShowColumn('name'))
<x-fab::lists.table.column >
<a href="{{ route('lego.go-load-up.zip-codes.edit', $zipCode) }}">{{ $zipCode->name }}</a>
</x-fab::lists.table.column>
@endif

@if($this->shouldShowColumn('is_eligible'))
<x-fab::lists.table.column >
{{ $zipCode->isEligible() ? 'Eligible' : 'Ineligible' }}
</x-fab::lists.table.column>
@endif

@if($this->shouldShowColumn('updated_at'))
<x-fab::lists.table.column
align="right">{{ $zipCode->updated_at->toFormattedDateString() }}</x-fab::lists.table.column>
<x-fab::lists.table.column align="right" slim>
<a href="{{ route('lego.go-load-up.zip-codes.edit', $zipCode) }}">Edit</a>
align="right">{{ $zipCode->updated_at->toFormattedDateString() }}
</x-fab::lists.table.column>
</x-fab::lists.table.row>
@endforeach
</x-fab::lists.table>

<div class="pt-6">
{{ $zipCodes->links() }}
</div>
</x-fab::layouts.page>
@endsection

@push('styles')
<link href="{{ asset('vendor/go-load-up/css/go-load-up.css') }}" rel="stylesheet">
@endpush
@endif

<x-fab::lists.table.column align="right" slim>
<a href="{{ route('lego.go-load-up.zip-codes.edit', $zipCode) }}">Edit</a>
</x-fab::lists.table.column>
</x-fab::lists.table.row>
@endforeach
</x-fab::lists.table>

@include('lego::models._includes.indexes.pagination')

@push('styles')
<link href="{{ asset('vendor/go-load-up/css/go-load-up.css') }}" rel="stylesheet">
@endpush
</x-fab::layouts.page>

6 changes: 3 additions & 3 deletions routes/backend.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
use Astrogoat\GoLoadUp\Http\Controllers\GoLoadUpController;
use Astrogoat\GoLoadUp\Http\Livewire\Models\CartRequirements;
use Astrogoat\GoLoadUp\Http\Livewire\Models\ZipCodes;
use Astrogoat\GoLoadUp\Http\Livewire\Models\Services;
use Illuminate\Support\Facades\Route;

Expand All @@ -12,8 +12,8 @@
'as' => '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');
});

Expand Down
6 changes: 4 additions & 2 deletions src/GoLoadUpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 0 additions & 14 deletions src/Http/Controllers/GoLoadUpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,16 @@
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);

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');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?php

namespace Astrogoat\GoLoadUp\Http\Livewire\Models;
namespace Astrogoat\GoLoadUp\Http\Livewire\Models\ZipCodes;

use Helix\Lego\Http\Livewire\Models\Form;
use Astrogoat\GoLoadUp\Models\ZipCode;
use Helix\Lego\Http\Livewire\Models\Form as BaseForm;

class ZipCodeForm extends Form
class Form extends BaseForm
{
protected bool $canBeViewed = false;

public function mount($zipCode)
{
$this->setModel($zipCode);
}

public function rules()
{
return [
Expand All @@ -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));
}
}

Expand Down
36 changes: 36 additions & 0 deletions src/Http/Livewire/Models/ZipCodes/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Astrogoat\GoLoadUp\Http\Livewire\Models\ZipCodes;

use Astrogoat\GoLoadUp\Models\ZipCode;
use Helix\Lego\Http\Livewire\Models\Index as BaseIndex;

class Index extends BaseIndex
{
public function model(): string
{
return ZipCode::class;
}

public function columns(): array
{
return [
'zip' => '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');
}
}

0 comments on commit 04d2741

Please sign in to comment.