[FOLLOWUP][FEATURE] Introduce System Information dropdown item 34/38434/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 2 Apr 2015 13:24:55 +0000 (15:24 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 7 Apr 2015 13:59:28 +0000 (15:59 +0200)
* Do not render failed logins
* Render menu by AJAX call
* Add JavaScript method to invoke a reload of the menu

Related: #66234
Resolves: #65767
Releases: master
Change-Id: Ic3d3fcacbf86ad728c200cc3f2e103d138f33680
Reviewed-on: http://review.typo3.org/38434
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php
typo3/sysext/backend/Resources/Private/Language/locallang.xlf
typo3/sysext/backend/Resources/Private/Templates/ToolbarMenu/SystemInformation.html
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/SystemInformationMenu.js
typo3/sysext/belog/Classes/Controller/SystemInformationController.php
typo3/sysext/belog/Resources/Private/Language/locallang.xlf
typo3/sysext/core/Configuration/DefaultConfiguration.php

index 7dbe5e0..f2e8685 100644 (file)
@@ -18,6 +18,7 @@ use TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface;
 use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
+use TYPO3\CMS\Core\Http\AjaxRequestHandler;
 use TYPO3\CMS\Core\Utility\CommandUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
@@ -47,6 +48,13 @@ class SystemInformationToolbarItem extends AbstractToolbarItem implements Toolba
        protected $highestSeverity = '';
 
        /**
+        * The CSS class for the badge
+        *
+        * @var string
+        */
+       protected $severityBadgeClass = '';
+
+       /**
         * @var array
         */
        protected $systemInformation = array();
@@ -73,7 +81,12 @@ class SystemInformationToolbarItem extends AbstractToolbarItem implements Toolba
 
                $pageRenderer = $this->getPageRenderer();
                $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu');
+       }
 
+       /**
+        * Collect the information for the menu
+        */
+       protected function collectInformation() {
                $this->getWebServer();
                $this->getPhpVersion();
                $this->getDatabase();
@@ -83,6 +96,19 @@ class SystemInformationToolbarItem extends AbstractToolbarItem implements Toolba
 
                $this->emitGetSystemInformation();
                $this->emitLoadMessages();
+
+               $this->severityBadgeClass = $this->highestSeverity !== InformationStatus::STATUS_NOTICE ? 'badge-' . $this->highestSeverity : '';
+       }
+
+       /**
+        * Renders the menu for AJAX calls
+        *
+        * @param array $params
+        * @param AjaxRequestHandler $ajaxObj
+        */
+       public function renderAjax($params = array(), $ajaxObj) {
+               $this->collectInformation();
+               $ajaxObj->addContent('systemInformationMenu', $this->getDropDown());
        }
 
        /**
@@ -240,13 +266,8 @@ class SystemInformationToolbarItem extends AbstractToolbarItem implements Toolba
         */
        public function getItem() {
                $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.sysinfo', TRUE);
-               $item = IconUtility::getSpriteIcon('actions-system-list-open', array('title' => $title));
-
-               if ($this->totalCount > 0) {
-                       $severityBadge = $this->highestSeverity !== InformationStatus::STATUS_NOTICE ? 'badge-' . $this->highestSeverity : '';
-                       $item .= '<span id="t3js-systeminformation-counter" class="badge ' . $severityBadge . '">' . $this->totalCount . '</span>';
-               }
-               return $item;
+               return IconUtility::getSpriteIcon('actions-system-list-open', array('title' => $title))
+                               . '<span id="t3js-systeminformation-counter" class="badge"></span>';
        }
 
        /**
@@ -262,6 +283,8 @@ class SystemInformationToolbarItem extends AbstractToolbarItem implements Toolba
                $this->getStandaloneView('backend')->assignMultiple(array(
                        'installToolUrl' => BackendUtility::getModuleUrl('system_InstallInstall'),
                        'messages' => $this->systemMessages,
+                       'count' => $this->totalCount,
+                       'severityBadgeClass' => $this->severityBadgeClass,
                        'systemInformation' => $this->systemInformation
                ));
                return $this->getStandaloneView()->render();
@@ -345,4 +368,4 @@ class SystemInformationToolbarItem extends AbstractToolbarItem implements Toolba
                return $this->signalSlotDispatcher;
        }
 
-}
+}
\ No newline at end of file
index 324ceda..d031df5 100644 (file)
@@ -13,7 +13,7 @@
                                <source>Application Information</source>
                        </trans-unit>
                        <trans-unit id="systemmessage.intro">
-                               <source><![CDATA[This is a short system overview, for advanced information please head to the <a href="%s">Install Tool</a>.]]></source>
+                               <source><![CDATA[This is a short system overview. For advanced information please head to the <a href="%s">Install Tool</a>.]]></source>
                        </trans-unit>
                        <trans-unit id="systemmessage.allgood" xml:space="preserve">
                                <source>Your system is fully operational.
index c3ef80d..79ce28f 100644 (file)
@@ -1,4 +1,4 @@
-<ul class="dropdown-list">
+<ul class="dropdown-list" data-count="{count}" data-severityclass="{severityBadgeClass}">
        <li class="dropdown-header"><f:translate key="systemmessage.header" /></li>
        <li id="systeminformation_installtool" class="dropdown-intro typo3-module-menu-item submodule mod-system_InstallInstall" data-modulename="system_InstallInstall">
                <f:translate key="systemmessage.intro" arguments="{0: '{installToolUrl}'}" />
@@ -22,7 +22,7 @@
        <f:if condition="{messages -> f:count()} > 0">
                <f:then>
                        <f:for each="{messages}" as="message">
-                               <li><span class="text-{message.status}">{message.text}</span></li>
+                               <li><span class="text-{message.status}"><f:format.raw>{message.text}</f:format.raw></span></li>
                        </f:for>
                </f:then>
                <f:else>
index fab870d..0333dd2 100644 (file)
 define('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu', ['jquery'], function($) {
 
        var SystemInformationMenu = {
+               identifier: {
+                       containerSelector: '#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem',
+                       toolbarIconSelector: '.dropdown-toggle span.t3-icon',
+                       menuContainerSelector: '.dropdown-menu'
+               },
                elements: {
-                       $counter: $('#t3js-systeminformation-counter')
+                       $counter: $('#t3js-systeminformation-counter'),
+                       $spinnerElement: $('<span>', {
+                               'class': 't3-icon fa fa-circle-o-notch spinner fa-spin'
+                       })
                }
        };
 
        /**
-        * register event handlers
+        * Updates the menu
         */
-       SystemInformationMenu.initializeEvents = function() {
-               var count = parseInt(SystemInformationMenu.elements.$counter.text());
-               SystemInformationMenu.elements.$counter.toggle(count > 0);
+       SystemInformationMenu.updateMenu = function() {
+               var $toolbarItemIcon = $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector),
+                       $spinnerIcon = SystemInformationMenu.elements.$spinnerElement.clone(),
+                       $existingIcon = $toolbarItemIcon.replaceWith($spinnerIcon);
+
+               $.ajax({
+                       url: TYPO3.settings.ajaxUrls['SystemInformationMenu::load'],
+                       type: 'post',
+                       cache: false,
+                       success: function(data) {
+                               $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector).html(data);
+                               SystemInformationMenu.updateCounter();
+                               $spinnerIcon.replaceWith($existingIcon);
+                       }
+               })
+       };
+
+       /**
+        * Updates the counter
+        */
+       SystemInformationMenu.updateCounter = function() {
+               var $ul = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector).find('ul'),
+                       count = $ul.data('count'),
+                       badgeClass = $ul.data('severityclass');
+
+               SystemInformationMenu.elements.$counter.text(count).toggle(count > 0);
+               SystemInformationMenu.elements.$counter.removeClass();
+
+               if (badgeClass !== '') {
+                       SystemInformationMenu.elements.$counter.addClass('badge ' + badgeClass);
+               }
        };
 
        /**
-        * initialize and return the Opendocs object
+        * Initialize and return the SystemInformationMenu object
         */
        $(document).ready(function() {
-               SystemInformationMenu.initializeEvents();
+               SystemInformationMenu.updateMenu();
        });
 
        TYPO3.SystemInformationMenu = SystemInformationMenu;
index 03f21f4..3255d66 100644 (file)
@@ -24,8 +24,7 @@ class SystemInformationController extends AbstractController {
        /**
         * Modifies the SystemInformation array
         *
-        * @param array $systemMessages Array of system messages
-        * @return
+        * @return NULL|array
         */
        public function appendMessage() {
                $constraint = $this->getConstraintFromBeUserData();
@@ -35,7 +34,7 @@ class SystemInformationController extends AbstractController {
 
                $this->setStartAndEndTimeFromTimeSelector($constraint);
                // we can't use the extbase repository here as the required TypoScript may not be parsed yet
-               $count = $this->getDatabaseConnection()->exec_SELECTcountRows('error', 'sys_log', 'tstamp >= ' . $constraint->getStartTimestamp() . ' AND tstamp <= ' . $constraint->getEndTimestamp() . ' AND error IN(-1,1,2,3)');
+               $count = $this->getDatabaseConnection()->exec_SELECTcountRows('error', 'sys_log', 'tstamp >= ' . $constraint->getStartTimestamp() . ' AND tstamp <= ' . $constraint->getEndTimestamp() . ' AND error IN(-1,1,2)');
 
                if ($count > 0) {
                        return array(
index 4f86c9b..b533287 100644 (file)
                                <source>Time</source>
                        </trans-unit>
                        <trans-unit id="systemmessage.errorsInPeriod">
-                               <source>We have found %1$d errors. Please check your administration log.</source>
+                               <source>We have found %1$d errors. Please check your system log.</source>
                        </trans-unit>
                </body>
        </file>
index 6fa5feb..5441de3 100644 (file)
@@ -677,6 +677,10 @@ return array(
                                'callbackMethod' => \TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem::class . '->createAjaxShortcut',
                                'csrfTokenCheck' => TRUE
                        ),
+                       'SystemInformationMenu::load' => array(
+                               'callbackMethod' => \TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem::class . '->renderAjax',
+                               'csrfTokenCheck' => TRUE
+                       ),
                        'ModuleMenu::reload' => array(
                                'callbackMethod' => \TYPO3\CMS\Backend\Controller\BackendController::class . '->getModuleMenuForReload',
                                'csrfTokenCheck' => TRUE