Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.4 #3

Merged
merged 12 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/Filters/Item/FilterCategoryItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Filters\Item;

use App\Filters\Traits\ShareableConstructor;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;

class FilterCategoryItem
{
use ShareableConstructor;

public function handle(Builder $builder, Closure $next): LengthAwarePaginator
{
if (($category = data_get($this->filters, 'category')) !== null) {
$builder->where('category_id', '=', $category);
}

return $next($builder);
}
}
4 changes: 2 additions & 2 deletions app/Filters/Signature/Filters/FilterSignatureCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Filters\Signature\Filters;

use App\Filters\Signature\ShareableConstructor;
use App\Filters\Traits\ShareableConstructor;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
Expand All @@ -16,7 +16,7 @@ public function handle(Builder $builder, Closure $next): LengthAwarePaginator
if (($category = data_get($this->filters, 'category')) !== null) {
$builder->whereHas(
'item',
fn (Builder $builder) => $builder->where('category_id', $category)
fn (Builder $builder) => $builder->where('category_id', '=', $category)
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Filters/Signature/Filters/FilterSignatureDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Filters\Signature\Filters;

use App\Filters\Signature\ShareableConstructor;
use App\Filters\Traits\ShareableConstructor;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
Expand Down
2 changes: 1 addition & 1 deletion app/Filters/Signature/Filters/FilterSignatureItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Filters\Signature\Filters;

use App\Filters\Signature\ShareableConstructor;
use App\Filters\Traits\ShareableConstructor;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Filters\Signature;
namespace App\Filters\Traits;

trait ShareableConstructor
{
Expand Down
17 changes: 14 additions & 3 deletions app/Http/Livewire/Frontend/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,32 @@ class Index extends Component
public ?string $search = null;

protected $listeners = [
'frontend::reset' => 'category',
'frontend::reset' => 'category',
'frontend::load::more' => 'item',
];

public function render(): View
{
return view('livewire.frontend.index');
}

public function more(): void
{
$this->limit += 9;

$this->emitSelf('frontend::load::more', [
'category' => $this->category,
]);
}

public function category(): void
{
$this->filtered = false;

$this->data = Category::with('items')
->withCount(['items' => fn (Builder $query) => $query->active()]) // @phpstan-ignore-line
->active()
->limit($this->limit)
->oldest('name')
->get();
}

Expand All @@ -53,7 +63,8 @@ public function item(Category $category): void
->search($this->search, 'name')
->with('signatures')
->active()
->limit($this->limit)
->take($this->limit)
->oldest('name')
->get();
}
}
4 changes: 3 additions & 1 deletion app/Http/Livewire/Item/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Create extends Component

public bool $modal = false;

public bool $description = false;

protected array $validationAttributes = [
'item.category_id' => 'categoria',
'item.name' => 'nome',
Expand Down Expand Up @@ -55,7 +57,7 @@ public function rules(): array
'item.category_id' => ['required', Rule::exists('categories', 'id')],
'item.name' => ['required', 'string', 'max:255', Rule::unique('items', 'name')],
'item.description' => ['nullable', 'max:255'],
'item.reference' => ['nullable', 'string', 'max:255'],
'item.reference' => ['nullable', 'url'],
'item.quantity' => ['required', 'integer'],
'item.price' => [Rule::when($this->item->is_quotable, ['required', 'numeric', ])],
'item.is_quotable' => ['nullable', 'boolean'],
Expand Down
60 changes: 60 additions & 0 deletions app/Http/Livewire/Item/Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Http\Livewire\Item;

use Illuminate\Contracts\View\View;
use Livewire\Component;
use WireUi\Traits\Actions;

class Filter extends Component
{
use Actions;

public bool $modal = false;

public bool $filtered = false;

public ?int $category = null;

public int $count = 1;

public function render(): View
{
return view('livewire.item.filter');
}

public function updatedModal(): void
{
if (!$this->modal) {
$this->category = null;
}
}

public function filter(): void
{
$this->modal = false;
$this->count = 1;

if (!$this->category) {
$this->notification()->error('Ops!', 'Selecione ao menos uma categoria.');

return;
}

$this->emitUp('item::index::filter', [
'category' => $this->category,
]);

$this->filtered = true;
}

public function clear(): void
{
$this->category = null;

$this->filtered = false;
$this->count = 0;

$this->emitUp('item::index::refresh');
}
}
33 changes: 23 additions & 10 deletions app/Http/Livewire/Item/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace App\Http\Livewire\Item;

use App\Filters\Item\FilterCategoryItem;
use App\Http\Livewire\Traits\Table;
use App\Models\Item;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Pipeline;
use Livewire\Component;

class Index extends Component
Expand All @@ -14,27 +17,37 @@ class Index extends Component

protected $listeners = [
'item::index::refresh' => '$refresh',
'item::index::filter' => 'filter',
];

private array $filters = [];

public function render(): View
{
return view('livewire.item.index', [
'items' => $this->data(),
]);
}

public function filter(array $filters): void
{
$this->filters = [...$filters];
}

private function data(): LengthAwarePaginator
{
return Item::with(['category', 'signatures'])
->withCount('signatures')
->search(
$this->search,
'name',
'description',
'reference',
)
->orderBy($this->sort, $this->direction)
->paginate($this->quantity);
$items = Item::with(['category', 'signatures'])
->withCount('signatures');

return Pipeline::send($items)
->through([
new FilterCategoryItem($this->filters),
])
->then(
fn (Builder $builder) => $builder->search($this->search, 'name', 'description', 'reference') // @phpstan-ignore-line
->orderBy($this->sort, $this->direction)
->paginate($this->quantity)
);
}

public function update(Item $item): void
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Livewire/Item/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Update extends Component

public bool $modal = false;

public bool $description = false;

protected $listeners = [
'item::update::load' => 'load',
];
Expand All @@ -38,7 +40,7 @@ public function rules(): array
'item.category_id' => ['required', Rule::exists('categories', 'id')],
'item.name' => ['required', 'string', 'max:255', Rule::unique('items', 'name')->ignore($this->item->id)],
'item.description' => ['nullable', 'max:255'],
'item.reference' => ['nullable', 'string', 'max:255'],
'item.reference' => ['nullable', 'url'],
'item.quantity' => ['required', 'integer'],
'item.price' => [Rule::when($this->item->is_quotable, ['required', 'numeric', ])],
'item.is_quotable' => ['nullable', 'boolean'],
Expand Down
1 change: 0 additions & 1 deletion app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Item extends Model

protected $casts = [
'quantity' => 'integer',
'price' => 'decimal:2',
'is_quotable' => 'boolean',
'is_active' => 'boolean',
'last_signed_at' => 'datetime',
Expand Down
1 change: 1 addition & 0 deletions app/View/Components/Filter/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Item extends Component
public function __construct(
public string $label = 'Item',
public ?string $placeholder = 'Procure um item',
public ?string $category = null,
public bool $active = true,
) {
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
public function up(): void
{
Schema::table(
'items',
fn (Blueprint $table) => $table->text('reference')->nullable()->change()
);
}

public function down(): void
{
Schema::table(
'items',
fn (Blueprint $table) => $table->string('reference')->nullable()->change()
);
}
};
22 changes: 20 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@alpinejs/mask": "^3.12.3",
"apexcharts": "^3.41.1"
"apexcharts": "^3.41.1",
"tippy.js": "^6.3.7"
}
}
24 changes: 24 additions & 0 deletions resources/css/app.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer utilities {
.custom-scrollbar {
scrollbar-width: auto;
}

.custom-scrollbar::-webkit-scrollbar {
width: 8px;
}

.custom-scrollbar::-webkit-scrollbar:horizontal {
height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
background-color: #c9c9c9;
border-radius: 10px;
border: transparent;
}
}
Loading
Loading