modules/dashboard/README.md
The Dashboard module provides customizable admin dashboards with report widgets, data visualizations, traffic analytics, and system health indicators. Dashboards can be assigned to roles and personalized per user. The module includes a data source abstraction that separates data retrieval from presentation, so plugins can expose their own metrics and have them rendered as charts, tables, or indicators without building any frontend UI.
The dashboard system is built around three concepts:
| Service | Class | Description |
|---|---|---|
DashManager | Dashboard\Classes\DashManager | Central registry for data sources and widgets |
| Controller | Route | Description |
|---|---|---|
Index | /dashboard | Displays the user's active dashboard |
Dashboards | /dashboard/dashboards | CRUD for dashboard definitions |
DashboardSettings | /dashboard/dashboardsettings | Traffic statistics configuration |
When a user visits the dashboard, the system resolves which dashboard to show:
Users can personalize their dashboard layout without affecting the original definition.
Data sources extend Dashboard\Classes\ReportDataSourceBase and define available dimensions and metrics. Plugins only need to declare what data they can provide -- the dashboard handles all chart rendering, date grouping, comparison, and layout:
<?php namespace Acme\Analytics\Classes;
use Dashboard\Classes\ReportDataSourceBase;
class SalesDataSource extends ReportDataSourceBase
{
public function registerDimensions(): array
{
return [
'date' => ['title' => 'Date', 'type' => 'date'],
'product' => ['title' => 'Product', 'type' => 'string'],
];
}
public function registerMetrics(): array
{
return [
'revenue' => ['title' => 'Revenue', 'type' => 'currency'],
'orders' => ['title' => 'Orders', 'type' => 'number'],
];
}
public function fetchData(ReportFetchData $fetchData): ReportFetchDataResult
{
// Query database and return results
}
}
| Data Source | Description |
|---|---|
SystemReportDataSource | System health, versions, warnings, permissions |
CmsReportDataSource | Website traffic (page views, unique visitors, grouped by date/path/referrer) |
CmsStatusDataSource | Website status (online/maintenance mode indicator) |
use Dashboard\Classes\DashManager;
public function boot()
{
DashManager::instance()->registerDataSourceClass(
'sales',
\Acme\Analytics\Classes\SalesDataSource::class
);
}
Report widgets extend Dashboard\Classes\VueReportWidgetBase and render data from data sources.
In your plugin's Plugin.php:
public function registerReportWidgets()
{
return [
\Acme\Analytics\Widgets\SalesChart::class => [
'label' => 'Sales Chart',
'context' => 'dashboard',
],
];
}
Any backend controller can embed a dashboard by implementing the DashController behavior:
class MyController extends \Backend\Classes\Controller
{
public $implement = [
\Dashboard\Behaviors\DashController::class,
];
public $dashConfig = 'config_dash.yaml';
}
| Event | Description |
|---|---|
backend.dash.extendReportsBefore | Before reports are loaded |
backend.dash.extendReports | Add or remove reports from a dashboard |
Event::listen('backend.dash.extendReports', function ($dashWidget) {
$dashWidget->addReports([/* ... */]);
$dashWidget->removeReport('some-report-id');
});
The TrafficLogger class records page views from the CMS frontend. Statistics are stored in the dashboard_traffic_stats_pageviews table and queried by CmsReportDataSource for traffic analytics widgets.
| Table | Description |
|---|---|
dashboard_dashboards | Dashboard definitions and configuration |
dashboard_dashboards_roles | Role assignments for dashboards |
dashboard_traffic_stats_pageviews | Page view tracking data |
dashboard_report_data_caches | Query result caching |
| Permission | Description |
|---|---|
dashboard | Access the dashboard |
dashboard.manage | Create and edit dashboards |
dashboard.internal_traffic_statistics | Configure traffic statistics settings |