Skip to content

Improve dashboard charts - migrate to chart.js #26923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 8 additions & 37 deletions app/code/Magento/Backend/Block/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backend\Block;

/**
* Class used to initialize layout for MBO Dashboard
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
* @see dashboard in adminhtml_dashboard_index.xml
*
* @api
* @since 100.0.2
*/
class Dashboard extends \Magento\Backend\Block\Template
class Dashboard extends Template
{
/**
* Location of the "Enable Chart" config param
Expand All @@ -23,42 +28,8 @@ class Dashboard extends \Magento\Backend\Block\Template
protected $_template = 'Magento_Backend::dashboard/index.phtml';

/**
* @return void
*/
protected function _prepareLayout()
{
$this->addChild('lastOrders', \Magento\Backend\Block\Dashboard\Orders\Grid::class);

$this->addChild('totals', \Magento\Backend\Block\Dashboard\Totals::class);

$this->addChild('sales', \Magento\Backend\Block\Dashboard\Sales::class);

$isChartEnabled = $this->_scopeConfig->getValue(
self::XML_PATH_ENABLE_CHARTS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
if ($isChartEnabled) {
$block = $this->getLayout()->createBlock(\Magento\Backend\Block\Dashboard\Diagrams::class);
} else {
$block = $this->getLayout()->createBlock(
\Magento\Backend\Block\Template::class
)->setTemplate(
'dashboard/graph/disabled.phtml'
)->setConfigUrl(
$this->getUrl(
'adminhtml/system_config/edit',
['section' => 'admin', '_fragment' => 'admin_dashboard-link']
)
);
}
$this->setChild('diagrams', $block);

$this->addChild('grids', \Magento\Backend\Block\Dashboard\Grids::class);

parent::_prepareLayout();
}

/**
* Get url for switch action
*
* @return string
*/
public function getSwitchUrl()
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Backend/Block/Dashboard/Diagrams.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

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

/**
* Internal constructor, that is called from real constructor
*
* @return void
*/
protected function _construct()
Expand All @@ -28,6 +32,8 @@ protected function _construct()
}

/**
* Preparing global layout
*
* @return $this
*/
protected function _prepareLayout()
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Backend/Block/Dashboard/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* Adminhtml dashboard google chart block
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
* @see dashboard.chart.amounts and dashboard.chart.orders in adminhtml_dashboard_index.xml
*
* @author Magento Core Team <core@magentocommerce.com>
*/
Expand Down
12 changes: 10 additions & 2 deletions app/code/Magento/Backend/Block/Dashboard/Grids.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backend\Block\Dashboard;

use Magento\Backend\Block\Dashboard\Tab\Products\Ordered;
use Magento\Backend\Block\Widget\Tabs;

/**
* Adminhtml dashboard bottom tabs
*
* @api
* @author Magento Core Team <core@magentocommerce.com>
*/
class Grids extends \Magento\Backend\Block\Widget\Tabs
class Grids extends Tabs
{
/**
* @var string
*/
protected $_template = 'Magento_Backend::widget/tabshoriz.phtml';

/**
* Internal constructor, that is called from real constructor
*
* @return void
*/
protected function _construct()
Expand Down Expand Up @@ -49,7 +57,7 @@ protected function _prepareLayout()
[
'label' => __('Bestsellers'),
'content' => $this->getLayout()->createBlock(
\Magento\Backend\Block\Dashboard\Tab\Products\Ordered::class
Ordered::class
)->toHtml(),
'active' => true
]
Expand Down
26 changes: 16 additions & 10 deletions app/code/Magento/Backend/Block/Dashboard/Orders/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,42 @@
*/
namespace Magento\Backend\Block\Dashboard\Orders;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Helper\Data;
use Magento\Framework\Module\Manager;
use Magento\Reports\Model\ResourceModel\Order\CollectionFactory;

/**
* Adminhtml dashboard recent orders grid
*
* @api
* @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
class Grid extends \Magento\Backend\Block\Dashboard\Grid
{
/**
* @var \Magento\Reports\Model\ResourceModel\Order\CollectionFactory
* @var CollectionFactory
*/
protected $_collectionFactory;

/**
* @var \Magento\Framework\Module\Manager
* @var Manager
*/
protected $_moduleManager;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
* @param \Magento\Framework\Module\Manager $moduleManager
* @param \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory
* @param Context $context
* @param Data $backendHelper
* @param Manager $moduleManager
* @param CollectionFactory $collectionFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
\Magento\Framework\Module\Manager $moduleManager,
\Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
Context $context,
Data $backendHelper,
Manager $moduleManager,
CollectionFactory $collectionFactory,
array $data = []
) {
$this->_moduleManager = $moduleManager;
Expand Down
23 changes: 15 additions & 8 deletions app/code/Magento/Backend/Block/Dashboard/Sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Backend\Block\Dashboard;

use Magento\Backend\Block\Template\Context;
use Magento\Framework\Module\Manager;
use Magento\Reports\Model\ResourceModel\Order\CollectionFactory;

/**
* Adminhtml dashboard sales statistics bar
*
* @api
* @author Magento Core Team <core@magentocommerce.com>
*/
class Sales extends \Magento\Backend\Block\Dashboard\Bar
class Sales extends Bar
{
/**
* @var string
*/
protected $_template = 'Magento_Backend::dashboard/salebar.phtml';

/**
* @var \Magento\Framework\Module\Manager
* @var Manager
*/
protected $_moduleManager;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory
* @param \Magento\Framework\Module\Manager $moduleManager
* @param Context $context
* @param CollectionFactory $collectionFactory
* @param Manager $moduleManager
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
\Magento\Framework\Module\Manager $moduleManager,
Context $context,
CollectionFactory $collectionFactory,
Manager $moduleManager,
array $data = []
) {
$this->_moduleManager = $moduleManager;
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Block\Dashboard\Tab;

/**
* Adminhtml dashboard order amounts diagram
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
* @see dashboard.chart.amounts in adminhtml_dashboard_index.xml
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Backend\Block\Dashboard\Tab;

class Amounts extends \Magento\Backend\Block\Dashboard\Graph
{
/**
Expand Down
6 changes: 4 additions & 2 deletions app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Block\Dashboard\Tab;

/**
* Adminhtml dashboard orders diagram
* @deprecated dashboard graphs were migrated to dynamic chart.js solution
* @see dashboard.chart.orders in adminhtml_dashboard_index.xml
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Backend\Block\Dashboard\Tab;

class Orders extends \Magento\Backend\Block\Dashboard\Graph
{
/**
Expand Down
40 changes: 23 additions & 17 deletions app/code/Magento/Backend/Block/Dashboard/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,43 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

/**
* Adminhtml dashboard totals bar
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Backend\Block\Dashboard;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Model\Dashboard\Period;
use Magento\Framework\Module\Manager;
use Magento\Reports\Model\ResourceModel\Order\Collection;
use Magento\Reports\Model\ResourceModel\Order\CollectionFactory;
use Magento\Store\Model\Store;

/**
* Totals block.
* Adminhtml dashboard totals bar
* @api
*/
class Totals extends \Magento\Backend\Block\Dashboard\Bar
class Totals extends Bar
{
/**
* @var string
*/
protected $_template = 'Magento_Backend::dashboard/totalbar.phtml';

/**
* @var \Magento\Framework\Module\Manager
* @var Manager
*/
protected $_moduleManager;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory
* @param \Magento\Framework\Module\Manager $moduleManager
* @param Context $context
* @param CollectionFactory $collectionFactory
* @param Manager $moduleManager
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Reports\Model\ResourceModel\Order\CollectionFactory $collectionFactory,
\Magento\Framework\Module\Manager $moduleManager,
Context $context,
CollectionFactory $collectionFactory,
Manager $moduleManager,
array $data = []
) {
$this->_moduleManager = $moduleManager;
Expand All @@ -58,9 +62,9 @@ protected function _prepareLayout()
) || $this->getRequest()->getParam(
'group'
);
$period = $this->getRequest()->getParam('period', '24h');
$period = $this->getRequest()->getParam('period', Period::PERIOD_24_HOURS);

/* @var $collection \Magento\Reports\Model\ResourceModel\Order\Collection */
/* @var $collection Collection */
$collection = $this->_collectionFactory->create()->addCreateAtPeriodFilter(
$period
)->calculateTotals(
Expand All @@ -80,7 +84,7 @@ protected function _prepareLayout()
} elseif (!$collection->isLive()) {
$collection->addFieldToFilter(
'store_id',
['eq' => $this->_storeManager->getStore(\Magento\Store\Model\Store::ADMIN_CODE)->getId()]
['eq' => $this->_storeManager->getStore(Store::ADMIN_CODE)->getId()]
);
}
}
Expand All @@ -94,5 +98,7 @@ protected function _prepareLayout()
$this->addTotal(__('Tax'), $totals->getTax());
$this->addTotal(__('Shipping'), $totals->getShipping());
$this->addTotal(__('Quantity'), $totals->getQuantity() * 1, true);

return $this;
}
}
Loading