diff --git a/Api/Log/RepositoryInterface.php b/Api/Log/RepositoryInterface.php index 3876ffd..163c362 100755 --- a/Api/Log/RepositoryInterface.php +++ b/Api/Log/RepositoryInterface.php @@ -13,21 +13,54 @@ interface RepositoryInterface { + /** + * Limit stream size to 100 lines + */ + public const STREAM_DEFAULT_LIMIT = 100; + + /** + * Log file path pattern + */ + public const LOG_FILE = '%s/log/messagebird-%s.log'; + /** * Add record to error log * * @param string $type * @param mixed $data - * */ - public function addErrorLog(string $type, $data); + public function addErrorLog(string $type, $data): void; /** * Add record to debug log * * @param string $type * @param mixed $data + */ + public function addDebugLog(string $type, $data): void; + + /** + * Add record to log + * + * @param string $type + * @param mixed $data + */ + public function addLog(string $type, $data): void; + + /** + * Returns path of logfile + * + * @param string $type + * @return string + */ + public function getLogFilePath(string $type): ?string; + + /** + * Return log entries as sorted array * + * @param string $path + * @param int|null $limit + * @return array|null */ - public function addDebugLog(string $type, $data); + public function getLogEntriesAsArray(string $path, ?int $limit = null): ?array; } diff --git a/Block/Adminhtml/MessageBird/Header.php b/Block/Adminhtml/Design/Header.php similarity index 91% rename from Block/Adminhtml/MessageBird/Header.php rename to Block/Adminhtml/Design/Header.php index 996d457..31877ac 100755 --- a/Block/Adminhtml/MessageBird/Header.php +++ b/Block/Adminhtml/Design/Header.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magmodules\MessageBird\Block\Adminhtml\MessageBird; +namespace Magmodules\MessageBird\Block\Adminhtml\Design; use Magento\Config\Block\System\Config\Form\Field; use Magento\Framework\Data\Form\Element\AbstractElement; diff --git a/Block/Adminhtml/MessageBird/Heading.php b/Block/Adminhtml/Design/Heading.php similarity index 70% rename from Block/Adminhtml/MessageBird/Heading.php rename to Block/Adminhtml/Design/Heading.php index 3cd9970..3f9d8b6 100755 --- a/Block/Adminhtml/MessageBird/Heading.php +++ b/Block/Adminhtml/Design/Heading.php @@ -5,7 +5,7 @@ */ declare(strict_types=1); -namespace Magmodules\MessageBird\Block\Adminhtml\MessageBird; +namespace Magmodules\MessageBird\Block\Adminhtml\Design; use Magento\Config\Block\System\Config\Form\Field; use Magento\Framework\Data\Form\Element\AbstractElement; @@ -26,8 +26,8 @@ public function render(AbstractElement $element): string $html = ''; $html .= ' '; $html .= ' '; - $html .= '
' . $element->getData('label') . '
'; - $html .= '
' . $element->getData('comment') . '
'; + $html .= '
' . $element->getData('label') . '
'; + $html .= '
' . $element->getData('comment') . '
'; $html .= ' '; $html .= ' '; $html .= ''; diff --git a/Block/Adminhtml/System/Config/Button/Credentials.php b/Block/Adminhtml/System/Config/Button/Credentials.php index e93ad59..5dd2ec8 100755 --- a/Block/Adminhtml/System/Config/Button/Credentials.php +++ b/Block/Adminhtml/System/Config/Button/Credentials.php @@ -83,19 +83,19 @@ public function getApiCheckUrl() } /** - * @return mixed + * @return string */ - public function getButtonHtml() + public function getButtonHtml(): string { - $buttonData = ['id' => 'messagebird-button_credentials', 'label' => __('Check Credentials')]; try { - $button = $this->getLayout()->createBlock( - Button::class - )->setData($buttonData); - return $button->toHtml(); + return $this->getLayout() + ->createBlock(Button::class) + ->setData([ + 'id' => 'mm-ui-button_credentials', + 'label' => __('Check Credentials') + ])->toHtml(); } catch (Exception $e) { - $this->logger->addErrorLog('LocalizedException', $e->getMessage()); - return false; + return ''; } } } diff --git a/Block/Adminhtml/System/Config/Button/DebugCheck.php b/Block/Adminhtml/System/Config/Button/DebugCheck.php deleted file mode 100755 index 0d808f9..0000000 --- a/Block/Adminhtml/System/Config/Button/DebugCheck.php +++ /dev/null @@ -1,94 +0,0 @@ -request = $context->getRequest(); - parent::__construct($context, $data); - } - - /** - * @param AbstractElement $element - * - * @return string - */ - public function render(AbstractElement $element) - { - $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); - return parent::render($element); - } - - /** - * @param AbstractElement $element - * - * @return string - */ - public function _getElementHtml(AbstractElement $element) - { - return $this->_toHtml(); - } - - /** - * @return string - */ - public function getDebugCheckUrl() - { - return $this->getUrl('messagebird/log/debug'); - } - - /** - * @return mixed - */ - public function getButtonHtml() - { - $buttonData = [ - 'id' => 'magmodules-messagebird-button_debug', - 'label' => __('Check last 100 debug log records') - ]; - try { - $button = $this->getLayout()->createBlock( - Button::class - )->setData($buttonData); - return $button->toHtml(); - } catch (Exception $e) { - return false; - } - } -} diff --git a/Block/Adminhtml/System/Config/Button/ErrorCheck.php b/Block/Adminhtml/System/Config/Button/ErrorCheck.php deleted file mode 100755 index 95b2a62..0000000 --- a/Block/Adminhtml/System/Config/Button/ErrorCheck.php +++ /dev/null @@ -1,95 +0,0 @@ -request = $context->getRequest(); - parent::__construct($context, $data); - } - - /** - * @param AbstractElement $element - * - * @return string - */ - public function render(AbstractElement $element) - { - $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); - return parent::render($element); - } - - /** - * @param AbstractElement $element - * - * @return string - */ - public function _getElementHtml(AbstractElement $element) - { - return $this->_toHtml(); - } - - /** - * @return string - */ - public function getErrorCheckUrl() - { - return $this->getUrl('messagebird/log/error'); - } - - /** - * @return mixed - */ - public function getButtonHtml() - { - $buttonData = [ - 'id' => 'magmodules-messagebird-button_error', - 'label' => __('Check last 100 error log records') - ]; - try { - $button = $this->getLayout()->createBlock( - Button::class - )->setData($buttonData); - return $button->toHtml(); - } catch (Exception $e) { - return false; - } - } -} diff --git a/Block/Adminhtml/System/Config/Button/Log.php b/Block/Adminhtml/System/Config/Button/Log.php new file mode 100644 index 0000000..34f055f --- /dev/null +++ b/Block/Adminhtml/System/Config/Button/Log.php @@ -0,0 +1,74 @@ +unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); + return parent::render($element); + } + + /** + * @param AbstractElement $element + * + * @return string + */ + public function _getElementHtml(AbstractElement $element): string + { + return $this->_toHtml(); + } + + /** + * @param string $type + * @return string + */ + public function getDownloadUrl(string $type): string + { + return $this->getUrl('messagebird/log/stream', ['type' => $type]); + } + + /** + * @param string $type + * @return string + */ + public function getButtonHtml(string $type): string + { + try { + return $this->getLayout() + ->createBlock(Button::class) + ->setData([ + 'id' => 'mm-ui-button_' . $type, + 'label' => __('Show last %1 %2 log records', LogRepository::STREAM_DEFAULT_LIMIT, $type) + ])->toHtml(); + } catch (Exception $e) { + return ''; + } + } +} diff --git a/Block/Adminhtml/System/Config/Button/VersionCheck.php b/Block/Adminhtml/System/Config/Button/VersionCheck.php index b5fa02b..b7f6896 100755 --- a/Block/Adminhtml/System/Config/Button/VersionCheck.php +++ b/Block/Adminhtml/System/Config/Button/VersionCheck.php @@ -53,7 +53,7 @@ public function __construct( /** * @return string */ - public function getVersion() + public function getVersion(): string { return $this->configRepository->getExtensionVersion(); } @@ -63,7 +63,7 @@ public function getVersion() * * @return string */ - public function render(AbstractElement $element) + public function render(AbstractElement $element): string { $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); return parent::render($element); @@ -74,7 +74,7 @@ public function render(AbstractElement $element) * * @return string */ - public function _getElementHtml(AbstractElement $element) + public function _getElementHtml(AbstractElement $element): string { return $this->_toHtml(); } @@ -82,32 +82,33 @@ public function _getElementHtml(AbstractElement $element) /** * @return string */ - public function getVersionCheckUrl() + public function getVersionCheckUrl(): string { - return $this->getUrl('messagebird/versioncheck/index'); + return $this->getUrl('messagebird/versionCheck/index'); } /** * @return string */ - public function getChangeLogUrl() + public function getChangeLogUrl(): string { - return $this->getUrl('messagebird/versioncheck/changelog'); + return $this->getUrl('messagebird/versionCheck/changelog'); } /** - * @return mixed + * @return string */ - public function getButtonHtml() + public function getButtonHtml(): string { - $buttonData = ['id' => 'magmodules-messagebird-button_version', 'label' => __('Check for latest versions')]; try { - $button = $this->getLayout()->createBlock( - Button::class - )->setData($buttonData); - return $button->toHtml(); + return $this->getLayout() + ->createBlock(Button::class) + ->setData([ + 'id' => 'mm-ui-button_version', + 'label' => __('Check for latest versions') + ])->toHtml(); } catch (Exception $e) { - return false; + return ''; } } } diff --git a/Block/ProductAlert/Price.php b/Block/ProductAlert/Price.php index 30a5f1d..7d699a9 100755 --- a/Block/ProductAlert/Price.php +++ b/Block/ProductAlert/Price.php @@ -91,9 +91,10 @@ public function setTemplate($template) $template = ''; } elseif (!$this->session->isLoggedIn() || !$this->configRepository->isEnabledForPriceChanges($storeId)) { $template = 'Magento_ProductAlert::product/view.phtml'; - $this->setSignupUrl($this->_helper->getSaveUrl('price')); + $this->setData('signup_url', $this->_helper->getSaveUrl('price')); } else { - $this->setSignupUrl( + $this->setData( + 'signup_url', $this->getUrl( 'messagebird/addalert/price', [ diff --git a/Block/ProductAlert/Stock.php b/Block/ProductAlert/Stock.php index de842ff..bd0b32a 100755 --- a/Block/ProductAlert/Stock.php +++ b/Block/ProductAlert/Stock.php @@ -88,9 +88,10 @@ public function setTemplate($template) $template = ''; } elseif (!$this->session->isLoggedIn() || !$this->configRepository->isEnabledForOutOfStock($storeId)) { $template = 'Magento_ProductAlert::product/view.phtml'; - $this->setSignupUrl($this->_helper->getSaveUrl('stock')); + $this->setData('signup_url', $this->_helper->getSaveUrl('stock')); } else { - $this->setSignupUrl( + $this->setData( + 'signup_url', $this->getUrl( 'messagebird/addalert/stock', [ diff --git a/Controller/Adminhtml/Log/Debug.php b/Controller/Adminhtml/Log/Debug.php deleted file mode 100755 index 48b018a..0000000 --- a/Controller/Adminhtml/Log/Debug.php +++ /dev/null @@ -1,138 +0,0 @@ -resultJsonFactory = $resultJsonFactory; - $this->dir = $dir; - $this->file = $file; - $this->serializerJson = $serializerJson; - parent::__construct($context); - } - - /** - * @return ResponseInterface|Json|ResultInterface - * @throws FileSystemException - */ - public function execute() - { - $resultJson = $this->resultJsonFactory->create(); - if ($this->isLogExists(self::DEBUG_LOG_FILE)) { - $result = ['result' => $this->prepareLogText(self::DEBUG_LOG_FILE)]; - } else { - $result = __('Log is empty'); - } - return $resultJson->setData($result); - } - - /** - * Check is log file exists - * - * @param string $file - * - * @return bool - */ - private function isLogExists(string $file): bool - { - try { - $logFile = sprintf($file, $this->dir->getPath('var')); - return $this->file->isExists($logFile); - } catch (Exception $e) { - return false; - } - } - - /** - * Prepare encoded log text - * - * @param string $file - * - * @return array - * @throws FileSystemException - */ - private function prepareLogText(string $file): array - { - $logFile = sprintf($file, $this->dir->getPath('var')); - $fileContent = explode(PHP_EOL, $this->file->fileGetContents($logFile)); - if (count($fileContent) > 100) { - $fileContent = array_slice($fileContent, -100, 100, true); - } - $result = []; - foreach ($fileContent as $line) { - $data = explode('] ', $line); - $date = ltrim(array_shift($data), '['); - $data = implode('] ', $data); - $data = explode(': ', $data); - array_shift($data); - $result[] = [ - 'date' => $date, - 'msg' => implode(': ', $data) - ]; - } - return $result; - } -} diff --git a/Controller/Adminhtml/Log/Error.php b/Controller/Adminhtml/Log/Error.php deleted file mode 100755 index 2867f97..0000000 --- a/Controller/Adminhtml/Log/Error.php +++ /dev/null @@ -1,134 +0,0 @@ -resultJsonFactory = $resultJsonFactory; - $this->dir = $dir; - $this->file = $file; - $this->serializerJson = $serializerJson; - parent::__construct($context); - } - - /** - * @return ResponseInterface|Json|ResultInterface - * @throws FileSystemException - */ - public function execute() - { - $resultJson = $this->resultJsonFactory->create(); - if ($this->isLogExists(self::ERROR_LOG_FILE)) { - $result = ['result' => $this->prepareLogText(self::ERROR_LOG_FILE)]; - } else { - $result = __('Log is empty'); - } - return $resultJson->setData($result); - } - - /** - * Check is log file exists - * - * @param string $file - * - * @return bool - */ - private function isLogExists(string $file): bool - { - try { - $logFile = sprintf($file, $this->dir->getPath('var')); - return $this->file->isExists($logFile); - } catch (Exception $e) { - return false; - } - } - - /** - * Prepare encoded log text - * - * @param string $file - * - * @return array - * @throws FileSystemException - */ - private function prepareLogText(string $file): array - { - $logFile = sprintf($file, $this->dir->getPath('var')); - $fileContent = explode(PHP_EOL, $this->file->fileGetContents($logFile)); - if (count($fileContent) > 100) { - $fileContent = array_slice($fileContent, -100, 100, true); - } - $result = []; - foreach ($fileContent as $line) { - $data = explode('] ', $line); - $date = ltrim(array_shift($data), '['); - $data = implode('] ', $data); - $data = explode(': ', $data); - array_shift($data); - $result[] = [ - 'date' => $date, - 'msg' => implode(': ', $data) - ]; - } - return $result; - } -} diff --git a/Controller/Adminhtml/Log/Stream.php b/Controller/Adminhtml/Log/Stream.php new file mode 100644 index 0000000..364bb8e --- /dev/null +++ b/Controller/Adminhtml/Log/Stream.php @@ -0,0 +1,74 @@ +resultJsonFactory = $resultJsonFactory; + $this->request = $context->getRequest(); + $this->logRepository = $logRepository; + parent::__construct($context); + } + + /** + * @return Json + */ + public function execute(): Json + { + $resultJson = $this->resultJsonFactory->create(); + $type = $this->request->getParam('type') == 'error' ? 'error' : 'debug'; + $logFilePath = $this->logRepository->getLogFilePath($type); + + if ($logFilePath && $result = $this->logRepository->getLogEntriesAsArray($logFilePath)) { + $result = ['result' => $result]; + } else { + $result = __('Log is empty'); + } + + return $resultJson->setData($result); + } +} diff --git a/Controller/Adminhtml/VersionCheck/Changelog.php b/Controller/Adminhtml/VersionCheck/Changelog.php index c53e0a7..c2b9438 100755 --- a/Controller/Adminhtml/VersionCheck/Changelog.php +++ b/Controller/Adminhtml/VersionCheck/Changelog.php @@ -8,10 +8,8 @@ namespace Magmodules\MessageBird\Controller\Adminhtml\VersionCheck; use Magento\Backend\App\Action; -use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\Result\JsonFactory; -use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; @@ -30,11 +28,6 @@ class Changelog extends Action */ private $resultJsonFactory; - /** - * @var ConfigRepository - */ - private $configRepository; - /** * @var JsonSerializer */ @@ -50,41 +43,31 @@ class Changelog extends Action * * @param Action\Context $context * @param JsonFactory $resultJsonFactory - * @param ConfigRepository $configRepository * @param JsonSerializer $json * @param File $file */ public function __construct( Action\Context $context, JsonFactory $resultJsonFactory, - ConfigRepository $configRepository, JsonSerializer $json, File $file ) { $this->resultJsonFactory = $resultJsonFactory; - $this->configRepository = $configRepository; $this->json = $json; $this->file = $file; parent::__construct($context); } /** - * @return ResponseInterface|Json|ResultInterface + * @return Json * @throws FileSystemException */ - public function execute() + public function execute(): Json { $resultJson = $this->resultJsonFactory->create(); $result = $this->getVersions(); - $current = $latest = preg_replace('/^v/', '', $this->configRepository->getExtensionVersion()); $data = $this->json->unserialize($result); - $logs = []; - foreach ($data as $version => $log) { - if (version_compare((string)$current, (string)$version) == -1) { - $logs[$version] = $log; - } - } - return $resultJson->setData($logs); + return $resultJson->setData($data); } /** @@ -94,7 +77,7 @@ public function execute() private function getVersions(): string { return $this->file->fileGetContents( - sprintf('http://version.magmodules.eu/%s.json', ConfigRepository::EXTENSION_CODE) + sprintf('https://version.magmodules.eu/%s.json', ConfigRepository::EXTENSION_CODE) ); } } diff --git a/Controller/Adminhtml/VersionCheck/Index.php b/Controller/Adminhtml/VersionCheck/Index.php index 27153be..e23ba93 100755 --- a/Controller/Adminhtml/VersionCheck/Index.php +++ b/Controller/Adminhtml/VersionCheck/Index.php @@ -12,7 +12,6 @@ use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\Result\JsonFactory; use Magento\Framework\Controller\ResultInterface; -use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Serialize\Serializer\Json as JsonSerializer; use Magmodules\MessageBird\Api\Config\RepositoryInterface as ConfigRepository; @@ -69,21 +68,31 @@ public function __construct( } /** - * @return ResponseInterface|Json|ResultInterface + * @return Json */ - public function execute() + public function execute(): Json { $resultJson = $this->resultJsonFactory->create(); $result = $this->getVersions(); $current = $latest = preg_replace('/^v/', '', $this->configRepository->getExtensionVersion()); + $changeLog = []; if ($result) { $data = $this->json->unserialize($result); $versions = array_keys($data); $latest = preg_replace('/^v/', '', reset($versions)); + foreach ($data as $version => $changes) { + if (version_compare(preg_replace('/^v/', '', $version), $current) == 0) { + break; + } + $changeLog[] = [ + $version => $changes['changelog'] + ]; + } } $data = [ - 'current_verion' => 'v' . $current, - 'last_version' => 'v' . $latest + 'current_version' => 'v' . $current, + 'last_version' => 'v' . $latest, + 'changelog' => $changeLog, ]; return $resultJson->setData(['result' => $data]); } @@ -95,7 +104,7 @@ private function getVersions(): string { try { return $this->file->fileGetContents( - sprintf('http://version.magmodules.eu/%s.json', ConfigRepository::EXTENSION_CODE) + sprintf('https://version.magmodules.eu/%s.json', ConfigRepository::EXTENSION_CODE) ); } catch (\Exception $exception) { return ''; diff --git a/Logger/DebugLogger.php b/Logger/DebugLogger.php index f8f220f..38c00c2 100755 --- a/Logger/DebugLogger.php +++ b/Logger/DebugLogger.php @@ -46,7 +46,7 @@ public function __construct( * @param mixed $data * */ - public function addLog(string $type, $data) + public function addLog(string $type, $data): void { if (is_array($data) || is_object($data)) { $this->addRecord(static::INFO, $type . ': ' . $this->json->serialize($data)); diff --git a/Logger/ErrorLogger.php b/Logger/ErrorLogger.php index d86abb5..770fbbe 100755 --- a/Logger/ErrorLogger.php +++ b/Logger/ErrorLogger.php @@ -46,7 +46,7 @@ public function __construct( * @param mixed $data * */ - public function addLog($type, $data) + public function addLog($type, $data): void { if (is_array($data) || is_object($data)) { $this->addRecord(static::ERROR, $type . ': ' . $this->json->serialize($data)); diff --git a/Logger/Handler/Debug.php b/Logger/Handler/Debug.php index cb3f634..3036557 100755 --- a/Logger/Handler/Debug.php +++ b/Logger/Handler/Debug.php @@ -24,5 +24,5 @@ class Debug extends Base /** * @var string */ - protected $fileName = '/var/log/messagebird/debug.log'; + protected $fileName = '/var/log/messagebird-debug.log'; } diff --git a/Logger/Handler/Error.php b/Logger/Handler/Error.php index d764cfd..bce4e52 100755 --- a/Logger/Handler/Error.php +++ b/Logger/Handler/Error.php @@ -24,5 +24,5 @@ class Error extends Base /** * @var string */ - protected $fileName = '/var/log/messagebird/error.log'; + protected $fileName = '/var/log/messagebird-error.log'; } diff --git a/Model/Config/Repository.php b/Model/Config/Repository.php index 958f126..7b62a0f 100755 --- a/Model/Config/Repository.php +++ b/Model/Config/Repository.php @@ -14,7 +14,6 @@ use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface as StoreManager; use Magmodules\MessageBird\Api\Config\RepositoryInterface; -use Magmodules\MessageBird\Api\Log\RepositoryInterface as LogRepository; /** * MessageBird Connect config repository class @@ -32,11 +31,6 @@ class Repository implements RepositoryInterface */ private $storeManager; - /** - * @var LogRepository - */ - private $logRepository; - /** * @var ProductMetadataInterface */ @@ -52,19 +46,16 @@ class Repository implements RepositoryInterface * * @param ScopeConfig $scopeConfig * @param StoreManager $storeManager - * @param LogRepository $logRepository * @param ProductMetadataInterface $metadata */ public function __construct( ScopeConfig $scopeConfig, StoreManager $storeManager, - LogRepository $logRepository, ProductMetadataInterface $metadata, EncryptorInterface $encryptor ) { $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; - $this->logRepository = $logRepository; $this->metadata = $metadata; $this->encryptor = $encryptor; } @@ -102,7 +93,6 @@ public function getStore(): StoreInterface try { return $this->storeManager->getStore(); } catch (Exception $e) { - $this->logRepository->addErrorLog('Store error', $e->getMessage()); if ($store = $this->storeManager->getDefaultStoreView()) { return $store; } diff --git a/Model/Log/Repository.php b/Model/Log/Repository.php index 04d3312..309a21d 100755 --- a/Model/Log/Repository.php +++ b/Model/Log/Repository.php @@ -7,10 +7,14 @@ namespace Magmodules\MessageBird\Model\Log; +use Magento\Framework\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\Driver\File; +use Magento\Framework\Stdlib\DateTime\DateTime; +use Magmodules\MessageBird\Api\Log\RepositoryInterface as LogRepository; +use Magmodules\MessageBird\Api\Log\RepositoryInterface as LogRepositoryInterface; use Magmodules\MessageBird\Logger\DebugLogger; use Magmodules\MessageBird\Logger\ErrorLogger; -use Magmodules\MessageBird\Api\Log\RepositoryInterface - as LogRepositoryInterface; +use Magmodules\MessageBird\Api\Config\RepositoryInterface as Config; /** * Logs repository class @@ -22,30 +26,57 @@ class Repository implements LogRepositoryInterface * @var DebugLogger */ private $debugLogger; - /** * @var ErrorLogger */ private $errorLogger; + /** + * @var DirectoryList + */ + private $dir; + /** + * @var DateTime + */ + private $dateTime; + /** + * @var File + */ + private $file; + /** + * @var Config + */ + private $config; /** * Repository constructor. * * @param DebugLogger $debugLogger * @param ErrorLogger $errorLogger + * @param DirectoryList $dir + * @param File $file + * @param DateTime $dateTime + * @param Config $config */ public function __construct( DebugLogger $debugLogger, - ErrorLogger $errorLogger + ErrorLogger $errorLogger, + DirectoryList $dir, + File $file, + DateTime $dateTime, + Config $config ) { $this->debugLogger = $debugLogger; $this->errorLogger = $errorLogger; + $this->dir = $dir; + $this->file = $file; + $this->dateTime = $dateTime; + $this->config = $config; } /** * @inheritDoc */ - public function addErrorLog(string $type, $data) + public function addErrorLog(string $type, $data): void { $this->errorLogger->addLog($type, $data); } @@ -53,8 +84,83 @@ public function addErrorLog(string $type, $data) /** * @inheritDoc */ - public function addDebugLog(string $type, $data) + public function addDebugLog(string $type, $data): void { $this->debugLogger->addLog($type, $data); } + + /** + * @inheritDoc + */ + public function addLog(string $type, $data): void + { + if ($this->config->isDebugMode()) { + $this->addDebugLog($type, $data); + } else { + $this->addErrorLog($type, $data); + } + } + + /** + * @inheritDoc + */ + public function getLogFilePath(string $type): ?string + { + try { + return sprintf(LogRepositoryInterface::LOG_FILE, $this->dir->getPath('var'), $type); + } catch (\Exception $exception) { + return null; + } + } + + /** + * @inheritDoc + */ + public function getLogEntriesAsArray(string $path, ?int $limit = null): ?array + { + try { + if (!$this->file->isExists($path)) { + return null; + } + + $stream = $this->file->fileOpen($path, 'r'); + $this->file->fileSeek($stream, 0, SEEK_END); + $pos = $this->file->fileTell($stream); + $numberOfLines = LogRepository::STREAM_DEFAULT_LIMIT; + while ($pos >= 0 && $numberOfLines > 0) { + $this->file->fileSeek($stream, $pos); + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $char = fgetc($stream); + if ($char === "\n") { + $numberOfLines--; + } + $pos--; + } + + $result = []; + // phpcs:ignore Magento2.Functions.DiscouragedFunction + while (!feof($stream) && $numberOfLines < LogRepository::STREAM_DEFAULT_LIMIT) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction + if ($line = fgets($stream)) { + $data = explode('] ', $line); + $date = ltrim(array_shift($data), '['); + $data = implode('] ', $data); + $data = explode(': ', $data); + unset($data[0]); + $type = $data[1] ?? '--'; + array_shift($data); + + $result[] = [ + 'date' => $this->dateTime->date('Y-m-d H:i:s', $date) . ' - ' . $type, + 'msg' => implode(': ', $data) + ]; + } + } + + $this->file->fileClose($stream); + return array_reverse($result); + } catch (\Exception $exception) { + return null; + } + } } diff --git a/composer.json b/composer.json index 797e9f8..6394b51 100755 --- a/composer.json +++ b/composer.json @@ -2,11 +2,11 @@ "name": "magmodules/magento2-messagebird", "description": "MessageBird integration for Magento 2", "type": "magento2-module", - "version": "1.0.1", + "version": "1.1.0", "require": { "magento/framework": ">=100.1.0", - "messagebird/php-rest-api": "^1.20", - "giggsey/libphonenumber-for-php": "^8.12" + "messagebird/php-rest-api": ">=1.20", + "giggsey/libphonenumber-for-php": ">=8.12" }, "license": [ "OSL-3.0", diff --git a/etc/adminhtml/system/branding.xml b/etc/adminhtml/system/branding.xml index 6566eb0..0c8ce0b 100755 --- a/etc/adminhtml/system/branding.xml +++ b/etc/adminhtml/system/branding.xml @@ -9,6 +9,6 @@ - Magmodules\MessageBird\Block\Adminhtml\MessageBird\Header + Magmodules\MessageBird\Block\Adminhtml\Design\Header diff --git a/etc/adminhtml/system/communication.xml b/etc/adminhtml/system/communication.xml index 5b7bce0..a603f21 100755 --- a/etc/adminhtml/system/communication.xml +++ b/etc/adminhtml/system/communication.xml @@ -15,7 +15,7 @@ - Magmodules\MessageBird\Block\Adminhtml\MessageBird\Heading + Magmodules\MessageBird\Block\Adminhtml\Design\Heading @@ -126,7 +126,7 @@ In collaboration with Mollie payments, we have made it possible to notify customers about unfinished payments using an e-mail. With the MessageBird integration, we can share this payment link directly with them through a text message so the customers can directly revive their order.

Please note that;
- This feature is only available when the Mollie Payments plugin is installed and enabled;
- The message is only sent if the customer didn't finish their order in a certain time period.

]]>
- Magmodules\MessageBird\Block\Adminhtml\MessageBird\Heading + Magmodules\MessageBird\Block\Adminhtml\Design\Heading
Logging Errors are always logged and written into the error.log file.]]> - Magmodules\MessageBird\Block\Adminhtml\MessageBird\Heading + Magmodules\MessageBird\Block\Adminhtml\Design\Heading @@ -23,15 +23,9 @@ Magento\Config\Model\Config\Source\Yesno magmodules_messagebird/debug/debug - + - - diff --git a/etc/adminhtml/system/general.xml b/etc/adminhtml/system/general.xml index 290cf97..c19896f 100755 --- a/etc/adminhtml/system/general.xml +++ b/etc/adminhtml/system/general.xml @@ -26,7 +26,7 @@ this link. Please note that sending messages with Test Mode disabled uses your available credits.]]> - Magmodules\MessageBird\Block\Adminhtml\MessageBird\Heading + Magmodules\MessageBird\Block\Adminhtml\Design\Heading diff --git a/etc/adminhtml/system/restrictions.xml b/etc/adminhtml/system/restrictions.xml index a6a8dd3..f7590ef 100755 --- a/etc/adminhtml/system/restrictions.xml +++ b/etc/adminhtml/system/restrictions.xml @@ -15,7 +15,7 @@ - Magmodules\MessageBird\Block\Adminhtml\MessageBird\Heading + Magmodules\MessageBird\Block\Adminhtml\Design\Heading diff --git a/etc/config.xml b/etc/config.xml index 6bbf957..a2e5c28 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,7 +8,7 @@ - v1.0.1 + v1.1.0 We successfully received your order with ID #{{order_id}} and awaiting your payment. diff --git a/view/adminhtml/requirejs-config.js b/view/adminhtml/requirejs-config.js deleted file mode 100755 index a9ab93d..0000000 --- a/view/adminhtml/requirejs-config.js +++ /dev/null @@ -1,6 +0,0 @@ -var config = { - deps: [ - 'Magmodules_MessageBird/js/button-functions', - 'Magmodules_MessageBird/js/show-more', - ] -}; diff --git a/view/adminhtml/templates/system/config/button/credentials.phtml b/view/adminhtml/templates/system/config/button/credentials.phtml index 597580b..639fdcd 100755 --- a/view/adminhtml/templates/system/config/button/credentials.phtml +++ b/view/adminhtml/templates/system/config/button/credentials.phtml @@ -11,38 +11,46 @@ use Magmodules\MessageBird\Block\Adminhtml\System\Config\Button\Credentials; * @var Credentials $block */ ?> + +
+
+ getButtonHtml() ?> + +
+ +
+
+ -getButtonHtml() ?> -
- - -
diff --git a/view/adminhtml/templates/system/config/button/debug.phtml b/view/adminhtml/templates/system/config/button/debug.phtml deleted file mode 100755 index 837e537..0000000 --- a/view/adminhtml/templates/system/config/button/debug.phtml +++ /dev/null @@ -1,21 +0,0 @@ - -
-
-
-
-
-getButtonHtml() ?> - diff --git a/view/adminhtml/templates/system/config/button/error.phtml b/view/adminhtml/templates/system/config/button/error.phtml deleted file mode 100755 index 9e1f367..0000000 --- a/view/adminhtml/templates/system/config/button/error.phtml +++ /dev/null @@ -1,20 +0,0 @@ - -
-
-
-
-
-getButtonHtml() ?> diff --git a/view/adminhtml/templates/system/config/button/log.phtml b/view/adminhtml/templates/system/config/button/log.phtml new file mode 100644 index 0000000..253f3c4 --- /dev/null +++ b/view/adminhtml/templates/system/config/button/log.phtml @@ -0,0 +1,42 @@ + + +
+
+
+
+
+
+
+ getButtonHtml('debug') ?> + + + +
+
+
+
+
+
+
+ getButtonHtml('error') ?> + + + +
+
\ No newline at end of file diff --git a/view/adminhtml/templates/system/config/button/version.phtml b/view/adminhtml/templates/system/config/button/version.phtml index a3276aa..ea2d829 100755 --- a/view/adminhtml/templates/system/config/button/version.phtml +++ b/view/adminhtml/templates/system/config/button/version.phtml @@ -11,14 +11,19 @@ use Magmodules\MessageBird\Block\Adminhtml\System\Config\Button\VersionCheck; * @var VersionCheck $block */ ?> -
+ +
escapeHtml($block->getVersion()); ?> - getButtonHtml() ?> -
-
-
+ +
+ getButtonHtml() ?> +
+ +
+
+
    diff --git a/view/adminhtml/templates/system/config/fieldset/header.phtml b/view/adminhtml/templates/system/config/fieldset/header.phtml index 733a2f9..d051af5 100755 --- a/view/adminhtml/templates/system/config/fieldset/header.phtml +++ b/view/adminhtml/templates/system/config/fieldset/header.phtml @@ -5,19 +5,63 @@ * * @var $block Magmodules\MessageBird\Block\Adminhtml\MessageBird\Header */ + +$logoMollie = $block->getViewFileUrl('Magmodules_MessageBird/images/logo-mollie.svg'); ?> -
    - -

    - escapeHtml(__('MessageBird for Magento')); ?>
    - escapeHtml(__('Deliver updates about payments, orders, invoices, back-in-stock notifications, - or price-change updates directly to your customers using the MessageBird integration.')); ?> -
    - escapeHtml(__('Use Mollie Payments to enable the option to sent payment reminders - to your customers around the world.')); ?> -

    - Download the Mollie Payment Plugin -
    -

    Developed in partnership with Magmodules

    + +
    +
    + + + + + + +
    +

    + escapeHtml(__('MessageBird for Magento')); ?> +

    +

    + escapeHtml( + __('Deliver updates about payments, orders, invoices, back-in-stock notifications, + ' . 'or price-change updates directly to your customers using the MessageBird integration.') + ); ?> + escapeHtml(__('Use Mollie Payments')); ?> + escapeHtml( + __('to enable the option to sent payment reminders to your customers around the world.') + ); ?> +

    +
    +
    + +
    +
    + MessageBird logo + + + escapeHtml(__('Download')); ?> + + escapeHtml(__('the Mollie Payment Plugin')); ?> + +
    + +
    + escapeHtml(__('Developed in partnership with')); ?> + Magmodules +
    + + \ No newline at end of file diff --git a/view/adminhtml/web/css/source/_icons.less b/view/adminhtml/web/css/source/_icons.less deleted file mode 100755 index 6f25221..0000000 --- a/view/adminhtml/web/css/source/_icons.less +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright © Magmodules.eu. All rights reserved. - * See COPYING.txt for license details. - */ - -@import "variables/_icons.less"; - -.lib-font-face( - @family-name: @icons-messagebird__font-name, - @font-path: @icons-messagebird__font-name-path, - @font-weight: normal, - @font-style: normal -); - -[class^="magmodules-messagebird-"]:before, -[class*=" magmodules-messagebird-"]:before { - font-family: @icons-messagebird__font-name; - font-style: normal; - font-weight: normal; - speak: never; - display: inline-block; - text-decoration: inherit; - width: 2.5rem; - margin-right: 0.5rem; - text-align: center; - font-variant: normal; - text-transform: none; - line-height: 2.5rem; - margin-left: 0.5rem; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -.magmodules-messagebird-icon__download-alt:before { - content: @magmodules-messagebird-icon__download-alt; - line-height: normal !important; -} - -.magmodules-messagebird-icon__list:before { - content: @magmodules-messagebird-icon__list; -} - -.magmodules-messagebird-icon__messagebird:before { - content: @magmodules-messagebird-icon__messagebird; -} - -.magmodules-messagebird-icon__list-unordered:before { - content: @magmodules-messagebird-icon__list-unordered; -} - -.magmodules-messagebird-icon__help-rounded:before { - content: @magmodules-messagebird-icon__help-rounded; -} - -.magmodules-messagebird-icon__thumbs-down:before { - content: @magmodules-messagebird-icon__thumbs-down; -} - -.magmodules-messagebird-icon__thumbs-up:before { - content: @magmodules-messagebird-icon__thumbs-up; -} - -.magmodules-messagebird-icon__font-icons:before { - content: @magmodules-messagebird-icon__font-icons; -} - -.magmodules-messagebird-icon__info-rounded1:before { - content: @magmodules-messagebird-icon__info-rounded1; -} - -.magmodules-messagebird-icon__download:before { - content: @magmodules-messagebird-icon__download; -} - -.magmodules-messagebird-icon__external-link:before { - content: @magmodules-messagebird-icon__external-link; -} - -.magmodules-messagebird-icon__notification-rounded:before { - content: @magmodules-messagebird-icon__notification-rounded; -} - -.magmodules-messagebird-icon__envelop:before { - content: @magmodules-messagebird-icon__envelop; -} - -.magmodules-messagebird-icon__list-unordered-four:before { - content: @magmodules-messagebird-icon__list-unordered-four; -} - -.magmodules-messagebird-icon__question-circled:before { - content: @magmodules-messagebird-icon__question-circled; -} - -.magmodules-messagebird-icon__list-thumbnails:before { - content: @magmodules-messagebird-icon__list-thumbnails; -} - -.magmodules-messagebird-icon__repeat:before { - content: @magmodules-messagebird-icon__repeat; -} - -.magmodules-messagebird-icon__info-rounded0:before { - content: @magmodules-messagebird-icon__info-rounded0; -} diff --git a/view/adminhtml/web/css/source/_mm-buttons.less b/view/adminhtml/web/css/source/_mm-buttons.less deleted file mode 100755 index ee6e294..0000000 --- a/view/adminhtml/web/css/source/_mm-buttons.less +++ /dev/null @@ -1,103 +0,0 @@ -#magmodules-messagebird-button { - - &_test, - &_help { - color: @color-white; - font-weight: 700; - font-size: 1.4rem; - padding: 1.9rem 3rem 1.5rem 1.5rem; - border: none; - text-shadow: 0px 1px 1px @magmodules-messagebird-color__3; - display: inline-block; - min-width: 180px; - vertical-align: top; - } - - &_help { - background: @magmodules-messagebird-color__1; - - &:hover { - color: @color-white; - text-decoration: none; - } - } - - &_test { - background: @magmodules-messagebird-bg__blue; - } - - &_version { - background: transparent; - padding-left: 0.85rem; - margin: -0.8rem 0 -1rem 2rem; - white-space: nowrap; - color: @magmodules-messagebird-version-btn-border; - border: 1px solid @magmodules-messagebird-color-gray_light; - transition: 0.3s color, 0.3s border; - - &:before { - content: @magmodules-messagebird-icon__repeat; - font-family: @icons-messagebird__font-name; - background-color: @magmodules-messagebird-version-btn-icon-bg; - color: @color-white; - border-radius: 50%; - width: 2.2rem; - height: 2.2rem; - display: inline-block; - line-height: 2.4rem; - font-size: 1.20rem; - transition: 0.3s background-color; - margin-right: 10px; - } - - &:hover { - color: @magmodules-messagebird-color__2; - - &::before { - background-color: @magmodules-messagebird-color__2; - } - } - } - - &_error, - &_debug { - border: none; - background: none; - padding: 0; - font-weight: 500; - font-size: 1.2rem; - color: @magmodules-messagebird-color__dark-gray; - - span { - text-decoration: underline; - } - - &:before { - content: @magmodules-messagebird-icon__external-link; - font-family: @icons-messagebird__font-name; - font-size: 1.5rem; - line-height: 1.5rem; - display: inline-block; - vertical-align: middle; - margin-right: 0.6rem; - } - } - - &_changelog { - background: transparent; - border: none; - text-decoration: underline; - padding: 0; - display: inline; - } -} - -.magmodules-messagebird-button__download:before { - margin-right: 0.6rem; - line-height: 1rem; -} - -.magmodules-messagebird-disabled { - position: absolute; - top: 0; -} diff --git a/view/adminhtml/web/css/source/_module.less b/view/adminhtml/web/css/source/_module.less index 84b1d23..b95dad2 100755 --- a/view/adminhtml/web/css/source/_module.less +++ b/view/adminhtml/web/css/source/_module.less @@ -1,373 +1,31 @@ -/** - * Copyright © Magmodules.eu. All rights reserved. - * See COPYING.txt for license details. - */ +// +// Imports +// --------------------------------------------- -@import '_icons.less'; -@import '_mm-buttons'; -@import './variables/_mm-colors.less'; +@import './variables/_colors.less'; +@import './module/ui/_button.less'; +@import './module/ui/_modal.less'; -.admin__menu .item-menu.parent.level-0 > a:before { - content: @magmodules-messagebird-icon__messagebird; - font-family: @icons-messagebird__font-name; - font-size: 2rem; - padding-top: .2rem; -} - -.messagebird-extensions .title:before { - content: ''; - display: inline-block; - background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI0LjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAxNjQuNSAxMzgiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDE2NC41IDEzODsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiM0QTQ1NDI7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMTQ3LjYsMjQuNWMtNi42LDAtMTIuNSwzLjMtMTYuMSw4LjNsLTI0LjMsMzQuMWMtMC45LDEuMy0yLjQsMi4xLTQsMi4xYy0yLjcsMC00LjktMi4yLTQuOS00LjkKCWMwLTEsMC4zLTIsMC44LTIuN2wyMC41LTMwLjdjMi4xLTMuMSwzLjMtNi45LDMuMy0xMWMwLTEwLjktOC44LTE5LjctMTkuNy0xOS43SDB2MTkuN2g4OC40YzAsNS40LTQuNCw5LjktOS45LDkuOUgwCgljMCw3LDEuNSwxMy43LDQuMSwxOS43aDY0LjVjMCw1LjQtNC40LDkuOS05LjksOS45SDkuOGM5LDEyLDIzLjMsMTkuNywzOS41LDE5LjdoMjQuM2MyLjcsMCw0LjksMi4yLDQuOSw0LjlzLTIuMiw0LjktNC45LDQuOUg0OS4zCglsLTMzLDQ5LjNINzZjMjcuMywwLDUwLjUtMTcuOCw1OC42LTQyLjRsMTEuMS0zMy43YzMuNi0xMC45LDEwLjItMjAuNSwxOC44LTI3LjhDMTYxLjEsMjguNCwxNTQuOCwyNC41LDE0Ny42LDI0LjVMMTQ3LjYsMjQuNXoKCSBNMTQ3LjYsMzguMWMtMiwwLTMuNy0xLjctMy43LTMuN3MxLjctMy43LDMuNy0zLjdzMy43LDEuNywzLjcsMy43UzE0OS43LDM4LjEsMTQ3LjYsMzguMXoiLz4KPHRleHQgdHJhbnNmb3JtPSJtYXRyaXgoMSAwIDAgMSAtNTY5LjAyOTggLTE2OC45NzgpIiBzdHlsZT0iZm9udC1mYW1pbHk6J015cmlhZFByby1SZWd1bGFyJzsgZm9udC1zaXplOjEycHg7Ij4jNGE0NTQyPC90ZXh0Pgo8L3N2Zz4K); - background-size: 25px; - background-repeat: no-repeat; - width: 35px; - height: 35px; - float: left; -} - -[data-ui-id="menu-messagebird-core-menu"] strong:before { - display: none; -} - -ul[role="menu"] [data-ui-id^="menu-messagebird"] strong:before { - content: ''; - display: inline-block; - background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI0LjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAxNjQuNSAxMzgiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDE2NC41IDEzODsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiNBNzlEOTU7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMTQ3LjYsMjQuNWMtNi42LDAtMTIuNSwzLjMtMTYuMSw4LjNsLTI0LjMsMzQuMWMtMC45LDEuMy0yLjQsMi4xLTQsMi4xYy0yLjcsMC00LjktMi4yLTQuOS00LjkKCWMwLTEsMC4zLTIsMC44LTIuN2wyMC41LTMwLjdjMi4xLTMuMSwzLjMtNi45LDMuMy0xMWMwLTEwLjktOC44LTE5LjctMTkuNy0xOS43SDB2MTkuN2g4OC40YzAsNS40LTQuNCw5LjktOS45LDkuOUgwCgljMCw3LDEuNSwxMy43LDQuMSwxOS43aDY0LjVjMCw1LjQtNC40LDkuOS05LjksOS45SDkuOGM5LDEyLDIzLjMsMTkuNywzOS41LDE5LjdoMjQuM2MyLjcsMCw0LjksMi4yLDQuOSw0LjlzLTIuMiw0LjktNC45LDQuOUg0OS4zCglsLTMzLDQ5LjNINzZjMjcuMywwLDUwLjUtMTcuOCw1OC42LTQyLjRsMTEuMS0zMy43YzMuNi0xMC45LDEwLjItMjAuNSwxOC44LTI3LjhDMTYxLjEsMjguNCwxNTQuOCwyNC41LDE0Ny42LDI0LjVMMTQ3LjYsMjQuNXoKCSBNMTQ3LjYsMzguMWMtMiwwLTMuNy0xLjctMy43LTMuN3MxLjctMy43LDMuNy0zLjdzMy43LDEuNywzLjcsMy43UzE0OS43LDM4LjEsMTQ3LjYsMzguMXoiLz4KPHRleHQgdHJhbnNmb3JtPSJtYXRyaXgoMSAwIDAgMSAtNTY5LjAyOTggLTE2OC45NzgpIiBzdHlsZT0iZm9udC1mYW1pbHk6J015cmlhZFByby1SZWd1bGFyJzsgZm9udC1zaXplOjEycHg7Ij4jNGE0NTQyPC90ZXh0Pgo8L3N2Zz4K); - background-size: 25px; - background-repeat: no-repeat; - width: 35px; - height: 35px; - float: left; -} - -.magmodules-messagebird-header, -.magmodules-messagebird-heading-block { - border: 0.1rem solid @color-gray90; - border-left: 3px solid @bordercolor; - font-size: 1.3rem; - display: flex; - text-align: left; -} - -.magmodules-messagebird-heading-block { - background: @color-white-fog; - padding: 1rem; - text-align: left; - color: @magmodules-messagebird-color__1; -} - -.magmodules-messagebird-heading-comment { - padding: 1rem 0rem 0rem 1rem; - font-size: 1.2rem; - line-height: 2.5rem; - border-left: 4px solid @color-white-fog; -} - -.magmodules-messagebird-recommend { - color: @bordercolor; - font-weight: 600; - display: block; - padding: 3px 0px 3px 0px; -} - -.magmodules-messagebird-header { - background: @color-white-fog no-repeat left 0.8rem center / 6rem; - padding: 1.8rem 1.8rem 1.8rem 8.8rem; - - &-text { - margin-top: 0.7rem; - line-height: 2.2rem; - } - - &-links { - i, - a { - color: @magmodules-messagebird-color__3; - display: inline-block; - } - - a { - margin-right: 2rem; - } - - i { - font-size: 1.75rem; - vertical-align: middle; - line-height: 1.5rem; - } - } - - &-actions { - margin-left: auto; - max-width: 50%; - text-align: center; +@import './module/_header.less'; +@import './module/_version.less'; +@import './module/_debug.less'; - i { - font-size: 2.5rem; - vertical-align: middle; - line-height: 1.5rem; - } - } -} - -#row_messagebird_messagebird_debug { - - &_debug_button { +@import './module/extend/_credentials.less'; - .value { - padding-top: 1rem; - } - } - - &_error_button { - - .value { - padding-top: 0.5rem; - } - } -} -#row_messagebird_messagebird_debug_selftest_heading { +// +// Common styles +// --------------------------------------------- - .magmodules-messagebird-heading-block { +.admin__page-nav._collapsed.magmodules-extensions .title:before { display: none; - } } -.magmodules-messagebird-result_version-wrapper { - align-items: center; - display: flex; - position: relative; - margin-top: -0.3rem; - margin-bottom: -0.3rem; - - .loading-mask, - .popup-loading { - position: absolute; - padding: 0; - height: 100%; - top: 0; - left: 0; - width: 100%; - margin: 0; - } - - .loading-mask { - height: 200%; - top: -50%; - } - - .popup-loading:after { - margin: 0; - left: 0; - top: 0; - height: 100%; - width: 100%; +.admin__page-nav._collapsed.magmodules-extensions .title, +.admin__page-nav._collapsed._show.magmodules-extensions .title { + background-image: url('@{baseDir}Magmodules_MessageBird/images/logo-magmodules.svg') !important; + background-position: 15px center; background-repeat: no-repeat; - background-position: center; - background-size: contain; - } -} - -.magmodules-messagebird-version { - border: 0 solid @color-gray68; - margin-left: 1rem; - padding: .6rem 1em .6rem 0.4rem; - white-space: nowrap; - font-weight: 600; - - a { - color: inherit; - text-decoration: underline; - } - - span { - font-weight: 500; - } - - &:before { - border-radius: 50%; - color: @color-white; - width: 2.4rem; - height: 2.4rem; - line-height: 2.6rem; - font-size: 1.2rem; - margin-right: .5rem; - } - - &.magmodules-messagebird-icon__thumbs-up:before { - background-color: @magmodules-messagebird-color__green-dark; - line-height: 2.5rem; - } - - &.magmodules-messagebird-icon__thumbs-down:before { - background-color: @magmodules-messagebird-color__yellow; - } -} - -.magmodules-messagebird-result { - - &_error-item, - &_debug-item { - flex-wrap: wrap; - display: flex; - padding: 1.5rem 1rem; - background: @color-white; - - &:nth-child(odd) { - background: @magmodules-messagebird-bg__odd; - } - - strong { - margin-bottom: 0.7rem; - margin-right: 20px; - } - } - - &_test-item { - display: flex; - border-bottom: 0.1rem solid @color-white; - padding: 1.5rem 0 1.5rem 1rem; - min-height: 75px; - - &:nth-child(odd) { - background: @magmodules-messagebird-bg__odd; - } - - &:before { - margin-right: 2rem; - font-size: 2.5rem; - font-family: @icons-messagebird__font-name; - } - - &.success:before { - content: @magmodules-messagebird-icon__notification-rounded; - color: @magmodules-messagebird-color__green-light; - } - - &.success { - color: @magmodules-messagebird-color__green-light; - } - - &.failed { - - &:before { - content: @magmodules-messagebird-icon__info-rounded0; - color: @magmodules-messagebird-color__red; - } - - em { - color: @magmodules-messagebird-color__orange; - } - } - - strong { - flex-basis: 10%; - font-weight: 600; - } - - span { - flex-basis: 60%; - } - - .magmodules-messagebird-icon__help-rounded { - color: @magmodules-messagebird-color__red; - font-size: 2rem; - margin-left: auto; - - &:hover { - text-decoration: none; - } - } - } -} - -#magmodules-messagebird-result_changelog .result { - list-style-type: none; - padding: 0; - margin: 1rem 0 0; -} - -.magmodules-messagebird-result_changelog-item { - padding: 0.8rem 1.6rem 1.6rem; - - - &:nth-child(odd) { - background: #F6F8FA; - } - - &:nth-child(even) { - background: #EDEFF1; - } - - & > div { - margin-top: 1rem; - } - - h1 { - font-size: 1.8rem; - } - - .magmodules-messagebird-divider { - display: inline-block; - padding: 0 0.4rem; - font-size: 1.8rem; - opacity: 0.5; - } -} - -.modal-content .popup-loading { - padding: 50px 0 10px; -} - -.modal-slide .modal-header .action-close { - padding: 2.1rem 2.6rem; -} - -.magmodules-messagebird-show-more-active { - - .magmodules-messagebird-show-more-block { - opacity: 1; - font-size: inherit; - max-height: 999em; - - br { - display: initial; - } - } - - .magmodules-messagebird-show-more-actions { - - .magmodules-messagebird-show-btn-more { - display: none; - } - - .magmodules-messagebird-show-btn-less { - display: initial; - } - } -} - -.magmodules-messagebird-show-more-block { - opacity: 0; - max-height: 0; - font-size: 0; - transition: 0.3s ease; - - br { - display: none; - } -} - -/*buttons*/ -.magmodules-messagebird-show-more-actions { - - a { - text-decoration: underline; - color: @magmodules-messagebird-color__orange; - } - - .magmodules-messagebird-show-btn-less { - display: none; - } + text-indent: 50px; + background-size: auto 70%; } diff --git a/view/adminhtml/web/css/source/module/_debug.less b/view/adminhtml/web/css/source/module/_debug.less new file mode 100755 index 0000000..6f50a03 --- /dev/null +++ b/view/adminhtml/web/css/source/module/_debug.less @@ -0,0 +1,84 @@ +// +// [ Debug ]: Heading +// --------------------------------------------- + +form[action*="magmodules_messagebird"] { + .magmodules-messagebird-variables(); + + .mm-ui-heading-block { + display: flex; + gap: 16px; + justify-content: space-between; + padding: 1rem; + + border-left: 3px solid @mm-ui-color8; + background-color: @mm-ui-color1; + + color: @mm-ui-color4; + font-size: 1.3rem; + text-align: left; + } + + .mm-ui-heading-comment { + padding: 1.2rem 0 0 1rem; + font-size: 1.2rem; + line-height: 2rem; + border-left: 3px solid @mm-ui-color1; + } + + + // + // [ Debug ]: Show more/less + // --------------------------------------------- + .mm-ui-show-more-actions { + a { + padding: 4px 12px; + border-radius: 12px; + background-color: fade(@mm-ui-color8, 60%); + + color: @mm-ui-color5; + font: @font-weight__semibold 1.2rem @font-family__base; + text-decoration: none; + transition: .3s; + + &:hover { + background-color: fade(@mm-ui-color8, 90%); + } + } + } + + .mm-ui-heading-comment { + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + + &.show { + -webkit-line-clamp: initial; + } + + span { + display: block; + + & + span { + margin-top: 10px; + } + } + } + + // + // [ Debug ]: Actions + // --------------------------------------------- + + #row_ui_connect_general_debug_debug_button .value { + padding-top: 1rem; + } + + #row_ui_connect_general_debug_error_button .value { + padding-top: .5rem; + } + + #row_ui_connect_general_debug_selftest_button .mm-ui-heading-block { + display: none; + } +} diff --git a/view/adminhtml/web/css/source/module/_header.less b/view/adminhtml/web/css/source/module/_header.less new file mode 100755 index 0000000..cb5d488 --- /dev/null +++ b/view/adminhtml/web/css/source/module/_header.less @@ -0,0 +1,71 @@ +// +// Header +// --------------------------------------------- + +form[action*="magmodules_messagebird"] { + .magmodules-messagebird-variables(); + + .mm-ui-header { + display: grid; + gap: 2.4rem; + margin-bottom: 2.4rem; + padding: 2.4rem; + + border-radius: .8rem; + background: @mm-ui-color-messagebird1; + color: @mm-ui-color1; + line-height: 2.4rem; + + p { + font-size: 1.6rem; + line-height: 2em; + + span { + color: @mm-ui-color8; + font-weight: 600; + } + } + + a { + color: @mm-ui-color8; + font-weight: 600; + text-decoration: none; + transition: .3s; + text-decoration: underline; + + &:hover { + color: darken(@mm-ui-color8, 15%); + } + } + } + + .mm-ui-header-up-box { + display: grid; + gap: 2.8rem; + align-items: flex-start; + grid-template-columns: auto 1fr; + + a { + width: 90px; + margin-top: .8rem; + } + } + + .mm-ui-header-down-box { + display: flex; + justify-content: space-between; + align-items: flex-end; + gap: 2.8rem; + + .mollie { + display: grid; + gap: .6rem; + } + } + + .mm-ui-header-title { + color: @mm-ui-color1; + font-size: 2.8rem; + font-weight: 600; + } +} diff --git a/view/adminhtml/web/css/source/module/_version.less b/view/adminhtml/web/css/source/module/_version.less new file mode 100755 index 0000000..2550560 --- /dev/null +++ b/view/adminhtml/web/css/source/module/_version.less @@ -0,0 +1,111 @@ +// +// Version block +// --------------------------------------------- + +form[action*="magmodules_messagebird"] { + .magmodules-messagebird-variables(); + + .mm-ui-result_version-wrapper { + position: relative; + display: flex; + align-items: flex-start; + min-height: 31px; + margin-top: -.8rem; + margin-bottom: -.3rem; + + > span { + position: relative; + top: 8px; + } + + .loading-mask { + top: 0 !important; + height: 100% !important; + + & ~ .button-wrapper { + display: none; + } + + // & ~ span { + // margin-top: 1rem; + // } + + & ~ #mm-ui-result_version { + position: relative; + top: 5px; + min-height: 31px; + } + } + + .button-wrapper { + position: relative; + margin-left: 15px; + } + + .loading-mask, + .popup-loading { + position: absolute; + padding: 0; + height: 100%; + top: 0; + left: 0; + width: 100%; + margin: 0; + } + + .loading-mask { + height: 200%; + top: -50%; + } + + .popup-loading:after { + margin: 0; + left: 0; + top: 0; + height: 100%; + width: 100%; + background-repeat: no-repeat; + background-position: center; + background-size: contain; + } + } + + .mm-ui-version { + position: relative; + top: -4px; + display: block; + margin-left: 1rem; + padding: .6rem 1em .6rem .4rem; + white-space: nowrap; + font-weight: @font-weight__semibold; + + span { + color: darken(@mm-ui-color6, 15%); + } + } + + .mm-ui-source-blocked { + position: relative; + top: -5px; + display: flex; + align-items: flex-start; + gap: 12px; + margin-left: 12px; + padding: 6px 16px 8px; + border-radius: 8px; + background-color: fade(@mm-ui-color8, 50%); + font-size: 12px; + + svg { + margin-top: 2px; + width: 20px; + min-width: 20px; + } + + span { + position: relative; + top: 5px; + margin-bottom: 7px; + } + } +} diff --git a/view/adminhtml/web/css/source/module/extend/_credentials.less b/view/adminhtml/web/css/source/module/extend/_credentials.less new file mode 100644 index 0000000..d052898 --- /dev/null +++ b/view/adminhtml/web/css/source/module/extend/_credentials.less @@ -0,0 +1,17 @@ +form[action*="magmodules_messagebird"] { + .magmodules-messagebird-variables(); + + .mm-ui-action { + display: flex; + align-items: center; + gap: 1.2rem; + } + + .mm-ui-connecting { + opacity: .75; + } + + .mm-ui-result:not(:empty) { + margin-top: 1.2rem; + } +} \ No newline at end of file diff --git a/view/adminhtml/web/css/source/module/ui/_button.less b/view/adminhtml/web/css/source/module/ui/_button.less new file mode 100755 index 0000000..1e386b7 --- /dev/null +++ b/view/adminhtml/web/css/source/module/ui/_button.less @@ -0,0 +1,121 @@ +// +// [ Buttons ] +// --------------------------------------------- + +form[action*="magmodules_messagebird"] { + .magmodules-messagebird-variables(); + + .buttons() { + display: flex; + align-items: center; + justify-content: center; + gap: 14px; + min-width: 130px; + padding: 1.2rem 1.6rem; + + border: 0; + border-radius: 8px; + font: @font-weight__bold 1.4rem @font-family__base; + text-decoration: none; + transition: .3s; + + i[class*="icon"] { + width: 25px; + height: 25px; + transition: .3s; + } + } + + // Buttons + #mm-ui-button_help { + .buttons(); + + background-color: @mm-ui-color4; + color: @mm-ui-color1; + + &:hover { + background-color: @mm-ui-color5; + } + } + + #mm-ui-button_test { + .buttons(); + + background-color: @mm-ui-color8; + color: @mm-ui-color5; + + &:hover { + background-color: darken(@mm-ui-color8, 10%); + } + } + + #mm-ui-button_debug, + #mm-ui-button_error, + #mm-ui-button_version, + #mm-ui-button_credentials { + .buttons(); + + padding: .8rem 1.6rem; + border: 1px solid fade(@mm-ui-color3, 80%); + background-color: transparent; + color: darken(@mm-ui-color3, 15%); + font: @font-weight__semibold 1.3rem @font-family__base; + + &:hover { + color: @mm-ui-color4; + } + } + + // Link buttons + #mm-ui-button_changelog { + display: inline; + padding: 0; + + border: none; + background: transparent; + + color: fade(@mm-ui-color4, 70%); + text-decoration: underline; + text-underline-offset: 2px; + transition: .3s; + + &:hover { + color: @mm-ui-color4; + } + } + + .mm-ui-debug-button-wrapper { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px 32px; + } + + .mm-ui-button-wrapper { + position: relative; + } + + #mm-ui-button_debug, + #mm-ui-button_error { + padding: 1rem 1.6rem 1rem 4.2rem; + + & + svg { + position: absolute; + top: 10px; + left: 14px; + fill: fade(@mm-ui-color4, 70%); + width: 20px; + height: 20px; + transition: .3s; + pointer-events: none; + } + + &:hover + svg._debug { + fill: darken(@mm-ui-color8, 20%); + } + + &:hover + svg._error { + fill: @mm-ui-color7; + } + } +} diff --git a/view/adminhtml/web/css/source/module/ui/_modal.less b/view/adminhtml/web/css/source/module/ui/_modal.less new file mode 100755 index 0000000..33c48ef --- /dev/null +++ b/view/adminhtml/web/css/source/module/ui/_modal.less @@ -0,0 +1,222 @@ +// +// [ Modal popup ] +// --------------------------------------------- + +.mm-ui-modal.messagebird { + .magmodules-messagebird-variables(); + + .popup-loading { + padding: 50px 0 10px; + } + + .modal-inner-wrap { + border-radius: 8px; + } + + .modal-header { + padding-bottom: 0; + + .modal-title { + padding: 0 5.7rem 12px 0; + margin-right: 0; + border-bottom: 1px solid @mm-ui-color2; + } + + .action-close { + padding: 2.1rem 2.6rem; + } + } + + .modal-content { + padding-bottom: 0; + + > div { + padding: 12px 0; + } + + ul { + display: grid; + grid-gap: 6px; + margin: 0; + list-style: none; + + > li { + padding: 10px 15px; + + &:nth-child(even) { + background: fade(@mm-ui-color2, 50%); + } + + & > div { + margin-top: 1rem; + } + } + + .mm-ui-divider { + display: inline-block; + padding: 0 0.4rem; + font-size: 1.8rem; + opacity: .5; + } + } + + .mm-ui-result_test-item { + position: relative; + display: grid; + gap: 20px; + grid-template-columns: 22px 1fr; + margin-bottom: 4px; + padding: 24px; + background-color: fade(@mm-ui-color2, 50%); + + > div { + margin: 0 !important; + padding: 0 !important; + + > div { + margin-top: 6px; + padding-left: 0; + } + } + + svg { + width: 22px; + height: 22px; + } + + div strong { + padding-right: 185px; + color: @mm-ui-color5 !important; + font-size: 1.6rem; + + &::before { + display: none; + } + } + + em { + display: block; + margin-top: 8px; + padding-left: 8px; + border-left: 4px solid @mm-ui-color8; + color: fade(@mm-ui-color4, 70%); + } + + &.success { + border-left: 8px solid @mm-ui-color8; + } + + &.failed { + border-left: 8px solid @mm-ui-color5; + } + + .mm-ui-icon__help-rounded { + position: absolute; + top: 20px; + right: 20px; + + display: flex; + gap: 12px; + align-items: center; + margin: 0; + padding: 8px 16px; + + border-radius: 12px; + background-color: @mm-ui-color8; + color: @mm-ui-color5; + text-decoration: none; + transition: .3s; + + svg { + width: 12px; + height: 12px; + } + + &:hover { + background-color: darken(@mm-ui-color8, 15%); + } + } + } + + .mm-ui-result_changelog-item { + margin-bottom: 4px; + padding: 24px; + background-color: fade(@mm-ui-color2, 50%); + border-left: 8px solid @mm-ui-color8; + + u { + display: block; + margin-bottom: -8px; + padding-left: 8px; + border-left: 4px solid @mm-ui-color8; + color: fade(@mm-ui-color4, 70%); + } + } + } + + .modal-footer { + display: flex; + justify-content: flex-end; + gap: 16px; + margin: 0 30px; + padding: 25px 0; + border-top: 1px solid @mm-ui-color2; + } + + .mm-ui-source-blocked { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 8px 16px 10px; + margin: 12px 0; + border-radius: 8px; + background-color: fade(@mm-ui-color8, 50%); + + svg { + width: 20px; + } + } + + // Buttons + .buttons() { + display: flex; + align-items: center; + justify-content: center; + gap: 14px; + min-width: 130px; + padding: 1.2rem 1.6rem; + + border: 0; + border-radius: 8px; + font: @font-weight__bold 1.4rem @font-family__base; + text-decoration: none; + text-transform: uppercase; + transition: .3s; + } + + .mm-ui-button__download { + .buttons(); + + background-color: @mm-ui-color4; + color: @mm-ui-color1; + + &:hover { + background-color: @mm-ui-color5; + } + + & + button { + display: none; + } + } + + .mm-ui-modal-close { + .buttons(); + + background-color: @mm-ui-color2; + color: @mm-ui-color4; + + &:hover { + background-color: darken(@mm-ui-color2, 5%); + } + } +} diff --git a/view/adminhtml/web/css/source/variables/_colors.less b/view/adminhtml/web/css/source/variables/_colors.less new file mode 100755 index 0000000..1985b3f --- /dev/null +++ b/view/adminhtml/web/css/source/variables/_colors.less @@ -0,0 +1,12 @@ +.magmodules-messagebird-variables() { + @mm-ui-color1: #f8f8f8; + @mm-ui-color2: #edeff1; + @mm-ui-color3: #b4b4b4; + @mm-ui-color4: #514943; + @mm-ui-color5: #41362f; + @mm-ui-color6: #79a12d; + @mm-ui-color7: #b41f1f; + @mm-ui-color8: #f9e063; + + @mm-ui-color-messagebird1: #001240; +} diff --git a/view/adminhtml/web/css/source/variables/_icons.less b/view/adminhtml/web/css/source/variables/_icons.less deleted file mode 100755 index b928565..0000000 --- a/view/adminhtml/web/css/source/variables/_icons.less +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright © Magmodules.eu. All rights reserved. - * See COPYING.txt for license details. - */ - -@icons-messagebird__font-name: 'messagebird-icons'; -@icons-messagebird__file-name: 'messagebird-icons'; -@icons-messagebird__font-name-path: '@{baseDir}Magmodules_MessageBird/fonts/@{icons-messagebird__file-name}/@{icons-messagebird__file-name}'; - -@magmodules-messagebird-icon__download-alt: '\e800'; -@magmodules-messagebird-icon__list: '\e801'; -@magmodules-messagebird-icon__messagebird: '\e802'; -@magmodules-messagebird-icon__list-unordered: '\e803'; -@magmodules-messagebird-icon__help-rounded: '\e804'; -@magmodules-messagebird-icon__thumbs-down: '\e805'; -@magmodules-messagebird-icon__thumbs-up: '\e806'; -@magmodules-messagebird-icon__font-icons: '\e807'; -@magmodules-messagebird-icon__info-rounded1: '\e808'; -@magmodules-messagebird-icon__download: '\e809'; -@magmodules-messagebird-icon__external-link: '\e80a'; -@magmodules-messagebird-icon__notification-rounded: '\e80b'; -@magmodules-messagebird-icon__envelop: '\e80c'; -@magmodules-messagebird-icon__list-unordered-four: '\e80d'; -@magmodules-messagebird-icon__question-circled: '\e80e'; -@magmodules-messagebird-icon__list-thumbnails: '\e80f'; -@magmodules-messagebird-icon__repeat: '\e810'; -@magmodules-messagebird-icon__info-rounded0: '\e811'; - diff --git a/view/adminhtml/web/css/source/variables/_mm-colors.less b/view/adminhtml/web/css/source/variables/_mm-colors.less deleted file mode 100755 index 4474515..0000000 --- a/view/adminhtml/web/css/source/variables/_mm-colors.less +++ /dev/null @@ -1,17 +0,0 @@ -@magmodules-messagebird-color__orange: #d85321; -@magmodules-messagebird-bg__blue: #007dbd; -@magmodules-messagebird-color__green-light: #79a12d; -@magmodules-messagebird-color-gray_light: #b4b4b4; -@magmodules-messagebird-color__red: #ce2525; -@magmodules-messagebird-color__green-dark: #2e701e; -@magmodules-messagebird-color__yellow: #d3b83a; -@magmodules-messagebird-border-color: #4f4943; -@magmodules-messagebird-color__dark-gray: #626262; -@magmodules-messagebird-bg__even: #edeff1; -@magmodules-messagebird-bg__odd: #f6f8fa; -@magmodules-messagebird-version-btn-border: #948f8b; -@magmodules-messagebird-version-btn-icon-bg: #96928e; -@magmodules-messagebird-color__1: #504944; -@magmodules-messagebird-color__2: #514943; -@magmodules-messagebird-color__3: #41362f; -@bordercolor: @magmodules-messagebird-color__orange; diff --git a/view/adminhtml/web/css/styles.css b/view/adminhtml/web/css/styles.css deleted file mode 100755 index cf1d7a7..0000000 --- a/view/adminhtml/web/css/styles.css +++ /dev/null @@ -1,164 +0,0 @@ -.mm-comment-messagebird { - padding: 10px 0px; - font-size: 12px; -} - -.mm-heading-messagebird { - color: #666; - text-align: left; - border: 1px solid rgba(229, 229, 229, 0.27); - border-left: 2px solid #ea4c00; - font-size: 14px; - margin: 20px 0 0; - padding: 5px 5px 5px 10px; - background: #f8f8f8; -} - -.mm-block-messagebird { - background: #001240; - border: 1px solid #e5e5e5; - border-left: 2px solid #ea4c00; - /* font-size: 12px; */ - color: white; - margin-bottom: auto; - padding: 5rem 3.5rem 13rem 3.5rem; -} - -.mm-block-messagebird table { - width: 520px !important; -} - -.mm-block-messagebird strong { - font-size: 1.7rem; - font-weight: 600; - margin-bottom: 10px; - display: inline-block; -} - -.mm-block-messagebird p { - /* font-size: 12px; */ - padding: 0 0 0.3em; - color: white; -} - -.mm-block-messagebird tr a { - color: white; - margin-top: 3px; - display: block; -} - -.mm-block-messagebird tr td { - padding: 5px 0px 0px 0px !important; - color: white; -} - -.mm-block-messagebird .accordion .form-inline .config td { - padding: 0.8rem 1.5rem 0 0; -} - -.mm-block-messagebird tr .signup a { - color: white; - font-weight: bold; -} - -.mm-block-messagebird .helpbutton { - width: 110px; - height: 110px; - float: left; - background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI0LjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAxNjQuNSAxMzgiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDE2NC41IDEzODsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiNGRkZGRkY7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMTQ3LjYsMjQuNWMtNi42LDAtMTIuNSwzLjMtMTYuMSw4LjNsLTI0LjMsMzQuMWMtMC45LDEuMy0yLjQsMi4xLTQsMi4xYy0yLjcsMC00LjktMi4yLTQuOS00LjkKCWMwLTEsMC4zLTIsMC44LTIuN2wyMC41LTMwLjdjMi4xLTMuMSwzLjMtNi45LDMuMy0xMWMwLTEwLjktOC44LTE5LjctMTkuNy0xOS43SDB2MTkuN2g4OC40YzAsNS40LTQuNCw5LjktOS45LDkuOUgwCgljMCw3LDEuNSwxMy43LDQuMSwxOS43aDY0LjVjMCw1LjQtNC40LDkuOS05LjksOS45SDkuOGM5LDEyLDIzLjMsMTkuNywzOS41LDE5LjdoMjQuM2MyLjcsMCw0LjksMi4yLDQuOSw0LjlzLTIuMiw0LjktNC45LDQuOUg0OS4zCglsLTMzLDQ5LjNINzZjMjcuMywwLDUwLjUtMTcuOCw1OC42LTQyLjRsMTEuMS0zMy43YzMuNi0xMC45LDEwLjItMjAuNSwxOC44LTI3LjhDMTYxLjEsMjguNCwxNTQuOCwyNC41LDE0Ny42LDI0LjVMMTQ3LjYsMjQuNXoKCSBNMTQ3LjYsMzguMWMtMiwwLTMuNy0xLjctMy43LTMuN3MxLjctMy43LDMuNy0zLjdzMy43LDEuNywzLjcsMy43UzE0OS43LDM4LjEsMTQ3LjYsMzguMXoiLz4KPHRleHQgdHJhbnNmb3JtPSJtYXRyaXgoMSAwIDAgMSAtNTY5LjAyOTggLTE2OC45NzgpIiBzdHlsZT0iZm9udC1mYW1pbHk6J015cmlhZFByby1SZWd1bGFyJzsgZm9udC1zaXplOjEycHg7Ij4jNGE0NTQyPC90ZXh0Pgo8L3N2Zz4K); - background-size: 90px; - background-repeat: no-repeat; -} - -.mm-block-messagebird .mollie { - width: 300px; - height: 50px; - float: left; - background-image: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjIwMCIgdmlld0JveD0iMCAwIDY3NyAyMDAiIHdpZHRoPSI2NzciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0iI2ZmZiI+PHBhdGggY2xpcC1ydWxlPSJldmVub2RkIiBkPSJtMjg2LjM0MiA2NS4zMTMyYy0zNy4xNzUgMC02Ny4zNSAzMC4yNDE1LTY3LjM1IDY3LjM0MzggMCAzNy4xMDEgMzAuMjQ1IDY3LjM0MyA2Ny4zNSA2Ny4zNDMgMzcuMTA2IDAgNjcuMzUtMzAuMjQyIDY3LjM1LTY3LjM0MyAwLTM3LjEwMjMtMzAuMTc0LTY3LjM0MzgtNjcuMzUtNjcuMzQzOHptMCAxMDIuODM0OGMtMTkuNTMzIDAtMzUuNDI1LTE1Ljg5LTM1LjQyNS0zNS40MjFzMTUuODkyLTM1LjQyMjIgMzUuNDI1LTM1LjQyMjIgMzUuNDI2IDE1Ljg5MTIgMzUuNDI2IDM1LjQyMjItMTUuODkzIDM1LjQyMS0zNS40MjYgMzUuNDIxeiIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0ibTUxMC4zNzUgNDIuMDAyMWMxMS42IDAgMjEuMDAzLTkuNDAyNSAyMS4wMDMtMjEuMDAxMSAwLTExLjU5ODUxLTkuNDAzLTIxLjAwMS0yMS4wMDMtMjEuMDAxLTExLjU5OSAwLTIxLjAwMyA5LjQwMjQ5LTIxLjAwMyAyMS4wMDEgMCAxMS41OTg2IDkuNDA0IDIxLjAwMTEgMjEuMDAzIDIxLjAwMTF6Ii8+PHBhdGggY2xpcC1ydWxlPSJldmVub2RkIiBkPSJtMTQ4Ljg0MiA2NS4zODMzYy0xLjc1LS4xNC0zLjQzMS0uMjEtNS4xODEtLjIxLTE2LjI0MiAwLTMxLjY0NCA2LjY1MDMtNDIuNzA2IDE4LjQxMDktMTEuMDYxNy0xMS42OTA2LTI2LjM5NC0xOC40MTA5LTQyLjQ5NjQtMTguNDEwOS0zMi4yMDQ3IDAtNTguNDU4NiAyNi4xODEzLTU4LjQ1ODYgNTguMzgyN3Y3My43MTRoMzEuNTA0N3YtNzIuODA0YzAtMTMuMzcgMTAuOTkxNi0yNS42OTEgMjMuOTQzNS0yNy4wMjExLjkxMDEtLjA3IDEuODIwMy0uMTQgMi42NjA0LS4xNCAxNC41NjIxIDAgMjYuNDYzOSAxMS45MDAxIDI2LjUzMzkgMjYuNDYxMXY3My41MDRoMzIuMjA0NXYtNzIuOTQ0YzAtMTMuMyAxMC45MjItMjUuNjIxIDIzLjk0NC0yNi45NTExLjkxLS4wNyAxLjgyLS4xNCAyLjY2LS4xNCAxNC41NjIgMCAyNi41MzQgMTEuODMwMSAyNi42MDQgMjYuMzIxMXY3My43MTRoMzIuMjA1di03Mi44MDRjMC0xNC43Ny01LjQ2MS0yOC45ODEyLTE1LjMzMi0zOS45NzE4LTkuODcyLTExLjA2MDUtMjMuMzg0LTE3Ljg1MDgtMzguMDg2LTE5LjExMDl6IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJtNDAzLjI2IDMuMTUwMTVoLTMyLjIwNXYxOTQuMjU5ODVoMzIuMjA1eiIvPjxwYXRoIGQ9Im00NjQuODY5IDMuMTUwMTVoLTMyLjIwNXYxOTQuMjU5ODVoMzIuMjA1eiIvPjxwYXRoIGQ9Im01MjYuNDc4IDY4LjUzMzRoLTMyLjIwNXYxMjguODA2NmgzMi4yMDV6Ii8+PHBhdGggY2xpcC1ydWxlPSJldmVub2RkIiBkPSJtNjc3IDEyOS42NDZjMC0xNy4wOC02LjY1MS0zMy4xODEyLTE4LjY5My00NS40MzE4LTEyLjExMi0xMi4yNTA2LTI4LjA3NC0xOS4wNDA5LTQ1LjA4Ni0xOS4wNDA5LS4yOCAwLS41NjEgMC0uODQxIDAtMTcuNjQyLjIxLTM0LjMwNSA3LjIxMDMtNDYuNzY2IDE5Ljc0MS0xMi40NjIgMTIuNTMwNi0xOS40NjMgMjkuMTIxNy0xOS42NzMgNDYuODMyNy0uMjEgMTguMDYgNi43MjEgMzUuMTQxIDE5LjUzMyA0OC4wOTIgMTIuODExIDEyLjk1MSAyOS43NTQgMjAuMDkxIDQ3LjgxNyAyMC4wOTFoLjA3YzIzLjY2MyAwIDQ1Ljg1Ni0xMi42NzEgNTcuOTY4LTMzLjA0MmwxLjU0LTIuNTktMjYuNjA0LTEzLjA5LTEuMzMgMi4xN2MtNi42NTEgMTAuOTktMTguMjAyIDE3LjUwMS0zMS4wMTQgMTcuNTAxLTE2LjM4MyAwLTMwLjUyNS0xMC45MjEtMzQuODY2LTI2LjQ2Mmg5Ny45NDV6bS02NS4wNC0zNS4yMTEzYzE0LjcwMyAwIDI3Ljg2NCA5LjY2MDMgMzIuNDg1IDIzLjM4MTNoLTY0Ljg5OWM0LjU1LTEzLjcyMSAxNy43MTItMjMuMzgxMyAzMi40MTQtMjMuMzgxM3oiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=); - background-size: 100px; - background-repeat: no-repeat; - margin-top: 40px; - padding-top: 40px; - color: white; -} - - -.mm-block-messagebird .header-developed { - width: 300px; - float: right; - margin-top: 40px; - padding-top: 40px; -} - - -.mm-block-messagebird .header-developed a { - color: white; - text-decoration: underline; -} - -.mm-comment-hover .readmore { - cursor: help !important; - float: right; - margin-top: -35px; - border: 0; - background-color: transparent !important; - opacity: 1 !important; - color: #524a43 !important; - font-size: 12px; - text-align: right; - margin-right: 0px; - padding-right: 30px; -} - -.mm-comment-hover:before { - -webkit-font-smoothing: antialiased; - font-size: 16px; - line-height: 1; - color: #514943; - content: '\e633'; - font-family: 'Admin Icons'; - vertical-align: middle; - display: inline-block; - font-weight: 400; - overflow: hidden; - speak: none; - text-align: center; - float: right; - margin-top: -35px; - margin-right: 5px; -} - -@media only screen and (max-width: 1070px) { - .mm-comment-hover .readmore { - width: 30px; - margin-right: 0px; - padding-right: 0px; - } - - .mm-comment-hover:before { - display: none; - } -} - -.mm-comment-hover #content { - display: none; - font-size: 12px; - line-height: 18px; - margin-left: 10px; -} - -.mm-comment-hover input[type="text"] { - color: transparent; - text-shadow: 0 0 0 #000; - padding: 6px 12px; - width: 150px; - cursor: pointer; -} - -.mm-comment-hover input[type="text"]:focus { - outline: none; -} - -.mm-comment-hover input:focus + div#content { - display: block; -} diff --git a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.eot b/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.eot deleted file mode 100755 index faf2013..0000000 Binary files a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.eot and /dev/null differ diff --git a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.svg b/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.svg deleted file mode 100755 index 0ad8417..0000000 --- a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.svg +++ /dev/null @@ -1,50 +0,0 @@ - - - -Copyright (C) 2020 by original authors @ fontello.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.ttf b/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.ttf deleted file mode 100755 index e1fecc0..0000000 Binary files a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.ttf and /dev/null differ diff --git a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.woff b/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.woff deleted file mode 100755 index 6ea0ded..0000000 Binary files a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.woff and /dev/null differ diff --git a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.woff2 b/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.woff2 deleted file mode 100755 index 92c671b..0000000 Binary files a/view/adminhtml/web/fonts/messagebird-icons/messagebird-icons.woff2 and /dev/null differ diff --git a/view/adminhtml/web/images/logo-magmodules.svg b/view/adminhtml/web/images/logo-magmodules.svg new file mode 100644 index 0000000..4fecc8c --- /dev/null +++ b/view/adminhtml/web/images/logo-magmodules.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/web/images/logo-messagebird.svg b/view/adminhtml/web/images/logo-messagebird.svg new file mode 100644 index 0000000..16ff266 --- /dev/null +++ b/view/adminhtml/web/images/logo-messagebird.svg @@ -0,0 +1 @@ +#4a4542 \ No newline at end of file diff --git a/view/adminhtml/web/images/logo-mollie.svg b/view/adminhtml/web/images/logo-mollie.svg new file mode 100644 index 0000000..31b68b4 --- /dev/null +++ b/view/adminhtml/web/images/logo-mollie.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/view/adminhtml/web/js/button-functions.js b/view/adminhtml/web/js/button-functions.js index dcee2f3..6274e14 100755 --- a/view/adminhtml/web/js/button-functions.js +++ b/view/adminhtml/web/js/button-functions.js @@ -1,266 +1,187 @@ require([ 'jquery', 'Magento_Ui/js/modal/modal', - 'prototype', 'loader' ], function ($, modal) { + 'use strict'; + + const moduleName = 'messagebird'; /** * @param{String} modalSelector - modal css selector. * @param{Object} options - modal options. */ - function initModal(modalSelector, options) { - var $resultModal = $(modalSelector); + function initModal(type, options) { + const modalId = `#mm-ui-result_${type}-modal`; + if (!$(modalId).length) return; + + let defaultOptions = { + modalClass: `mm-ui-modal ${moduleName}`, + type: 'popup', + responsive: true, + innerScroll: true, + title: options.title || '', + buttons: [ + { + text: $.mage.__('Close window'), + class: 'mm-ui-modal-close', + click: function () { + this.closeModal(); + }, + } + ] + }; - if (!$resultModal.length) return; + // Additional buttons for downloading + if (options.buttons) { + let additionalButtons = { + text: $.mage.__('download as .txt file'), + class: 'mm-ui-button__download mm-ui-icon__download-alt', + click: () => { + let elText = document.getElementById(`mm-ui-result_${options.buttons}`).innerText || '', + link = document.createElement('a'); - var popup = modal(options, $resultModal); - $resultModal.loader({texts: ''}); + link.setAttribute('download', `${options.buttons}-log.txt`); + link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(elText)); + link.click(); + }, + }; + + defaultOptions.buttons.unshift(additionalButtons); + } + + modal(defaultOptions, $(modalId)); + $(modalId).loader({texts: ''}); } var successHandlers = { /** - * @param{Object[]} result - Ajax request response data. + * @param{Object[]} obj - Ajax request response data. * @param{Object} $container - jQuery container element. + * @param{String} type - debug || error || test. */ - debug: function (result, $container) { - - if (Array.isArray(result)) { + logs(response, $container, type) { + // If source blocked + if (response.error) response = this.tmpBlockedSource(response.message); - var lisHtml = result.map(function (err) { - return '
  • ' + err.date + '

    ' + err.msg + '

  • '; - }).join(''); - - $container.find('.result').empty().append('
      ' + lisHtml + '
    '); - } else { - - $container.find('.result').empty().append(result); + if (Array.isArray(response.result)) { + if (type === 'debug' || type === 'error') { + response = `
      ${response.result.map((data) => this.tmpLogs(type, data)).join('')}
    `; + } } - }, - - /** - * @param{Object[]} result - Ajax request response data. - * @param{Object} $container - jQuery container element. - */ - error: function (result, $container) { - if (Array.isArray(result)) { - - var lisHtml = result.map(function (err) { - return '
  • ' + err.date + '

    ' + err.msg + '

  • '; - }).join(''); - - $container.find('.result').empty().append('
      ' + lisHtml + '
    '); - } else { - - $container.find('.result').empty().append(result); - } + $container.find('.result').empty().append(response); }, - /** - * @param{Object[]} result - Ajax request response data. - * @param{Object} $container - jQuery container element. - */ - test: function (result, $container) { - - var lisHtml = result.map(function (test) { - - var supportLinkHtml = test.support_link ? - '' : ''; - var resultText = test.result_code === 'success' ? - $.mage.__('Passed') : $.mage.__('Failed'); - var resultMsg = test.result_code === 'failed' ? test.result_msg : ''; - - return '
  • ' + resultText + '' - + '

    ' + test.test + '

    ' + resultMsg + '

    ' - + supportLinkHtml + '
  • '; - }).join(''); + tmpLogs(type, data) { + return `
  • + ${data.date} +

    ${data.msg}

    +
  • `; + }, - $container.find('.result').empty().append(lisHtml); + tmpBlockedSource(message) { + return `
    +
    + + + + ${message} +
    +
    `; }, /** * @param{Object[]} result - Ajax request response data. * @param{Object} $container - jQuery container element. */ - version: function (result, $container) { - - var resultHtml = ''; - var currentVersion = result.current_verion.replace(/v|version/gi, ''); - var latestVersion = result.last_version.replace(/v|version/gi, ''); - if (this.compare(latestVersion, currentVersion) < 0) { - resultHtml = '' - + $.mage.__('Great, you are using the latest version.') - + ''; + version(response, $container) { + let resultHTML = ''; + + if (response.error) { + // If source blocked + resultHTML = this.tmpBlockedSource(response.message); } else { + let resultText = $.mage.__('Great, you are using the latest version.'), + resultClass = 'up'; - var translatedResult = $.mage.__('There is a new version available (%1) see .') - .replace('%1', latestVersion); + if (this.isLastVersion(response.result.current_version, response.result.last_version)) { + resultClass = 'down'; + resultText = $.mage.__('There is a new version available (%1) see .') + .replace('%1', response.result.last_version.slice(1)); + } - resultHtml = '' - + translatedResult - + ''; + resultHTML = ` + ${resultText} + `; } - $container.html(resultHtml); + $container.html(resultHTML); }, - compare: function(a, b) { - if (a === b) { - return 0; - } - var a_components = a.split("."); - var b_components = b.split("."); - var len = Math.min(a_components.length, b_components.length); - for (var i = 0; i < len; i++) { - if (parseInt(a_components[i]) > parseInt(b_components[i])) { - return 1; - } + /** + * @param{String} - current module version + * @param{String} - last module version + * @returns {Boolean} + */ + isLastVersion(v1, v2) { + let array1 = v1.slice(1).split('.').map((i) => +i), + array2 = v2.slice(1).split('.').map((i) => +i); - if (parseInt(a_components[i]) < parseInt(b_components[i])) { - return -1; - } + for(let i = 0; i < array1.length; i++) { + if (array1[i] !== array2[i]) return array1[i] < array2[i] ? true : false; } - if (a_components.length > b_components.length) { - return 1; - } - if (a_components.length < b_components.length) { - return -1; - } - return 0; + + return false; }, /** * @param{Object[]} result - Ajax request response data. * @param{Object} $container - jQuery container element. */ - changelog: function (result, $container) { - - var lisHtml = Object.keys(result).map(function (key) { - - var version = key; - var date = result[key].date; - var resultHtml = result[key].changelog; - - return '
  • ' - + version + '|' - + date + '
    ' - + resultHtml + '
  • '; - }).join(''); - - $container.find('.result').empty().append(lisHtml); + changelog(response, $container) { + let listHTML = Object.keys(response).map((version) => { + return `
  • + ${version} + | + ${response[version].date} +
    ${response[version].changelog}
    +
  • `; + }); + + $container.find('.result').empty().append(listHTML.join('')); }, } - // init debug modal - initModal('#magmodules-messagebird-result_debug-modal', { - type: 'popup', - responsive: true, - innerScroll: true, - title: $.mage.__('last 100 debug log lines'), - buttons: [ - { - text: $.mage.__('download as .txt file'), - class: 'magmodules-messagebird-button__download magmodules-messagebird-icon__download-alt', - click: function () { - - var elText = document.getElementById('magmodules-messagebird-result_debug').innerText || ''; - var link = document.createElement('a'); - - link.setAttribute('download', 'debug-log.txt'); - link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(elText)); - link.click(); - }, - }, - { - text: $.mage.__('ok'), - class: '', - click: function () { - this.closeModal(); - }, - } - ] + // init modals + $(() => { + initModal('debug', { title: $.mage.__('Last 100 debug log records'), buttons: 'debug' }); + initModal('error', { title: $.mage.__('Last 100 error log records'), buttons: 'error' }); + initModal('changelog', { title: $.mage.__('Changelog') }); }); - - // init error modal - initModal('#magmodules-messagebird-result_error-modal', { - type: 'popup', - responsive: true, - innerScroll: true, - title: $.mage.__('last 100 error log records'), - buttons: [ - { - text: $.mage.__('download as .txt file'), - class: 'magmodules-messagebird-button__download magmodules-messagebird-icon__download-alt', - click: function () { - - var elText = document.getElementById('magmodules-messagebird-result_error').innerText || ''; - var link = document.createElement('a'); - - link.setAttribute('download', 'error-log.txt'); - link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(elText)); - link.click(); - }, - }, - { - text: $.mage.__('ok'), - class: '', - click: function () { - this.closeModal(); - }, - } - ] - }); - - // init selftest modal - initModal('#magmodules-messagebird-result_test-modal', { - type: 'popup', - responsive: true, - innerScroll: true, - title: $.mage.__('Self-test'), - buttons: [ - { - text: $.mage.__('ok'), - class: '', - click: function () { - this.closeModal(); - }, - } - ] - }); - - // init changelog modal - initModal('#magmodules-messagebird-result_changelog-modal', { - type: 'popup', - responsive: true, - innerScroll: true, - title: 'Changelog', - buttons: [ - { - text: $.mage.__('ok'), - class: '', - click: function () { - this.closeModal(); - }, - } - ] - }); - + // init loader on the Check Version block - $('.magmodules-messagebird-result_version-wrapper').loader({texts: ''}); + $('.mm-ui-result_version-wrapper').loader({texts: ''}); /** * Ajax request event */ - $(document).on('click', '[id^=magmodules-messagebird-button]', function () { - var actionName = this.id.split('_')[1]; - var $modal = $('#magmodules-messagebird-result_' + actionName + '-modal'); - var $result = $('#magmodules-messagebird-result_' + actionName); + $(document).on('click', '[id^=mm-ui-button]', function () { + if (this.id.split('_')[1] === 'credentials') { + return false; + } + + let action = this.id.split('_')[1], + $modal = $(`#mm-ui-result_${action}-modal`), + $result = $(`#mm-ui-result_${action}`); - if (actionName === 'version') { - $(this).fadeOut(300).addClass('magmodules-messagebird-disabled'); - $modal = $('.magmodules-messagebird-result_' + actionName + '-wrapper'); + const func = action === 'debug' || + action === 'error' || + action === 'test' ? 'logs' : action; + + if (action === 'version') { + $(this).fadeOut(300).addClass('mm-ui-disabled'); + $modal = $(`.mm-ui-result_${action}-wrapper`); $modal.loader('show'); } else { $modal.modal('openModal').loader('show'); @@ -268,20 +189,23 @@ require([ $result.hide(); - new Ajax.Request($modal.data('magmodules-messagebird-endpoind-url'), { - loaderArea: false, - asynchronous: true, - onSuccess: function (response) { - - if (response.status > 200) { - var result = response.statusText; - } else { - successHandlers[actionName](response.responseJSON.result || response.responseJSON, $result); - - $result.fadeIn(); - $modal.loader('hide'); - } - } - }); + fetch($modal.attr('data-mm-ui-endpoind-url')) + .then((res) => res.clone().json().catch(() => res.text())) + .then((data) => { + successHandlers[func](data, $result, action); + }) + .catch(() => { + // If response block with adBlock extensions + const error = { + error: true, + message: $.mage.__("Failed to load data. Disable the ad blocker. If it didn't help, please contact us."), + }; + + successHandlers[func](error, $result, action); + }) + .finally(() => { + $result.fadeIn(); + $modal.loader('hide'); + }); }); }); diff --git a/view/adminhtml/web/js/show-more.js b/view/adminhtml/web/js/show-more.js index f2e7440..6c7679c 100755 --- a/view/adminhtml/web/js/show-more.js +++ b/view/adminhtml/web/js/show-more.js @@ -1,50 +1,58 @@ require([ - 'jquery' -], function ($) { - - var $mmHeadingComment = $('.magmodules-messagebird-heading-comment'); - - if($mmHeadingComment.length) { - - $(window).load(function() { - - var showMoreLessBtnHtml = ''; - - $mmHeadingComment.each(function (i, el) { - var elStyles = getComputedStyle(el); - var $el = $(el); - var oldHtml = $el.html(); - var ellipsesIndex = oldHtml.length; - var maxElHeight = parseInt(elStyles.lineHeight) * 2; - - if (maxElHeight < $el.outerHeight()) { - - while (maxElHeight < $el.outerHeight()) { - $el.html(function (index, text) { - var newText = text.replace(/\W*\s(\S)*$/, ''); - ellipsesIndex = newText.length; - return newText; - }); - } - - var visibleStr = oldHtml.substr(0, ellipsesIndex); - var hiddenStr = oldHtml.substr(ellipsesIndex); - - $el.html('' + visibleStr + '' - + hiddenStr.replace('
    ', '
    ') - + '
    ' + showMoreLessBtnHtml); - - } - }); + 'jquery', + 'mage/translate', + '!domReady' +], function ($, $t) { + + let comment = $('.mm-ui-heading-comment'), + heading = comment.parent().find('.mm-ui-heading-block'), + showMoreLessBtnHtml = ` + `; + + // Additional check if tab was closed during initialization + const parent = document.querySelector('form[action*="magmodules_messagebird"]'); + const observer = new MutationObserver((mutation) => { + for (let i = 0; i < mutation.length; i++) { + if (mutation[i].target.classList.contains('section-config')) { + isShowMore(); + } + } + }); + + observer.observe(parent, { + subtree: true, + attributes: true, + attributeFilter: ['class'], + }); + + if(comment.length) { + heading.append(showMoreLessBtnHtml); + + $(document).on('click', '.mm-ui-show-more-actions a', (e) => { + let button = $(e.target), + parent = button.closest('.value').find('.mm-ui-heading-comment'); + + if (parent.hasClass('show')) { + parent.removeClass('show'); + button.text($t('More')); + } else { + parent.addClass('show'); + button.text($t('Less')); + } }); - /** - * Toggle show more btn event. - */ - $(document).on('click', '.magmodules-messagebird-show-more-actions a', function() { - $(this).closest('.magmodules-messagebird-heading-comment').toggleClass('magmodules-messagebird-show-more-active'); + $(document).ready(isShowMore); + window.addEventListener("resize", isShowMore); + } + + function isShowMore() { + Array.from(comment).forEach((item) => { + const BTN = item.closest('td').querySelector('.mm-ui-show-more-actions'); + item.scrollHeight <= 55 ? BTN.classList.add('hidden') : BTN.classList.remove('hidden'); }); } });