Skip to content

Commit

Permalink
Merge pull request #332 from lara-zeus/use-tools
Browse files Browse the repository at this point in the history
add filament tools package
  • Loading branch information
atmonshi authored Oct 29, 2024
2 parents 283c860 + f03147f commit a1d5727
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 485 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"guava/filament-icon-picker": "^2.0",
"lara-zeus/accordion": "^1.1",
"lara-zeus/core": "^3.1",
"lara-zeus/filament-plugin-tools": "^1.0",
"lara-zeus/list-group": "^1.0",
"ryangjchandler/blade-tabler-icons": "^2.3"
},
Expand Down
933 changes: 508 additions & 425 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/BoltPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use LaraZeus\Bolt\Filament\Resources\FormResource;
use LaraZeus\Core\Concerns\CanGloballySearch;
use LaraZeus\Core\Concerns\HasRouteNamePrefix;
use LaraZeus\FilamentPluginTools\Concerns\CanDisableBadges;

final class BoltPlugin implements Plugin
{
use CanDisableBadges;
use CanGloballySearch;
use Configuration;
use EvaluatesClosures;
Expand Down
40 changes: 0 additions & 40 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Bolt;

use Closure;
use LaraZeus\Bolt\Enums\Resources;

trait Configuration
{
Expand Down Expand Up @@ -32,10 +31,6 @@ trait Configuration

protected bool $formActionsAreSticky = false;

protected Closure | bool $showNavigationBadges = true;

protected array $showNavigationBadgesArray = [];

public function customSchema(array $schema): static
{
$this->customSchema = $schema;
Expand Down Expand Up @@ -120,39 +115,4 @@ public function getHiddenResources(): ?array
{
return $this->hideResources;
}

public function hideNavigationBadges(Closure | bool $show = false, ?Resources $resource = null): static
{
return $this->setShowNavigationBadges($show, $resource);
}

public function showNavigationBadges(Closure | bool $show = true, ?Resources $resource = null): static
{
return $this->setShowNavigationBadges($show, $resource);
}

private function setShowNavigationBadges(Closure | bool $show = true, ?Resources $resource = null): static
{
if ($resource !== null) {
$this->showNavigationBadgesArray[$resource->value] = $show;
} else {
$this->showNavigationBadges = $show;
}

return $this;
}

public function getShowNavigationBadges(?Resources $resource = null): bool
{
if ($resource !== null) {
return $this->showNavigationBadgesArray[$resource->value] ?? $this->evaluate($this->showNavigationBadges);
}

return $this->evaluate($this->showNavigationBadges);
}

public static function getNavigationBadgesVisibility(?Resources $resource = null): bool
{
return (new static)::get()->getShowNavigationBadges($resource);
}
}
12 changes: 0 additions & 12 deletions src/Enums/Resources.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Fields/Classes/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function ExportColumn(Field $field): ?ExportColumn
return ExportColumn::make('zeusData.' . $field->options['htmlId'])
->label($field->name)
->state(function (Response $record) use ($field) {

/** @var ?Response $response */
$response = $record->fieldsResponses()->where('field_id', $field->id)->first();
$response = (int) $response->response;

Expand Down
1 change: 1 addition & 0 deletions src/Fields/FieldsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public function ExportColumn(Field $field): ?ExportColumn
->label($field->name)
->state(function (Response $record) use ($field) {

/** @var ?Response $response */
$response = $record->fieldsResponses()->where('field_id', $field->id)->first();

if ($response === null) {
Expand Down
3 changes: 1 addition & 2 deletions src/Filament/Resources/CategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Str;
use LaraZeus\Bolt\BoltPlugin;
use LaraZeus\Bolt\Enums\Resources;
use LaraZeus\Bolt\Filament\Resources\CategoryResource\Pages\CreateCategory;
use LaraZeus\Bolt\Filament\Resources\CategoryResource\Pages\EditCategory;
use LaraZeus\Bolt\Filament\Resources\CategoryResource\Pages\ListCategories;
Expand All @@ -48,7 +47,7 @@ public static function getModel(): string

public static function getNavigationBadge(): ?string
{
if (! BoltPlugin::getNavigationBadgesVisibility(Resources::CategoryResource)) {
if (! BoltPlugin::getNavigationBadgesVisibility(self::class)) {
return null;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Filament/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use LaraZeus\Bolt\BoltPlugin;
use LaraZeus\Bolt\Enums\Resources;
use LaraZeus\Bolt\Filament\Resources\CollectionResource\Pages;
use LaraZeus\Bolt\Filament\Resources\CollectionResource\Widgets\EditCollectionWarning;

Expand All @@ -33,7 +32,7 @@ public static function getModel(): string

public static function getNavigationBadge(): ?string
{
if (! BoltPlugin::getNavigationBadgesVisibility(Resources::CollectionResource)) {
if (! BoltPlugin::getNavigationBadgesVisibility(self::class)) {
return null;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Filament/Resources/FormResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use LaraZeus\Bolt\BoltPlugin;
use LaraZeus\Bolt\Concerns\HasOptions;
use LaraZeus\Bolt\Concerns\Schemata;
use LaraZeus\Bolt\Enums\Resources;
use LaraZeus\Bolt\Facades\Bolt;
use LaraZeus\Bolt\Filament\Actions\ReplicateFormAction;
use LaraZeus\Bolt\Filament\Resources\FormResource\Pages;
Expand Down Expand Up @@ -60,7 +59,7 @@ public static function getModel(): string

public static function getNavigationBadge(): ?string
{
if (! BoltPlugin::getNavigationBadgesVisibility(Resources::FormResource)) {
if (! BoltPlugin::getNavigationBadgesVisibility(self::class)) {
return null;
}

Expand Down
1 change: 1 addition & 0 deletions src/Models/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected static function booted(): void
{
static::deleting(function (Field $field) {
if ($field->isForceDeleting()) {
// @phpstan-ignore-next-line
$field->fieldResponses()->withTrashed()->get()->each(function ($item) {
$item->forceDelete();
});
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ protected static function booted(): void
}

if ($form->isForceDeleting()) {
// @phpstan-ignore-next-line
$form->fieldsResponses()->withTrashed()->get()->each(fn ($item) => $item->forceDelete());
// @phpstan-ignore-next-line
$form->responses()->withTrashed()->get()->each(fn ($item) => $item->forceDelete());
// @phpstan-ignore-next-line
$form->sections()->withTrashed()->get()->each(function ($item) {
$item->fields()->withTrashed()->get()->each(fn ($item) => $item->forceDelete());
$item->forceDelete();
Expand Down
1 change: 1 addition & 0 deletions src/Models/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected static function booted(): void
}

if ($response->isForceDeleting()) {
// @phpstan-ignore-next-line
$response->fieldsResponses()->withTrashed()->get()->each(fn ($item) => $item->forceDelete());
} else {
$response->fieldsResponses->each(fn ($item) => $item->delete());
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Section extends Model
'options' => 'array',
];

public function getTable()
public function getTable(): string
{
return config('zeus-bolt.table-prefix') . 'sections';
}
Expand All @@ -43,6 +43,7 @@ protected static function booted(): void
{
static::deleting(function (Section $section) {
if ($section->isForceDeleting()) {
// @phpstan-ignore-next-line
$section->fields()->withTrashed()->get()->each(function ($item) {
$item->fieldResponses()->withTrashed()->get()->each(function ($item) {
$item->forceDelete();
Expand Down

0 comments on commit a1d5727

Please sign in to comment.