From a0b0cc59b9a0b57c375eb031b610f2916fed7c43 Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Tue, 30 Jul 2024 07:53:16 +0300 Subject: [PATCH] new config --- src/Configuration.php | 140 ++++++++++-------------------------------- 1 file changed, 31 insertions(+), 109 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index a123f13b..5dd4f7f6 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -3,14 +3,36 @@ namespace LaraZeus\Bolt; use Closure; -use LaraZeus\Bolt\Enums\Resources; +use Filament\Support\Concerns\EvaluatesClosures; +use LaraZeus\Bolt\Filament\Resources\CategoryResource; +use LaraZeus\Bolt\Filament\Resources\CollectionResource; +use LaraZeus\Bolt\Filament\Resources\FormResource; +use LaraZeus\Core\Concerns\CanGloballySearch; +use LaraZeus\Core\Concerns\CanStickyActions; +use LaraZeus\Core\Concerns\HasModels; +use LaraZeus\Core\Concerns\HasNavigationGroupLabel; +use LaraZeus\Core\Concerns\CanHideResources; +use LaraZeus\Core\Concerns\HasNavigationBadges; +use LaraZeus\Core\Concerns\HasUploads; trait Configuration { - /** - * you can overwrite any model and use your own - */ - protected array $boltModels = []; + use CanGloballySearch; + use EvaluatesClosures; + use HasModels; + use HasNavigationGroupLabel; + use CanHideResources; + use CanStickyActions; + use HasNavigationBadges; + use HasUploads; + + public array $defaultGloballySearchableAttributes = [ + CategoryResource::class => ['name', 'slug'], + CollectionResource::class => ['name', 'values'], + FormResource::class => ['name', 'slug'], + ]; + + protected Closure | string $navigationGroupLabel = 'Bolt'; protected array $customSchema = [ 'form' => null, @@ -18,28 +40,19 @@ trait Configuration 'field' => null, ]; - protected array $hideResources = []; - /** * available extensions, leave it null to disable the extensions tab from the forms */ protected ?array $extensions = null; - /** - * the resources navigation group - */ - protected Closure | string $navigationGroupLabel = 'Bolt'; - - protected bool $formActionsAreSticky = false; - - protected Closure | bool $showNavigationBadges = true; - - protected array $showNavigationBadgesArray = []; + public static function getDefaultModelsToMerge():array + { + return config('zeus-bolt.models'); + } public function customSchema(array $schema): static { $this->customSchema = $schema; - return $this; } @@ -53,50 +66,6 @@ public static function getSchema(string $type): ?string return (new static())::get()->getCustomSchema()[$type]; } - public function boltModels(array $models): static - { - $this->boltModels = $models; - - return $this; - } - - public function getBoltModels(): array - { - return $this->boltModels; - } - - public static function getModel(string $model): string - { - return array_merge( - config('zeus-bolt.models'), - (new static())::get()->getBoltModels() - )[$model]; - } - - public function navigationGroupLabel(Closure | string $label): static - { - $this->navigationGroupLabel = $label; - - return $this; - } - - public function getNavigationGroupLabel(): Closure | string - { - return $this->evaluate($this->navigationGroupLabel); - } - - public function formActionsAreSticky(bool $condition = false): static - { - $this->formActionsAreSticky = $condition; - - return $this; - } - - public function isFormActionsAreSticky(): bool - { - return $this->evaluate($this->formActionsAreSticky); - } - public function extensions(?array $extensions): static { $this->extensions = $extensions; @@ -108,51 +77,4 @@ public function getExtensions(): ?array { return $this->extensions; } - - public function hideResources(array $resources): static - { - $this->hideResources = $resources; - - return $this; - } - - 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); - } }