From 7beb56d6d8eb1fddef9ffc0066e7135217311f67 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Mon, 13 Jul 2020 16:20:36 -0400 Subject: [PATCH] Issue #2 - Add badge notification config setting --- Block/Adminhtml/Badge.php | 41 ++++++++++++++++++++-- Helper/Data.php | 34 ++++++++++++++++++ Model/Config/Source/BadgeNotification.php | 26 ++++++++++++++ composer.json | 2 +- etc/adminhtml/system.xml | 8 +++++ etc/config.xml | 17 +++++++++ view/adminhtml/templates/badge.phtml | 3 +- view/adminhtml/web/js/notification-icon.js | 13 +++++-- 8 files changed, 138 insertions(+), 6 deletions(-) create mode 100755 Helper/Data.php create mode 100644 Model/Config/Source/BadgeNotification.php create mode 100755 etc/config.xml diff --git a/Block/Adminhtml/Badge.php b/Block/Adminhtml/Badge.php index cff6aaf..a8d0038 100644 --- a/Block/Adminhtml/Badge.php +++ b/Block/Adminhtml/Badge.php @@ -9,23 +9,60 @@ use Magento\Backend\Block\Template; use MagePal\Core\Controller\Adminhtml\Version\Index; +use MagePal\Core\Helper\Data; class Badge extends Template { - const SEARCH_URL = 'https://www.magepal.com/catalogsearch/result/?utm_source=search&utm_medium=admin&utm_campaign=core'; + const SEARCH_URL = 'https://www.magepal.com/catalogsearch/result/'; + /** + * @var Data + */ + private $dataHelper; + /** + * Badge constructor. + * @param Template\Context $context + * @param Data $dataHelper + * @param array $data + */ + public function __construct( + Template\Context $context, + Data $dataHelper, + array $data = [] + ) { + parent::__construct($context, $data); + $this->dataHelper = $dataHelper; + } + + /** + * @return bool + */ + public function getNotificationOption() + { + return $this->dataHelper->getBadgeNotificationValue(); + } + + /** + * @return string + */ public function getNotificationUrl() { return $this->getUrl('magepal/version/index'); } + /** + * @return bool + */ public function isAuthorized() { return $this->_authorization->isAllowed(Index::ADMIN_RESOURCE); } + /** + * @return string + */ public function getSearchUrl() { - return self::SEARCH_URL; + return self::SEARCH_URL . '?utm_source=search&utm_medium=admin&utm_campaign=core'; } } diff --git a/Helper/Data.php b/Helper/Data.php new file mode 100755 index 0000000..b173c4f --- /dev/null +++ b/Helper/Data.php @@ -0,0 +1,34 @@ +scopeConfig->getValue( + self::XML_PATH_ACTIVE, + ScopeInterface::SCOPE_STORE, + $scopeCode + ); + } +} diff --git a/Model/Config/Source/BadgeNotification.php b/Model/Config/Source/BadgeNotification.php new file mode 100644 index 0000000..7a783f8 --- /dev/null +++ b/Model/Config/Source/BadgeNotification.php @@ -0,0 +1,26 @@ + Data::NOTIFICATION_ENABLED, 'label' => 'Yes'], + ['value' => Data::NOTIFICATION_WITHIN_TAB, 'label' => 'When Tab Open'], + ['value' => Data::NOTIFICATION_DISABLED, 'label' => __('No')] + ]; + } +} diff --git a/composer.json b/composer.json index eef7a8c..94cc8c6 100755 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ }, "type": "magento2-module", - "version": "1.1.4", + "version": "1.1.5", "autoload": { "files": [ "registration.php" diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 57dbff1..b8a3f7b 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -25,6 +25,14 @@ 1 MagePal\Core\Block\Adminhtml\System\Config\Field\Extensions + + + + + MagePal\Core\Model\Config\Source\BadgeNotification + + + diff --git a/etc/config.xml b/etc/config.xml new file mode 100755 index 0000000..5c85a13 --- /dev/null +++ b/etc/config.xml @@ -0,0 +1,17 @@ + + + + + + + 1 + + + + diff --git a/view/adminhtml/templates/badge.phtml b/view/adminhtml/templates/badge.phtml index db49c04..3017270 100644 --- a/view/adminhtml/templates/badge.phtml +++ b/view/adminhtml/templates/badge.phtml @@ -13,7 +13,8 @@ "*": { "magePalCoreNotificationIcon": { "url":"escapeUrl($block->getNotificationUrl()) ?>", - "searchUrl":"escapeUrl($block->getSearchUrl()) ?>" + "searchUrl":"escapeUrl($block->getSearchUrl()) ?>", + "notificationOption": "getNotificationOption() ?>" } } } diff --git a/view/adminhtml/web/js/notification-icon.js b/view/adminhtml/web/js/notification-icon.js index 4013fd6..2effdff 100644 --- a/view/adminhtml/web/js/notification-icon.js +++ b/view/adminhtml/web/js/notification-icon.js @@ -16,7 +16,7 @@ define([ var html = ''; $element.before(html); - return function (config) { + var showBadge = function (config) { $.ajax({ url: config.url, type: 'get', @@ -25,10 +25,19 @@ define([ }).done(function (response) { if (typeof response === 'object' && response.hasOwnProperty('count') && response.count > 0) { var html = '' + response.count + ''; - $element.append(html); + if (config.notificationOption !== 1) { + $element.append(html); + } + $element.parent().parent().find('ul.items li.item:first').append(html) } }); + }; + + return function (config) { + if (config.notificationOption !== 0) { + showBadge(config); + } var openWindow = function ($element) { if ($($element).val().length > 2) {