Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Add navigationIcon, navigationSort and NavigationGroup to plugin
Add defaultGrid function to plugin
  • Loading branch information
invaders-xx committed May 14, 2024
1 parent 95f985a commit 0ec5d75
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 6 deletions.
58 changes: 55 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
![invaders-xx-gridstack-dashboard](https://github.com/invaders-xx/filament-gridstack-dashboard/assets/604907/0dffac39-3daa-4788-99ec-abe85d126b4b)

# Create and manage filament Dashboards using gridstack js

<img width="1715" alt="image" src="https://github.com/invaders-xx/filament-gridstack-dashboard/assets/604907/cadb4346-d3fe-4749-ba6e-0e4eed2c9576">

<img width="1715" alt="image" src="https://github.com/invaders-xx/filament-gridstack-dashboard/assets/604907/f41809b0-3ef0-4dd9-a894-ff199050ca2d">
Expand All @@ -22,11 +23,11 @@ You can install the package via composer:
```bash
composer require invaders-xx/filament-gridstack-dashboard
```

```bash
php artisan filament:assets
```


> **Note: Add plugin Blade files to your custom theme `tailwind.config.js` for dark mode.**
>
> To set up your own custom theme, you can visit
Expand Down Expand Up @@ -81,7 +82,23 @@ public function panel(Panel $panel): Panel
}
```

you can configure the settings path (string in dotted format where to store in the settings)
You can configure the settings path (string in dotted format where to store in the settings)
By default the path is 'dashboard.layout'

```php
use InvadersXX\FilamentGridstackDashboard\GridstackDashboardPlugin;

public function panel(Panel $panel): Panel
{
return $panel
->plugins([
GridstackDashboardPlugin::make()
->settingsPath('dashboard.settings'),
])
}
```

You can configure the navigationIcon, the navigationGroup and the navigationSort
By default the path is 'dashboard.layout'

```php
Expand All @@ -91,7 +108,42 @@ public function panel(Panel $panel): Panel
{
return $panel
->plugins([
GridstackDashboardPlugin::make()->settingsPath('dashboard.settings'),
GridstackDashboardPlugin::make()
->navigationIcon('heroicon-o-chart-bar')
->navigationGroup('Admin')
->navigationSort(1),
])
}
```

You can configure a default grid using defaultGrid() function. This function has an array as parameter. This array
should have the following format:

```php
[
'widget' => AccountWidget::class, // Widget class
'x' => 0, // starting column on the grid
'y' => 0, // row on the grid
'w' => 12, // number of columns on the grid
]
```

```php
use InvadersXX\FilamentGridstackDashboard\GridstackDashboardPlugin;
use Filament\Widgets\AccountWidget;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
GridstackDashboardPlugin::make()
->defaultGrid([
[
'widget' => AccountWidget::class,
'x' => 0,
'y' => 0,
'w' => 12,
],
]),
])
}
```
Expand Down
20 changes: 18 additions & 2 deletions src/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Widgets\TableWidget;
use Filament\Widgets\Widget;
use Illuminate\Contracts\Support\Htmlable;
use InvadersXX\FilamentGridstackDashboard\GridstackDashboardPlugin;

class Dashboard extends BaseDashboard
Expand All @@ -17,7 +18,22 @@ class Dashboard extends BaseDashboard

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

public function getColumns(): int | array
public static function getNavigationGroup(): ?string
{
return GridstackDashboardPlugin::get()->getNavigationGroup() ?? parent::getNavigationGroup();
}

public static function getNavigationIcon(): string|Htmlable|null
{
return GridstackDashboardPlugin::get()->getNavigationIcon() ?? parent::getNavigationIcon();
}

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

public function getColumns(): int|array
{
return 12;
}
Expand Down Expand Up @@ -125,6 +141,6 @@ protected function getHeaderActions(): array

protected function getVisibleWidgetsForGrid(): array
{
return auth()->user()->settings()->get(static::getSettingsPath(), []);
return auth()->user()->settings()->get(static::getSettingsPath(), GridstackDashboardPlugin::get()->getDefaultGrid());
}
}
60 changes: 59 additions & 1 deletion src/GridstackDashboardPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@

namespace InvadersXX\FilamentGridstackDashboard;

use Closure;
use Filament\Contracts\Plugin;
use Filament\Panel;
use Filament\Support\Concerns\EvaluatesClosures;
use Illuminate\Contracts\Support\Htmlable;
use InvadersXX\FilamentGridstackDashboard\Filament\Pages\Dashboard;

class GridstackDashboardPlugin implements Plugin
{
use EvaluatesClosures;

protected string|Closure|null $navigationGroup = null;

protected string|Closure|null $navigationIcon = null;

protected string $settingsPath = 'dashboard.layout';

protected array|Closure $defaultGrid = [];

protected int|Closure|null $navigationSort = -200;

public static function make(): static
{
return app(static::class);
Expand All @@ -39,18 +49,66 @@ public function register(Panel $panel): void
]);
}

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

return $this;
}

public function defaultGrid(array|Closure $grid): static
{
$this->defaultGrid = $grid;

return $this;
}

public function navigationSort(int|Closure $navigationSort): static
{
$this->navigationSort = $navigationSort;

return $this;
}

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

return $this;
}

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

return $this;
}

public function getSettingsPath(): string
{
return $this->evaluate($this->settingsPath);
}

public function getDefaultGrid(): array
{
return $this->evaluate($this->defaultGrid);
}

public function getNavigationSort(): int
{
return $this->evaluate($this->navigationSort);
}

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

public function getNavigationIcon(): string|Htmlable|null
{
return $this->evaluate($this->navigationIcon);
}

public function boot(Panel $panel): void
{
}
Expand Down

0 comments on commit 0ec5d75

Please sign in to comment.