Skip to content

Commit d00b206

Browse files
committed
Improve dashboard charts - migrate to chart.js
1 parent 04b376d commit d00b206

File tree

43 files changed

+38199
-499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+38199
-499
lines changed

app/code/Magento/Backend/Block/Dashboard.php

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Backend\Block;
89

910
/**
11+
* Class used to initialize layout for MBO Dashboard
12+
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
13+
* @see dashboard in adminhtml_dashboard_index.xml
14+
*
1015
* @api
1116
* @since 100.0.2
1217
*/
13-
class Dashboard extends \Magento\Backend\Block\Template
18+
class Dashboard extends Template
1419
{
1520
/**
1621
* Location of the "Enable Chart" config param
@@ -23,42 +28,8 @@ class Dashboard extends \Magento\Backend\Block\Template
2328
protected $_template = 'Magento_Backend::dashboard/index.phtml';
2429

2530
/**
26-
* @return void
27-
*/
28-
protected function _prepareLayout()
29-
{
30-
$this->addChild('lastOrders', \Magento\Backend\Block\Dashboard\Orders\Grid::class);
31-
32-
$this->addChild('totals', \Magento\Backend\Block\Dashboard\Totals::class);
33-
34-
$this->addChild('sales', \Magento\Backend\Block\Dashboard\Sales::class);
35-
36-
$isChartEnabled = $this->_scopeConfig->getValue(
37-
self::XML_PATH_ENABLE_CHARTS,
38-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
39-
);
40-
if ($isChartEnabled) {
41-
$block = $this->getLayout()->createBlock(\Magento\Backend\Block\Dashboard\Diagrams::class);
42-
} else {
43-
$block = $this->getLayout()->createBlock(
44-
\Magento\Backend\Block\Template::class
45-
)->setTemplate(
46-
'dashboard/graph/disabled.phtml'
47-
)->setConfigUrl(
48-
$this->getUrl(
49-
'adminhtml/system_config/edit',
50-
['section' => 'admin', '_fragment' => 'admin_dashboard-link']
51-
)
52-
);
53-
}
54-
$this->setChild('diagrams', $block);
55-
56-
$this->addChild('grids', \Magento\Backend\Block\Dashboard\Grids::class);
57-
58-
parent::_prepareLayout();
59-
}
60-
61-
/**
31+
* Get url for switch action
32+
*
6233
* @return string
6334
*/
6435
public function getSwitchUrl()

app/code/Magento/Backend/Block/Dashboard/Diagrams.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* Adminhtml dashboard diagram tabs
10+
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
11+
* @see dashboard.diagrams in adminhtml_dashboard_index.xml
1012
*
1113
* @author Magento Core Team <core@magentocommerce.com>
1214
*/
@@ -18,6 +20,8 @@ class Diagrams extends \Magento\Backend\Block\Widget\Tabs
1820
protected $_template = 'Magento_Backend::widget/tabshoriz.phtml';
1921

2022
/**
23+
* Internal constructor, that is called from real constructor
24+
*
2125
* @return void
2226
*/
2327
protected function _construct()
@@ -28,6 +32,8 @@ protected function _construct()
2832
}
2933

3034
/**
35+
* Preparing global layout
36+
*
3137
* @return $this
3238
*/
3339
protected function _prepareLayout()

app/code/Magento/Backend/Block/Dashboard/Graph.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
/**
1111
* Adminhtml dashboard google chart block
12+
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
13+
* @see dashboard.chart.amounts and dashboard.chart.orders in adminhtml_dashboard_index.xml
1214
*
1315
* @author Magento Core Team <core@magentocommerce.com>
1416
*/

app/code/Magento/Backend/Block/Dashboard/Grids.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Backend\Block\Dashboard;
79

10+
use Magento\Backend\Block\Dashboard\Tab\Products\Ordered;
11+
use Magento\Backend\Block\Widget\Tabs;
12+
813
/**
914
* Adminhtml dashboard bottom tabs
1015
*
16+
* @api
1117
* @author Magento Core Team <core@magentocommerce.com>
1218
*/
13-
class Grids extends \Magento\Backend\Block\Widget\Tabs
19+
class Grids extends Tabs
1420
{
1521
/**
1622
* @var string
1723
*/
1824
protected $_template = 'Magento_Backend::widget/tabshoriz.phtml';
1925

2026
/**
27+
* Internal constructor, that is called from real constructor
28+
*
2129
* @return void
2230
*/
2331
protected function _construct()
@@ -49,7 +57,7 @@ protected function _prepareLayout()
4957
[
5058
'label' => __('Bestsellers'),
5159
'content' => $this->getLayout()->createBlock(
52-
\Magento\Backend\Block\Dashboard\Tab\Products\Ordered::class
60+
Ordered::class
5361
)->toHtml(),
5462
'active' => true
5563
]

app/code/Magento/Backend/Block/Dashboard/Orders/Grid.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,42 @@
55
*/
66
namespace Magento\Backend\Block\Dashboard\Orders;
77

8+
use Magento\Backend\Block\Template\Context;
9+
use Magento\Backend\Helper\Data;
10+
use Magento\Framework\Module\Manager;
11+
use Magento\Reports\Model\ResourceModel\Order\CollectionFactory;
12+
813
/**
914
* Adminhtml dashboard recent orders grid
1015
*
16+
* @api
1117
* @author Magento Core Team <core@magentocommerce.com>
1218
* @SuppressWarnings(PHPMD.DepthOfInheritance)
1319
*/
1420
class Grid extends \Magento\Backend\Block\Dashboard\Grid
1521
{
1622
/**
17-
* @var \Magento\Reports\Model\ResourceModel\Order\CollectionFactory
23+
* @var CollectionFactory
1824
*/
1925
protected $_collectionFactory;
2026

2127
/**
22-
* @var \Magento\Framework\Module\Manager
28+
* @var Manager
2329
*/
2430
protected $_moduleManager;
2531

2632
/**
27-
* @param \Magento\Backend\Block\Template\Context $context
28-
* @param \Magento\Backend\Helper\Data $backendHelper
29-
* @param \Magento\Framework\Module\Manager $moduleManager
30-
* @param \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory
33+
* @param Context $context
34+
* @param Data $backendHelper
35+
* @param Manager $moduleManager
36+
* @param CollectionFactory $collectionFactory
3137
* @param array $data
3238
*/
3339
public function __construct(
34-
\Magento\Backend\Block\Template\Context $context,
35-
\Magento\Backend\Helper\Data $backendHelper,
36-
\Magento\Framework\Module\Manager $moduleManager,
37-
\Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
40+
Context $context,
41+
Data $backendHelper,
42+
Manager $moduleManager,
43+
CollectionFactory $collectionFactory,
3844
array $data = []
3945
) {
4046
$this->_moduleManager = $moduleManager;

app/code/Magento/Backend/Block/Dashboard/Sales.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,42 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Backend\Block\Dashboard;
79

10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Framework\Module\Manager;
12+
use Magento\Reports\Model\ResourceModel\Order\CollectionFactory;
13+
814
/**
915
* Adminhtml dashboard sales statistics bar
1016
*
17+
* @api
1118
* @author Magento Core Team <core@magentocommerce.com>
1219
*/
13-
class Sales extends \Magento\Backend\Block\Dashboard\Bar
20+
class Sales extends Bar
1421
{
1522
/**
1623
* @var string
1724
*/
1825
protected $_template = 'Magento_Backend::dashboard/salebar.phtml';
1926

2027
/**
21-
* @var \Magento\Framework\Module\Manager
28+
* @var Manager
2229
*/
2330
protected $_moduleManager;
2431

2532
/**
26-
* @param \Magento\Backend\Block\Template\Context $context
27-
* @param \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory
28-
* @param \Magento\Framework\Module\Manager $moduleManager
33+
* @param Context $context
34+
* @param CollectionFactory $collectionFactory
35+
* @param Manager $moduleManager
2936
* @param array $data
3037
*/
3138
public function __construct(
32-
\Magento\Backend\Block\Template\Context $context,
33-
\Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
34-
\Magento\Framework\Module\Manager $moduleManager,
39+
Context $context,
40+
CollectionFactory $collectionFactory,
41+
Manager $moduleManager,
3542
array $data = []
3643
) {
3744
$this->_moduleManager = $moduleManager;

app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
namespace Magento\Backend\Block\Dashboard\Tab;
8+
79
/**
810
* Adminhtml dashboard order amounts diagram
11+
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
12+
* @see dashboard.chart.amounts in adminhtml_dashboard_index.xml
913
*
1014
* @author Magento Core Team <core@magentocommerce.com>
1115
*/
12-
namespace Magento\Backend\Block\Dashboard\Tab;
13-
1416
class Amounts extends \Magento\Backend\Block\Dashboard\Graph
1517
{
1618
/**

app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
namespace Magento\Backend\Block\Dashboard\Tab;
8+
79
/**
810
* Adminhtml dashboard orders diagram
11+
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
12+
* @see dashboard.chart.orders in adminhtml_dashboard_index.xml
913
*
1014
* @author Magento Core Team <core@magentocommerce.com>
1115
*/
12-
namespace Magento\Backend\Block\Dashboard\Tab;
13-
1416
class Orders extends \Magento\Backend\Block\Dashboard\Graph
1517
{
1618
/**

app/code/Magento/Backend/Block/Dashboard/Totals.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,42 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

7-
/**
8-
* Adminhtml dashboard totals bar
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
11-
*/
128
namespace Magento\Backend\Block\Dashboard;
139

10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Framework\Module\Manager;
12+
use Magento\Reports\Model\ResourceModel\Order\Collection;
13+
use Magento\Reports\Model\ResourceModel\Order\CollectionFactory;
14+
use Magento\Store\Model\Store;
15+
1416
/**
15-
* Totals block.
17+
* Adminhtml dashboard totals bar
18+
* @api
1619
*/
17-
class Totals extends \Magento\Backend\Block\Dashboard\Bar
20+
class Totals extends Bar
1821
{
1922
/**
2023
* @var string
2124
*/
2225
protected $_template = 'Magento_Backend::dashboard/totalbar.phtml';
2326

2427
/**
25-
* @var \Magento\Framework\Module\Manager
28+
* @var Manager
2629
*/
2730
protected $_moduleManager;
2831

2932
/**
30-
* @param \Magento\Backend\Block\Template\Context $context
31-
* @param \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory
32-
* @param \Magento\Framework\Module\Manager $moduleManager
33+
* @param Context $context
34+
* @param CollectionFactory $collectionFactory
35+
* @param Manager $moduleManager
3336
* @param array $data
3437
*/
3538
public function __construct(
36-
\Magento\Backend\Block\Template\Context $context,
37-
\Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
38-
\Magento\Framework\Module\Manager $moduleManager,
39+
Context $context,
40+
CollectionFactory $collectionFactory,
41+
Manager $moduleManager,
3942
array $data = []
4043
) {
4144
$this->_moduleManager = $moduleManager;
@@ -60,7 +63,7 @@ protected function _prepareLayout()
6063
);
6164
$period = $this->getRequest()->getParam('period', '24h');
6265

63-
/* @var $collection \Magento\Reports\Model\ResourceModel\Order\Collection */
66+
/* @var $collection Collection */
6467
$collection = $this->_collectionFactory->create()->addCreateAtPeriodFilter(
6568
$period
6669
)->calculateTotals(
@@ -80,7 +83,7 @@ protected function _prepareLayout()
8083
} elseif (!$collection->isLive()) {
8184
$collection->addFieldToFilter(
8285
'store_id',
83-
['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]
86+
['eq' => $this->_storeManager->getStore(Store::ADMIN_CODE)->getId()]
8487
);
8588
}
8689
}
@@ -94,5 +97,7 @@ protected function _prepareLayout()
9497
$this->addTotal(__('Tax'), $totals->getTax());
9598
$this->addTotal(__('Shipping'), $totals->getShipping());
9699
$this->addTotal(__('Quantity'), $totals->getQuantity() * 1, true);
100+
101+
return $this;
97102
}
98103
}

0 commit comments

Comments
 (0)