diff --git a/src/DashboardNova.php b/src/DashboardNova.php index 98b357a..2a0182a 100644 --- a/src/DashboardNova.php +++ b/src/DashboardNova.php @@ -55,6 +55,15 @@ public static function dashboardsIn($directory) ); } + public static function cardsInDashboards($directory) + { + $dashboards = static::$dashboards; + + foreach ($dashboards as $dashboard) { + DashboardNova::cards($dashboard->cards()); + } + } + /** * Register the given dashboards. * diff --git a/src/Http/Requests/DashboardCardRequest.php b/src/Http/Requests/DashboardCardRequest.php index f6cd55f..0047be5 100644 --- a/src/Http/Requests/DashboardCardRequest.php +++ b/src/Http/Requests/DashboardCardRequest.php @@ -4,6 +4,7 @@ use AlexBowers\MultipleDashboard\DashboardNova; use Laravel\Nova\Http\Requests\NovaRequest; +use App\Providers\NovaServiceProvider; class DashboardCardRequest extends NovaRequest { @@ -15,7 +16,16 @@ class DashboardCardRequest extends NovaRequest public function availableCards($dashboard) { if ($dashboard == 'main') { - return DashboardNova::availableDashboardCards($this); + /** + * This is a huge hack, and will not work for anybody not using + * the `App` default namespace. + */ + return (new class(app()) extends NovaServiceProvider { + public function getAroundProtectedMethod() + { + return $this->cards(); + } + })->getAroundProtectedMethod(); } return DashboardNova::availableDashboardCardsForDashboard($dashboard, $this); diff --git a/src/Http/Requests/DashboardMetricRequest.php b/src/Http/Requests/DashboardMetricRequest.php index eeb9111..4ae40ef 100644 --- a/src/Http/Requests/DashboardMetricRequest.php +++ b/src/Http/Requests/DashboardMetricRequest.php @@ -5,6 +5,7 @@ use Laravel\Nova\Nova; use Laravel\Nova\Metrics\Metric; use Laravel\Nova\Http\Requests\DashboardMetricRequest as CoreDashboardMetricRequest; +use AlexBowers\MultipleDashboard\DashboardNova; class DashboardMetricRequest extends CoreDashboardMetricRequest { @@ -27,6 +28,6 @@ public function metric() */ public function availableMetrics() { - return Nova::availableDashboardCards($this)->whereInstanceOf(Metric::class); + return DashboardNova::allAvailableDashboardCards($this)->whereInstanceOf(Metric::class); } } diff --git a/src/Tool.php b/src/Tool.php index 15dd93e..5f2ed3c 100644 --- a/src/Tool.php +++ b/src/Tool.php @@ -7,24 +7,5 @@ class Tool extends BaseTool { - /** - * Perform any tasks that need to happen when the tool is booted. - * - * @return void - */ - public function boot() - { - Nova::script('nova-multiple-dashboard', __DIR__.'/../dist/js/tool.js'); - Nova::style('nova-multiple-dashboard', __DIR__.'/../dist/css/tool.css'); - } - - /** - * Build the view that renders the navigation links for the tool. - * - * @return \Illuminate\View\View - */ - public function renderNavigation() - { - return view('nova-multiple-dashboard::navigation'); - } + // } diff --git a/src/ToolServiceProvider.php b/src/ToolServiceProvider.php index 584e42f..2076bae 100644 --- a/src/ToolServiceProvider.php +++ b/src/ToolServiceProvider.php @@ -32,6 +32,7 @@ public function boot() Nova::serving(function (ServingNova $event) { DashboardNova::dashboardsIn(app_path('Nova')); + DashboardNova::cardsInDashboards(app_path('Nova')); Nova::script('nova-multiple-dashboard', __DIR__ . '/../dist/js/tool.js'); }); } @@ -50,6 +51,10 @@ protected function routes() Route::middleware(['nova', Authorize::class]) ->prefix('nova-vendor/AlexBowers/nova-multiple-dashboard') ->group(__DIR__.'/../routes/api.php'); + + Route::get('/nova', function () { + return redirect('/nova/dashboards/main'); + }); } /**