Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Works for main dashboard too
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbowers committed Sep 4, 2018
1 parent 9f57905 commit 20c5970
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
9 changes: 9 additions & 0 deletions src/DashboardNova.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 11 additions & 1 deletion src/Http/Requests/DashboardCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AlexBowers\MultipleDashboard\DashboardNova;
use Laravel\Nova\Http\Requests\NovaRequest;
use App\Providers\NovaServiceProvider;

class DashboardCardRequest extends NovaRequest
{
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Requests/DashboardMetricRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -27,6 +28,6 @@ public function metric()
*/
public function availableMetrics()
{
return Nova::availableDashboardCards($this)->whereInstanceOf(Metric::class);
return DashboardNova::allAvailableDashboardCards($this)->whereInstanceOf(Metric::class);
}
}
21 changes: 1 addition & 20 deletions src/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
//
}
5 changes: 5 additions & 0 deletions src/ToolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
Expand All @@ -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');
});
}

/**
Expand Down

0 comments on commit 20c5970

Please sign in to comment.