From 74347d41c25d3431a1ca43e62ed08bc083c9df08 Mon Sep 17 00:00:00 2001 From: Syed Kounain Abbas Rizvi Date: Tue, 12 Mar 2024 06:21:42 +0530 Subject: [PATCH 1/3] Added Option to Set default layout from Config --- config/curator.php | 3 +++ src/Resources/MediaResource/ListMedia.php | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config/curator.php b/config/curator.php index 2a16162d..4978343a 100644 --- a/config/curator.php +++ b/config/curator.php @@ -58,4 +58,7 @@ 'display_upload_new' => true, ], 'multi_select_key' => 'metaKey', + 'table' => [ + 'layout' => 'list', + ] ]; diff --git a/src/Resources/MediaResource/ListMedia.php b/src/Resources/MediaResource/ListMedia.php index 57f79b07..437cb439 100644 --- a/src/Resources/MediaResource/ListMedia.php +++ b/src/Resources/MediaResource/ListMedia.php @@ -12,7 +12,12 @@ class ListMedia extends ListRecords { - public string $layoutView = 'grid'; + public string $layoutView; + + public function boot() + { + $this->layoutView = config('curator.table.layout') ?? 'grid'; + } protected $listeners = [ 'changeLayoutView' => 'changeLayoutView', From 36c5b745f9ee22db814769f89883980a2df50be9 Mon Sep 17 00:00:00 2001 From: Syed Kounain Abbas Rizvi Date: Wed, 13 Mar 2024 11:31:23 +0530 Subject: [PATCH 2/3] Added Setting Default View from Plugin --- README.md | 1 + src/CuratorPlugin.php | 16 +++++++++++++++- src/Resources/MediaResource/ListMedia.php | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6f170429..2ecd58f9 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ public function panel(Panel $panel): Panel ->navigationSort(3) ->navigationCountBadge() ->registerNavigation(false) + ->defaultView('grid' || 'list') ->resource(\App\Filament\Resources\CustomMediaResource::class) ]); } diff --git a/src/CuratorPlugin.php b/src/CuratorPlugin.php index b41db143..f406e3ae 100644 --- a/src/CuratorPlugin.php +++ b/src/CuratorPlugin.php @@ -24,6 +24,8 @@ class CuratorPlugin implements Plugin protected ?bool $shouldRegisterNavigation = null; + protected ?string $defaultListView = null; + protected string | Closure | null $pluralLabel = null; protected ?string $resource = null; @@ -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', @@ -103,6 +105,11 @@ public function shouldRegisterNavigation(): ?bool return $this->shouldRegisterNavigation ?? config('curator.should_register_navigation'); } + public function defaultListView(): ?string + { + return $this->defaultListView ?? config('curator.table.layout'); + } + public function navigationGroup(string | Closure | null $group = null): static { $this->navigationGroup = $group; @@ -138,6 +145,13 @@ public function registerNavigation(bool $show = true): static return $this; } + public function defaultView(string $view): static + { + $this->defaultListView = $view; + + return $this; + } + public function pluralLabel(string | Closure $label): static { $this->pluralLabel = $label; diff --git a/src/Resources/MediaResource/ListMedia.php b/src/Resources/MediaResource/ListMedia.php index 437cb439..85aeec08 100644 --- a/src/Resources/MediaResource/ListMedia.php +++ b/src/Resources/MediaResource/ListMedia.php @@ -16,7 +16,7 @@ class ListMedia extends ListRecords public function boot() { - $this->layoutView = config('curator.table.layout') ?? 'grid'; + $this->layoutView = CuratorPlugin::get()->defaultListView(); } protected $listeners = [ From a0a8b7b7d2cd0b74e4ec4a407cb17aaead655c4d Mon Sep 17 00:00:00 2001 From: Syed Kounain Abbas Rizvi Date: Thu, 21 Mar 2024 01:29:17 +0530 Subject: [PATCH 3/3] Made Required Changes --- config/curator.php | 2 +- src/CuratorPlugin.php | 8 ++++---- src/Resources/MediaResource/ListMedia.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/curator.php b/config/curator.php index 4978343a..da996f6b 100644 --- a/config/curator.php +++ b/config/curator.php @@ -59,6 +59,6 @@ ], 'multi_select_key' => 'metaKey', 'table' => [ - 'layout' => 'list', + 'layout' => 'grid', ] ]; diff --git a/src/CuratorPlugin.php b/src/CuratorPlugin.php index f406e3ae..2cae1dc1 100644 --- a/src/CuratorPlugin.php +++ b/src/CuratorPlugin.php @@ -24,7 +24,7 @@ class CuratorPlugin implements Plugin protected ?bool $shouldRegisterNavigation = null; - protected ?string $defaultListView = null; + protected ?string $getDefaultListView = null; protected string | Closure | null $pluralLabel = null; @@ -105,9 +105,9 @@ public function shouldRegisterNavigation(): ?bool return $this->shouldRegisterNavigation ?? config('curator.should_register_navigation'); } - public function defaultListView(): ?string + public function getDefaultListView(): ?string { - return $this->defaultListView ?? config('curator.table.layout'); + return $this->getDefaultListView ?? config('curator.table.layout'); } public function navigationGroup(string | Closure | null $group = null): static @@ -147,7 +147,7 @@ public function registerNavigation(bool $show = true): static public function defaultView(string $view): static { - $this->defaultListView = $view; + $this->getDefaultListView = $view; return $this; } diff --git a/src/Resources/MediaResource/ListMedia.php b/src/Resources/MediaResource/ListMedia.php index 85aeec08..4cc2e968 100644 --- a/src/Resources/MediaResource/ListMedia.php +++ b/src/Resources/MediaResource/ListMedia.php @@ -16,7 +16,7 @@ class ListMedia extends ListRecords public function boot() { - $this->layoutView = CuratorPlugin::get()->defaultListView(); + $this->layoutView = CuratorPlugin::get()->getDefaultListView(); } protected $listeners = [