Skip to content

Commit

Permalink
Merge pull request #457 from abbasmashaddy72/3.x
Browse files Browse the repository at this point in the history
Added Option to Set default layout from Config
  • Loading branch information
awcodes authored Mar 22, 2024
2 parents 09bdf6f + a0a8b7b commit c92b343
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function panel(Panel $panel): Panel
->navigationSort(3)
->navigationCountBadge()
->registerNavigation(false)
->defaultView('grid' || 'list')
->resource(\App\Filament\Resources\CustomMediaResource::class)
]);
}
Expand Down
3 changes: 3 additions & 0 deletions config/curator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@
'display_upload_new' => true,
],
'multi_select_key' => 'metaKey',
'table' => [
'layout' => 'grid',
]
];
16 changes: 15 additions & 1 deletion src/CuratorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CuratorPlugin implements Plugin

protected ?bool $shouldRegisterNavigation = null;

protected ?string $getDefaultListView = null;

protected string | Closure | null $pluralLabel = null;

protected ?string $resource = null;
Expand All @@ -40,7 +42,7 @@ public function register(Panel $panel): void
$this->getResource(),
]);

if (! is_panel_auth_route()) {
if (!is_panel_auth_route()) {
$panel
->renderHook(
'panels::body.end',
Expand Down Expand Up @@ -103,6 +105,11 @@ public function shouldRegisterNavigation(): ?bool
return $this->shouldRegisterNavigation ?? config('curator.should_register_navigation');
}

public function getDefaultListView(): ?string
{
return $this->getDefaultListView ?? config('curator.table.layout');
}

public function navigationGroup(string | Closure | null $group = null): static
{
$this->navigationGroup = $group;
Expand Down Expand Up @@ -138,6 +145,13 @@ public function registerNavigation(bool $show = true): static
return $this;
}

public function defaultView(string $view): static
{
$this->getDefaultListView = $view;

return $this;
}

public function pluralLabel(string | Closure $label): static
{
$this->pluralLabel = $label;
Expand Down
7 changes: 6 additions & 1 deletion src/Resources/MediaResource/ListMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

class ListMedia extends ListRecords
{
public string $layoutView = 'grid';
public string $layoutView;

public function boot()
{
$this->layoutView = CuratorPlugin::get()->getDefaultListView();
}

protected $listeners = [
'changeLayoutView' => 'changeLayoutView',
Expand Down

0 comments on commit c92b343

Please sign in to comment.