From 4e2d5bdf2bccc58bf4ec172ba94277d1143072c0 Mon Sep 17 00:00:00 2001
From: daniel <daniel.barbero@artica.es>
Date: Fri, 30 Oct 2020 13:23:47 +0100
Subject: [PATCH] fix counter groups child

---
 .../include/javascript/tree/TreeController.js | 34 ++++++++++++++++---
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js
index 497e18c266..1aeb7ad799 100644
--- a/pandora_console/include/javascript/tree/TreeController.js
+++ b/pandora_console/include/javascript/tree/TreeController.js
@@ -12,6 +12,8 @@
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 
+/*global $, _*/
+
 var TreeController = {
   controllers: [],
   getController: function() {
@@ -38,12 +40,35 @@ var TreeController = {
           return;
         }
 
+        function _recursiveGroupsCount(elements, childGroupsLength) {
+          if (typeof childGroupsLength === "undefined") {
+            childGroupsLength = 0;
+          }
+
+          _.each(elements, function(element) {
+            if (typeof element.children !== "undefined") {
+              childGroupsLength = _recursiveGroupsCount(
+                element.children,
+                childGroupsLength
+              );
+              childGroupsLength += element.children.length;
+            }
+          });
+          return childGroupsLength;
+        }
+
         // Load branch
         function _processGroup(container, elements, rootGroup) {
           var $group = $("<ul></ul>");
+          var childGroupsLength = _recursiveGroupsCount(elements);
 
-          // First group
+          // First group.
           if (typeof rootGroup != "undefined" && rootGroup == true) {
+            var messageLength = controller.tree.length;
+            if (childGroupsLength > 0) {
+              messageLength = childGroupsLength + controller.tree.length;
+            }
+
             $group
               .addClass("tree-root")
               .hide()
@@ -54,13 +79,12 @@ var TreeController = {
                   'images/pandora.png" />' +
                   "<span class='margin-left-1'>" +
                   (controller.tree.length > 0
-                    ? controller.foundMessage + ": " + controller.tree.length
+                    ? controller.foundMessage + ": " + messageLength
                     : "") +
                   "</div>"
               );
-          }
-          // Normal group
-          else {
+          } else {
+            // Normal group.
             $group.addClass("tree-group").hide();
           }