Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 087d659

Browse files
committed
Use improved dashboard widget api to register chart widget as a datasets...
Signed-off-by: Sam <6567634+sampoyigi@users.noreply.github.com>
1 parent 935b731 commit 087d659

File tree

15 files changed

+541
-1003
lines changed

15 files changed

+541
-1003
lines changed

Extension.php

Lines changed: 131 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,132 @@
11
<?php namespace Thoughtco\Reports;
22

3-
use DB;
4-
use Event;
5-
use Admin\Widgets\Form;
3+
use Admin\Controllers\Dashboard;
4+
use Admin\DashboardWidgets\Charts;
5+
use Admin\DashboardWidgets\Statistics;
6+
use Admin\Widgets\DashboardContainer;
67
use System\Classes\BaseExtension;
8+
use Thoughtco\Reports\Classes\ReportsCache;
79

810
/**
911
* Extension Information File
10-
**/
12+
**/
1113
class Extension extends BaseExtension
1214
{
1315
public function boot()
1416
{
15-
17+
Statistics::registerCards(function () {
18+
return [
19+
'total_items' => [
20+
'label' => 'lang:thoughtco.reports::default.text_total_items',
21+
'icon' => ' bg-warning text-white fa fa-line-chart',
22+
'valueFrom' => [ReportsCache::class, 'getValue'],
23+
],
24+
'pickup_orders_value' => [
25+
'label' => 'lang:thoughtco.reports::default.text_collection_orders',
26+
'icon' => ' bg-blue text-white fa fa-store',
27+
'valueFrom' => [ReportsCache::class, 'getValue'],
28+
],
29+
'pickup_orders_count' => [
30+
'label' => 'lang:thoughtco.reports::default.text_collection_orders_count',
31+
'icon' => ' bg-blue text-white fa fa-store',
32+
'valueFrom' => [ReportsCache::class, 'getValue'],
33+
],
34+
'delivery_orders_value' => [
35+
'label' => 'lang:thoughtco.reports::default.text_delivery_orders',
36+
'icon' => ' bg-blue text-white fa fa-shipping-fast',
37+
'valueFrom' => [ReportsCache::class, 'getValue'],
38+
],
39+
'delivery_orders_count' => [
40+
'label' => 'lang:thoughtco.reports::default.text_delivery_orders_count',
41+
'icon' => ' bg-blue text-white fa fa-shipping-fast',
42+
'valueFrom' => [ReportsCache::class, 'getValue'],
43+
],
44+
'cancelled_orders_value' => [
45+
'label' => 'lang:thoughtco.reports::default.text_cancelled_orders',
46+
'icon' => ' bg-danger text-white fa fa-exclamation-circle',
47+
'valueFrom' => [ReportsCache::class, 'getValue'],
48+
],
49+
'cancelled_orders_count' => [
50+
'label' => 'lang:thoughtco.reports::default.text_cancelled_orders_count',
51+
'icon' => ' bg-danger text-white fa fa-exclamation-circle',
52+
'valueFrom' => [ReportsCache::class, 'getValue'],
53+
],
54+
];
55+
});
56+
57+
Charts::registerDatasets(function () {
58+
return [
59+
'orders_by_day_data' => [
60+
'label' => 'lang:thoughtco.reports::default.text_orders_by_day',
61+
'type' => 'doughnut',
62+
'icon' => ' fa fa-calendar',
63+
'datasetFrom' => [ReportsCache::class, 'getValue'],
64+
],
65+
'orders_by_hour_data' => [
66+
'label' => 'lang:thoughtco.reports::default.text_orders_by_hour',
67+
'type' => 'doughnut',
68+
'icon' => ' fa fa-clock',
69+
'datasetFrom' => [ReportsCache::class, 'getValue'],
70+
],
71+
'orders_by_category_data' => [
72+
'label' => 'lang:thoughtco.reports::default.text_orders_by_category',
73+
'type' => 'pie',
74+
'icon' => ' fa fa-stream',
75+
'datasetFrom' => [ReportsCache::class, 'getValue'],
76+
],
77+
'orders_by_payment_method_data' => [
78+
'label' => 'lang:thoughtco.reports::default.text_orders_by_payment_type',
79+
'type' => 'pie',
80+
'icon' => ' fa fa-money-check-alt',
81+
'datasetFrom' => [ReportsCache::class, 'getValue'],
82+
],
83+
];
84+
});
85+
86+
Dashboard::extend(function (Dashboard $dashboard) {
87+
$dashboard->extendDashboard(function (DashboardContainer $widget) {
88+
$widget->defaultWidgets = array_merge($widget->defaultWidgets, [
89+
'top_customers' => [
90+
'widget' => 'lists',
91+
'priority' => 40,
92+
'context' => 'top_customers',
93+
'width' => '6',
94+
],
95+
'bottom_customers' => [
96+
'widget' => 'lists',
97+
'priority' => 40,
98+
'context' => 'bottom_customers',
99+
'width' => '6',
100+
],
101+
'orders_by_day' => [
102+
'widget' => 'charts',
103+
'priority' => 50,
104+
'dataset' => 'orders_by_day_data',
105+
'width' => '3',
106+
],
107+
'orders_by_hour' => [
108+
'widget' => 'charts',
109+
'priority' => 50,
110+
'dataset' => 'orders_by_hour_data',
111+
'width' => '3',
112+
],
113+
'orders_by_category' => [
114+
'widget' => 'charts',
115+
'priority' => 50,
116+
'dataset' => 'orders_by_category_data',
117+
'width' => '3',
118+
],
119+
'orders_by_payment_method' => [
120+
'widget' => 'charts',
121+
'priority' => 50,
122+
'dataset' => 'orders_by_payment_method_data',
123+
'width' => '3',
124+
],
125+
]);
126+
});
127+
});
16128
}
17-
129+
18130
public function registerFormWidgets()
19131
{
20132
return [
@@ -28,7 +140,17 @@ public function registerFormWidgets()
28140
],
29141
];
30142
}
31-
143+
144+
public function registerDashboardWidgets()
145+
{
146+
return [
147+
\Thoughtco\Reports\Widgets\Lists::class => [
148+
'code' => 'lists',
149+
'label' => 'lang:thoughtco.reports::default.text_list_widget_title',
150+
],
151+
];
152+
}
153+
32154
public function registerNavigation()
33155
{
34156
return [
@@ -54,8 +176,8 @@ public function registerNavigation()
54176
],
55177
],
56178
];
57-
}
58-
179+
}
180+
59181
public function registerPermissions()
60182
{
61183
return [

0 commit comments

Comments
 (0)