Skip to content

Commit

Permalink
Merge pull request #4 from invaders-xx/add-more-plugin-options
Browse files Browse the repository at this point in the history
Add more plugin options
  • Loading branch information
invaders-xx authored May 30, 2024
2 parents 1600415 + 11e97db commit 0dd7791
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ php artisan vendor:publish --tag="filament-gridstack-dashboard-views"

## Usage

All functions used to configure the plugin can have a closure as argument.

```php
use InvadersXX\FilamentGridstackDashboard\GridstackDashboardPlugin;

Expand Down Expand Up @@ -189,7 +191,8 @@ public function panel(Panel $panel): Panel
}
```

You can configure the navigationIcon, the navigationGroup and the navigationSort
You can configure the navigationIcon, the navigationGroup, the navigationLabel, the navigationSort, canAccess and
shouldRegisterNavigation

```php
use InvadersXX\FilamentGridstackDashboard\GridstackDashboardPlugin;
Expand All @@ -201,6 +204,9 @@ public function panel(Panel $panel): Panel
GridstackDashboardPlugin::make()
->navigationIcon('heroicon-o-chart-bar')
->navigationGroup('Admin')
->shouldRegisterNavigation(false)
->canAccess(fn() => auth()->id()===1)
->navigationLabel('Dashboard')
->navigationSort(1),
])
}
Expand Down
15 changes: 15 additions & 0 deletions src/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ class Dashboard extends BaseDashboard

protected static string $view = 'filament-gridstack-dashboard::pages.dashboard';

public static function canAccess(): bool
{
return GridstackDashboardPlugin::get()->getCanAccess() ?? parent::canAccess();
}

public static function getNavigationLabel(): string
{
return GridstackDashboardPlugin::get()->getNavigationLabel() ?? parent::getNavigationLabel();
}

public static function shouldRegisterNavigation(): bool
{
return GridstackDashboardPlugin::get()->getShouldRegisterNavigation() ?? parent::$shouldRegisterNavigation;
}

public static function getNavigationGroup(): ?string
{
return GridstackDashboardPlugin::get()->getNavigationGroup() ?? parent::getNavigationGroup();
Expand Down
42 changes: 42 additions & 0 deletions src/GridstackDashboardPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ class GridstackDashboardPlugin implements Plugin

protected bool|Closure $disableResize = false;

protected bool|Closure $canAccess = true;

protected bool|Closure $shouldRegisterNavigation = true;

protected string|Closure $resizable = 'se';

protected string|Closure|null $navigationLabel = null;

public static function make(): static
{
return app(static::class);
Expand Down Expand Up @@ -117,6 +123,27 @@ public function resizable(string|Closure $resizable): static
return $this;
}

public function canAccess(bool|Closure $canAccess = true): static
{
$this->canAccess = $canAccess;

return $this;
}

public function shouldRegisterNavigation(bool|Closure $shouldRegisterNavigation = true): static
{
$this->shouldRegisterNavigation = $shouldRegisterNavigation;

return $this;
}

public function navigationLabel(string|Closure $navigationLabel): static
{
$this->navigationLabel = $navigationLabel;

return $this;
}

public function navigationSort(int|Closure $navigationSort): static
{
$this->navigationSort = $navigationSort;
Expand Down Expand Up @@ -148,6 +175,11 @@ public function getDefaultGrid(): array
return $this->evaluate($this->defaultGrid);
}

public function getNavigationLabel(): ?string
{
return $this->evaluate($this->navigationLabel);
}

public function getNavigationSort(): int
{
return $this->evaluate($this->navigationSort);
Expand Down Expand Up @@ -188,6 +220,16 @@ public function getDisableDrag(): ?bool
return $this->evaluate($this->disableDrag);
}

public function getCanAccess(): ?bool
{
return $this->evaluate($this->canAccess);
}

public function getShouldRegisterNavigation(): ?bool
{
return $this->evaluate($this->shouldRegisterNavigation);
}

public function getDisableResize(): ?bool
{
return $this->evaluate($this->disableResize);
Expand Down

0 comments on commit 0dd7791

Please sign in to comment.