Skip to content

Commit

Permalink
Add configuration options for navigation badges
Browse files Browse the repository at this point in the history
  • Loading branch information
Edsardio committed Jan 13, 2024
1 parent e829e86 commit e7ce27e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
36 changes: 36 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LaraZeus\Bolt;

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

trait Configuration
{
Expand Down Expand Up @@ -232,4 +233,39 @@ 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 (!is_null($resource)) {
$this->showNavigationBadgesArray[$resource->value] = $show;
} else {
$this->showNavigationBadges = $show;
}

return $this;
}

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

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

public static function getShowOrHideNavigationBadges(?Resources $resource = null): bool
{
return (new static())::get()->getShowNavigationBadges($resource);
}
}
10 changes: 10 additions & 0 deletions src/Enums/Resources.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace LaraZeus\Bolt\Enums;

enum Resources: string
{
case CategoryResource = 'CategoryResource';
case CollectionResource = 'CollectionResource';
case FormResource = 'FormResource';
}
7 changes: 6 additions & 1 deletion src/Filament/Resources/CategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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 @@ -47,7 +48,11 @@ public static function getModel(): string

public static function getNavigationBadge(): ?string
{
return (string) BoltPlugin::getModel('Category')::query()->count();
if (!BoltPlugin::getShowOrHideNavigationBadges(Resources::CategoryResource)) {
return null;
}

return (string)BoltPlugin::getModel('Category')::query()->count();
}

public static function getGloballySearchableAttributes(): array
Expand Down
7 changes: 6 additions & 1 deletion src/Filament/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 @@ -32,7 +33,11 @@ public static function getModel(): string

public static function getNavigationBadge(): ?string
{
return (string) BoltPlugin::getModel('Collection')::query()->count();
if (!BoltPlugin::getShowOrHideNavigationBadges(Resources::CollectionResource)) {
return null;
}

return (string)BoltPlugin::getModel('Collection')::query()->count();
}

public static function getGloballySearchableAttributes(): array
Expand Down
7 changes: 6 additions & 1 deletion src/Filament/Resources/FormResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use LaraZeus\Bolt\BoltPlugin;
use LaraZeus\Bolt\Concerns\HasOptions;
use LaraZeus\Bolt\Concerns\Schemata;
use LaraZeus\Bolt\Enums\Resources;
use LaraZeus\Bolt\Filament\Actions\ReplicateFormAction;
use LaraZeus\Bolt\Filament\Resources\FormResource\Pages;
use LaraZeus\Bolt\Models\Form as ZeusForm;
Expand All @@ -57,7 +58,11 @@ public static function getModel(): string

public static function getNavigationBadge(): ?string
{
return (string) BoltPlugin::getModel('Form')::query()->count();
if (!BoltPlugin::getShowOrHideNavigationBadges(Resources::FormResource)) {
return null;
}

return (string)BoltPlugin::getModel('Form')::query()->count();
}

public static function getGloballySearchableAttributes(): array
Expand Down

0 comments on commit e7ce27e

Please sign in to comment.