Skip to content

Commit

Permalink
Merge pull request #24 from sampoyigi/master
Browse files Browse the repository at this point in the history
Use improved dashboard widget api
  • Loading branch information
ryanmitchell authored Jun 29, 2023
2 parents 935b731 + 6020f7a commit 926ad66
Show file tree
Hide file tree
Showing 15 changed files with 545 additions and 1,019 deletions.
159 changes: 134 additions & 25 deletions Extension.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,132 @@
<?php namespace Thoughtco\Reports;

use DB;
use Event;
use Admin\Widgets\Form;
use Admin\Controllers\Dashboard;
use Admin\DashboardWidgets\Charts;
use Admin\DashboardWidgets\Statistics;
use Admin\Widgets\DashboardContainer;
use System\Classes\BaseExtension;
use Thoughtco\Reports\Classes\ReportsCache;

/**
* Extension Information File
**/
**/
class Extension extends BaseExtension
{
public function boot()
{

Statistics::registerCards(function () {
return [
'total_items' => [
'label' => 'lang:thoughtco.reports::default.text_total_items',
'icon' => ' bg-warning text-white fa fa-line-chart',
'valueFrom' => [ReportsCache::class, 'getValue'],
],
'pickup_orders_value' => [
'label' => 'lang:thoughtco.reports::default.text_collection_orders',
'icon' => ' bg-blue text-white fa fa-store',
'valueFrom' => [ReportsCache::class, 'getValue'],
],
'pickup_orders_count' => [
'label' => 'lang:thoughtco.reports::default.text_collection_orders_count',
'icon' => ' bg-blue text-white fa fa-store',
'valueFrom' => [ReportsCache::class, 'getValue'],
],
'delivery_orders_value' => [
'label' => 'lang:thoughtco.reports::default.text_delivery_orders',
'icon' => ' bg-blue text-white fa fa-shipping-fast',
'valueFrom' => [ReportsCache::class, 'getValue'],
],
'delivery_orders_count' => [
'label' => 'lang:thoughtco.reports::default.text_delivery_orders_count',
'icon' => ' bg-blue text-white fa fa-shipping-fast',
'valueFrom' => [ReportsCache::class, 'getValue'],
],
'cancelled_orders_value' => [
'label' => 'lang:thoughtco.reports::default.text_cancelled_orders',
'icon' => ' bg-danger text-white fa fa-exclamation-circle',
'valueFrom' => [ReportsCache::class, 'getValue'],
],
'cancelled_orders_count' => [
'label' => 'lang:thoughtco.reports::default.text_cancelled_orders_count',
'icon' => ' bg-danger text-white fa fa-exclamation-circle',
'valueFrom' => [ReportsCache::class, 'getValue'],
],
];
});

Charts::registerDatasets(function () {
return [
'orders_by_day_data' => [
'label' => 'lang:thoughtco.reports::default.text_orders_by_day',
'type' => 'doughnut',
'icon' => ' fa fa-calendar',
'datasetFrom' => [ReportsCache::class, 'getValue'],
],
'orders_by_hour_data' => [
'label' => 'lang:thoughtco.reports::default.text_orders_by_hour',
'type' => 'doughnut',
'icon' => ' fa fa-clock',
'datasetFrom' => [ReportsCache::class, 'getValue'],
],
'orders_by_category_data' => [
'label' => 'lang:thoughtco.reports::default.text_orders_by_category',
'type' => 'pie',
'icon' => ' fa fa-stream',
'datasetFrom' => [ReportsCache::class, 'getValue'],
],
'orders_by_payment_method_data' => [
'label' => 'lang:thoughtco.reports::default.text_orders_by_payment_type',
'type' => 'pie',
'icon' => ' fa fa-money-check-alt',
'datasetFrom' => [ReportsCache::class, 'getValue'],
],
];
});

Dashboard::extend(function (Dashboard $dashboard) {
$dashboard->extendDashboard(function (DashboardContainer $widget) {
$widget->defaultWidgets = array_merge($widget->defaultWidgets, [
'top_customers' => [
'widget' => 'lists',
'priority' => 40,
'context' => 'top_customers',
'width' => '6',
],
'bottom_customers' => [
'widget' => 'lists',
'priority' => 40,
'context' => 'bottom_customers',
'width' => '6',
],
'orders_by_day' => [
'widget' => 'charts',
'priority' => 50,
'dataset' => 'orders_by_day_data',
'width' => '3',
],
'orders_by_hour' => [
'widget' => 'charts',
'priority' => 50,
'dataset' => 'orders_by_hour_data',
'width' => '3',
],
'orders_by_category' => [
'widget' => 'charts',
'priority' => 50,
'dataset' => 'orders_by_category_data',
'width' => '3',
],
'orders_by_payment_method' => [
'widget' => 'charts',
'priority' => 50,
'dataset' => 'orders_by_payment_method_data',
'width' => '3',
],
]);
});
});
}

public function registerFormWidgets()
{
return [
Expand All @@ -28,34 +140,31 @@ public function registerFormWidgets()
],
];
}


public function registerDashboardWidgets()
{
return [
\Thoughtco\Reports\Widgets\Lists::class => [
'code' => 'lists',
'label' => 'lang:thoughtco.reports::default.text_list_widget_title',
],
];
}

public function registerNavigation()
{
return [
'reports' => [
'icon' => 'fa-chart-pie',
'title' => lang('lang:thoughtco.reports::default.text_title'),
'priority' => 35,
'child' => [
'dashboard' => [
'priority' => 5,
'class' => 'pages',
'href' => admin_url('thoughtco/reports/dashboard'),
'title' => lang('lang:thoughtco.reports::default.text_dashboard_title'),
'permission' => 'Thoughtco.Reports.View',
],
'builder' => [
'priority' => 5,
'class' => 'pages',
'href' => admin_url('thoughtco/reports/builder'),
'title' => lang('lang:thoughtco.reports::default.text_builder_title'),
'permission' => 'Thoughtco.Reports.View',
],
],
'class' => 'pages',
'href' => admin_url('thoughtco/reports/builder'),
'permission' => 'Thoughtco.Reports.View',
],
];
}
}

public function registerPermissions()
{
return [
Expand Down
Loading

0 comments on commit 926ad66

Please sign in to comment.