[TASK] SystemInformationMenu: Automatically refresh counter badge 18/53018/2
authorJohannes Goslar <jogo@kronberger-spiele.de>
Thu, 1 Jun 2017 16:22:31 +0000 (18:22 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 2 Jun 2017 09:47:38 +0000 (11:47 +0200)
Automatically reload the SystemInformation every 5 minutes.

Resolves: #68920
Releases: master, 8.7
Change-Id: Ie21d345d6bcbbae30f0fd77f084c22b1b2a0f6f2
Reviewed-on: https://review.typo3.org/53018
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/SystemInformationMenu.js

index b3bb52e..5421ca4 100644 (file)
@@ -46,6 +46,11 @@ define([
        };
 
        /**
+        * Timer for auto reloading the SystemInformation
+        */
+       SystemInformationMenu.timer = null;
+
+       /**
         * Updates the menu
         */
        SystemInformationMenu.updateMenu = function() {
@@ -53,9 +58,9 @@ define([
                        $existingIcon = $toolbarItemIcon.clone(),
                        $menuContainer = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector);
 
-               // hide the menu if it's active
-               if ($menuContainer.is(':visible')) {
-                       $menuContainer.click();
+               if (SystemInformationMenu.timer !== null) {
+                       clearTimeout(SystemInformationMenu.timer);
+                       SystemInformationMenu.timer = null;
                }
 
                Icons.getIcon('spinner-circle-light', Icons.sizes.small).done(function(spinner) {
@@ -64,6 +69,9 @@ define([
 
                $.ajax({
                        url: TYPO3.settings.ajaxUrls['systeminformation_render'],
+                       data: {
+                               skipSessionUpdate: 1
+                       },
                        type: 'post',
                        cache: false,
                        success: function(data) {
@@ -73,6 +81,12 @@ define([
 
                                SystemInformationMenu.initialize();
                        }
+               }).done(function(){
+                       // reload error data every five minutes
+                       SystemInformationMenu.timer = setTimeout(
+                               SystemInformationMenu.updateMenu,
+                               1000 * 300
+                       );
                });
        };
 
@@ -86,10 +100,14 @@ define([
                        badgeClass = $container.data('severityclass');
 
                $counter.text(count).toggle(parseInt(count) > 0);
-               $counter.removeClass();
 
+               // ensure all default classes are available and previous
+               // (at this time in processing unknown) class is removed
+               $counter.removeClass();
+               $counter.addClass('t3js-systeminformation-counter toolbar-item-badge badge');
+               // badgeClass e.g. could be 'badge-info', 'badge-danger', ...
                if (badgeClass !== '') {
-                       $counter.addClass('toolbar-item-badge badge ' + badgeClass);
+                       $counter.addClass(badgeClass);
                }
        };