diff --git a/ajax/backend/independent/clearCache.php b/ajax/backend/independent/clearCache.php new file mode 100644 index 0000000000000000000000000000000000000000..b5af512678f07608342798d680b275be409a52c0 --- /dev/null +++ b/ajax/backend/independent/clearCache.php @@ -0,0 +1,22 @@ +<?php + +/** + * This file contains package_quiqqer_menu_ajax_backend_independent_clearCache + */ + +/** + * Clears the menu cache + */ + +use QUI\Menu\Independent\Handler; + +QUI::$Ajax->registerFunction( + 'package_quiqqer_menu_ajax_backend_independent_clearCache', + function ($menuId) { + QUI\Cache\Manager::clear( + Handler::getMenuCacheName($menuId) + ); + }, + ['menuId'], + 'Permission::checkAdminUser' +); diff --git a/bin/Controls/Independent/MenuPanel.js b/bin/Controls/Independent/MenuPanel.js index 40ef740c7fd2fcdd7e0d47d3bc2f932f28ee16c4..31f6b33d444be75d4e8ad0efbe4c61edccf126f6 100644 --- a/bin/Controls/Independent/MenuPanel.js +++ b/bin/Controls/Independent/MenuPanel.js @@ -11,6 +11,7 @@ define('package/quiqqer/menu/bin/Controls/Independent/MenuPanel', [ 'qui/controls/windows/Confirm', 'qui/controls/contextmenu/Menu', 'qui/controls/contextmenu/Item', + 'Ajax', 'Locale', 'package/quiqqer/menu/bin/classes/Independent/Handler', @@ -19,7 +20,7 @@ define('package/quiqqer/menu/bin/Controls/Independent/MenuPanel', [ 'css!package/quiqqer/menu/bin/Controls/Independent/MenuPanel.css' ], function (QUI, QUIPanel, QUIMap, QUIMapItem, QUIConfirm, QUIContextMenu, QUIContextMenuItem, - QUILocale, MenuHandler, Mustache, templateCreate) { + QUIAjax, QUILocale, MenuHandler, Mustache, templateCreate) { "use strict"; const lg = 'quiqqer/menu'; @@ -85,6 +86,34 @@ define('package/quiqqer/menu/bin/Controls/Independent/MenuPanel', [ } }); + this.addButton({ + textimage: 'fa fa-paint-brush', + name : 'clearcache', + text : QUILocale.get(lg, 'cache.clear.button.title'), + styles : { + 'float': 'right' + }, + events : { + click: (Btn) => { + Btn.disable(); + Btn.setAttribute('textimage', 'fa fa-spinner fa-spin'); + QUIAjax.post('package_quiqqer_menu_ajax_backend_independent_clearCache', () => { + Btn.setAttribute('textimage', 'fa fa-bars'); + Btn.enable(); + + QUI.getMessageHandler(function (QUI) { + QUI.addSuccess( + QUILocale.get('quiqqer/quiqqer', 'message.clear.cache.successful') + ); + }); + }, { + 'package': 'quiqqer/menu', + menuId : this.getAttribute('menuId') + }); + } + } + }); + /* this.addButton({ name : 'delete', diff --git a/bin/onAdminLoadFooter.js b/bin/onAdminLoadFooter.js new file mode 100644 index 0000000000000000000000000000000000000000..04e3d060f52730f18da891bc38afda1e019fd8b7 --- /dev/null +++ b/bin/onAdminLoadFooter.js @@ -0,0 +1,55 @@ +window.addEvent('domready', function () { + require([ + 'qui/QUI', + 'qui/controls/buttons/Button', + 'Ajax', + 'Locale' + ], function (QUI, QUIButton, QUIAjax, QUILocale) { + QUI.addEvent('onQuiqqerCacheClearPanel', function (Setting) { + const lg = 'quiqqer/menu'; + const Content = Setting.getElm(); + + const Table = new Element('table', { + 'class': 'data-table data-table-flexbox quiqqer-settings-cache-table quiqqer-settings-cache-container', + html : '<thead>' + + ' <tr>' + + ' <th>' + QUILocale.get(lg, 'cache.clear.title') + '</th>' + + ' </tr>' + + '</thead>' + + '<tbody>' + + ' <tr>' + + ' <td>' + + ' ' + + ' </td>' + + ' </tr>' + + '</tbody>' + }).inject(Content); + + new QUIButton({ + textimage: 'fa fa-bars', + text : QUILocale.get(lg, 'cache.clear.button.title'), + styles : { + width: '100%' + }, + events : { + click: function (Btn) { + Btn.disable(); + Btn.setAttribute('textimage', 'fa fa-spinner fa-spin'); + QUIAjax.post('package_quiqqer_menu_ajax_backend_independent_clearCache', function () { + Btn.setAttribute('textimage', 'fa fa-bars'); + Btn.enable(); + + QUI.getMessageHandler(function (QUI) { + QUI.addSuccess( + QUILocale.get('quiqqer/quiqqer', 'message.clear.cache.successful') + ); + }); + }, { + 'package': 'quiqqer/menu' + }); + } + } + }).inject(Table.getElement('tbody tr td')); + }); + }); +}); diff --git a/events.xml b/events.xml index 1b64a87351c7a89c80f1d39a5f4e928fd3c1ef37..3a2d7543002241d47a9efc00faa1c3b3cb330a33 100644 --- a/events.xml +++ b/events.xml @@ -2,4 +2,5 @@ <events> <event on="onSiteSave" fire="\QUI\Menu\EventHandler::onSiteSave"/> <event on="onSmartyInit" fire="\QUI\Menu\EventHandler::onSmartyInit"/> + <event on="onAdminLoadFooter" fire="\QUI\Menu\EventHandler::onAdminLoadFooter"/> </events> diff --git a/locale.xml b/locale.xml index ca1bc1507dc53cd0dd7a6908c3d9d2693348e58f..db00769f0434c9ef2d545060abc2080bd0d5d3a8 100644 --- a/locale.xml +++ b/locale.xml @@ -424,5 +424,14 @@ <en><![CDATA[tag - A tag (keyword) for the current document]]></en> </locale> + <locale name="cache.clear.title"> + <de><![CDATA[Menü Cache]]></de> + <en><![CDATA[Menu cache]]></en> + </locale> + <locale name="cache.clear.button.title"> + <de><![CDATA[Menü Cache leeren]]></de> + <en><![CDATA[Clear menu cache]]></en> + </locale> + </groups> </locales> \ No newline at end of file diff --git a/settings.xml b/settings.xml index 25dfc1f15f36cda0ad7ec70c1f7dbec3c15f9f66..6f8cc738b901c86590b50bfad97afd501dfc00b6 100644 --- a/settings.xml +++ b/settings.xml @@ -55,4 +55,31 @@ </settings> </project> + + <settings> + <window name="quiqqer-cache" menu-parent="/settings/quiqqer/"> + <title> + <locale group="quiqqer/quiqqer" var="quiqqer.settings.cache"/> + </title> + + <params> + <icon>fa fa-sort-amount-desc</icon> + </params> + + + <category name="management" require="controls/cache/Settings"> + + <settings title="clearMenuCache" name="clearMenuCache"> + <title> + <locale group="quiqqer/quiqqer" var="quiqqer.menu.clearMenuCache.title"/> + </title> + + <button>boom</button> + </settings> + + </category> + + </window> + </settings> + </quiqqer> \ No newline at end of file diff --git a/src/QUI/Menu/EventHandler.php b/src/QUI/Menu/EventHandler.php index 1c24f8c03a1ad5365dacb730bad618f22de82a8d..598f3fc06b4f83287723caef3ad5681084f51128 100644 --- a/src/QUI/Menu/EventHandler.php +++ b/src/QUI/Menu/EventHandler.php @@ -45,4 +45,15 @@ public static function onSmartyInit(Smarty $Smarty) $Smarty->registerPlugin("function", "menu", "QUI\\Menu\\Independent\\Smarty::onSmartyInit"); } } + + /** + * QUIQQER Event: onAdminLoadFooter + * + * @return void + */ + public static function onAdminLoadFooter() + { + $jsFile = URL_OPT_DIR . 'quiqqer/menu/bin/onAdminLoadFooter.js'; + echo '<script src="' . $jsFile . '" async></script>'; + } } diff --git a/src/QUI/Menu/Independent/Handler.php b/src/QUI/Menu/Independent/Handler.php index 0468802ae4d372343613aaf5055f6a45f802aaf8..9c67d4dbad77046812b31683c4d2059c044702e4 100644 --- a/src/QUI/Menu/Independent/Handler.php +++ b/src/QUI/Menu/Independent/Handler.php @@ -4,6 +4,8 @@ use QUI; +use function md5; + /** * Menu handler * - get menus @@ -29,6 +31,29 @@ public static function getMenu(int $menuId): Menu return new Menu($menuId); } + /** + * @param bool|int $menuId + * @param QUI\Projects\Project|null $Project + * @return string + */ + public static function getMenuCacheName($menuId = false, QUI\Projects\Project $Project = null): string + { + if ($Project) { + $project = $Project->getName(); + $lang = $Project->getLang(); + $template = $Project->getAttribute('template'); + $projectHash = '/' . md5($project . '/' . $lang . '/' . $template); + } else { + $projectHash = ''; + } + + if ($menuId) { + return 'quiqqer/menu/independent/' . $menuId . $projectHash; + } + + return 'quiqqer/menu/independent'; + } + /** * @param int $menuId * @return array @@ -39,7 +64,7 @@ public static function getMenu(int $menuId): Menu public static function getMenuData(int $menuId): array { $data = QUI::getDataBase()->fetch([ - 'from' => self::table(), + 'from' => self::table(), 'where' => [ 'id' => $menuId ], diff --git a/src/QUI/Menu/Independent/Smarty.php b/src/QUI/Menu/Independent/Smarty.php index 467a9b2385654b1571c6d3bb67010e50acbd18a1..38860be7e30979d30f1a6d4ef295c0fd16aa3c55 100644 --- a/src/QUI/Menu/Independent/Smarty.php +++ b/src/QUI/Menu/Independent/Smarty.php @@ -23,6 +23,20 @@ public static function menu($params, $smarty): string return ''; } + try { + $Project = QUI::getRewrite()->getProject(); + } catch (QUI\Exception $Exception) { + return ''; + } + + $menuId = $params['menuId']; + $cacheName = Handler::getMenuCacheName($menuId, $Project); + + try { + return QUI\Cache\Manager::get($cacheName); + } catch (QUI\Exception $Exception) { + } + try { $Menu = QUI\Menu\Independent\Handler::getMenu($params['menuId']); $Control = new $params['menuDesign']($Menu); @@ -31,6 +45,9 @@ public static function menu($params, $smarty): string return ''; } - return $Control->create(); + $html = $Control->create(); + QUI\Cache\Manager::set($cacheName, $html); + + return $html; } }