From e33a9bc3e4f88735814b3c2e5fadf9455477aae9 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@pandorafms.com>
Date: Mon, 6 Mar 2023 13:32:21 +0100
Subject: [PATCH] Services TreeView

---
 .../include/class/TreeService.class.php       | 27 +++++++++-------
 .../include/functions_treeview.php            |  4 +--
 .../include/javascript/tree/TreeController.js |  2 +-
 pandora_console/include/lib/Module.php        | 31 +++++++++++++++++++
 pandora_console/include/styles/tree.css       | 26 ++++++++++------
 5 files changed, 67 insertions(+), 23 deletions(-)

diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php
index e68158c117..69b06fd684 100644
--- a/pandora_console/include/class/TreeService.class.php
+++ b/pandora_console/include/class/TreeService.class.php
@@ -222,22 +222,30 @@ class TreeService extends Tree
 
             switch ($status) {
                 case SERVICE_STATUS_NORMAL:
-                    $processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_ok_ball.png').'" data-title="NORMAL status." data-use_title_for_force_title="1" class="forced_title" alt="NORMAL status." />';
+                    $serviceStatusLine = COL_NORMAL;
                 break;
 
                 case SERVICE_STATUS_CRITICAL:
-                    $processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_critical_ball.png').'" data-title="CRITICAL status." data-use_title_for_force_title="1" class="forced_title" alt="CRITICAL status." />';
+                    $serviceStatusLine = COL_CRITICAL;
                 break;
 
                 case SERVICE_STATUS_WARNING:
-                    $processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_warning_ball.png').'" data-title="WARNING status." data-use_title_for_force_title="1" class="forced_title" alt="WARNING status." />';
+                    $serviceStatusLine = COL_WARNING;
                 break;
 
                 case SERVICE_STATUS_UNKNOWN:
                 default:
-                    $processed_items[$row['id']]['statusImageHTML'] = '<img src="'.ui_get_full_url('images/status_sets/default/agent_no_data_ball.png').'" data-title="UNKNOWN status." data-use_title_for_force_title="1" class="forced_title" alt="UNKNOWN status." />';
+                    $serviceStatusLine = COL_UNKNOWN;
                 break;
             }
+
+            $processed_items[$row['id']]['statusImageHTML'] = html_print_div(
+                [
+                    'class' => 'node-service-status',
+                    'style' => 'background-color: '.$serviceStatusLine,
+                ],
+                true
+            );
         }
 
         $this->tree = $processed_items;
@@ -510,14 +518,11 @@ class TreeService extends Tree
                     $tmp['eventAgent'] = $item->module()->id_agente();
                     $tmp['disabled'] = $item->module()->disabled();
 
-                    $html = '<img src="';
-                    $html .= ui_get_full_url(
-                        '/images/status_sets/default/'.$item->module()->lastStatusImage()
+                    $html = html_print_div(
+                        [ 'style' => 'width:7px;background-color: '.$item->module()->lastStatusColor() ],
+                        true
                     );
-                    $html .= '" data-title="'.$title;
-                    $html .= '" data-use_title_for_force_title="1" ';
-                    $html .= 'class="forced_title" alt="';
-                    $html .= $item->module()->lastStatusTitle().'" />';
+
                     $tmp['statusImageHTML'] = $html;
                     $tmp = array_merge(
                         $tmp,
diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php
index b92aae0ce2..b43d6bba95 100755
--- a/pandora_console/include/functions_treeview.php
+++ b/pandora_console/include/functions_treeview.php
@@ -702,7 +702,7 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false)
     // Events graph toggle.
     $eventsGraph = html_print_div(
         [
-            'class'   => 'graphic_agents',
+            'style'   => 'height: 150px;',
             'content' => graph_graphic_agentevents(
                 $id_agente,
                 '500px;',
@@ -732,7 +732,7 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false)
     );
 
     if ($config['agentaccess']) {
-        $access_graph = '<div class="w100p height_130px center">';
+        $access_graph = '<div style="height: 150px;" class="w100p center">';
         $access_graph .= graphic_agentaccess(
             $id_agente,
             SECONDS_1DAY,
diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js
index 51c69830cd..0adc31586f 100644
--- a/pandora_console/include/javascript/tree/TreeController.js
+++ b/pandora_console/include/javascript/tree/TreeController.js
@@ -980,7 +980,7 @@ var TreeController = {
               break;
             case "module":
               $content.addClass("module");
-              //console.log(element);                $statusImage.addClass("node-status");
+
               // Status image
               if (
                 typeof element.statusImageHTML != "undefined" &&
diff --git a/pandora_console/include/lib/Module.php b/pandora_console/include/lib/Module.php
index d0687c2d8c..843d239463 100644
--- a/pandora_console/include/lib/Module.php
+++ b/pandora_console/include/lib/Module.php
@@ -512,6 +512,37 @@ class Module extends Entity
     }
 
 
+    /**
+     * Return the color to image representing last status.
+     *
+     * @return string Hexadecimal notation color.
+     */
+    public function lastStatusColor()
+    {
+        switch ($this->lastStatus()) {
+            case AGENT_MODULE_STATUS_CRITICAL_ALERT:
+            case AGENT_MODULE_STATUS_CRITICAL_BAD:
+            return COL_CRITICAL;
+
+            case AGENT_MODULE_STATUS_WARNING_ALERT:
+            case AGENT_MODULE_STATUS_WARNING:
+            return COL_WARNING;
+
+            case AGENT_MODULE_STATUS_UNKNOWN:
+            return COL_UNKNOWN;
+
+            case AGENT_MODULE_STATUS_NO_DATA:
+            case AGENT_MODULE_STATUS_NOT_INIT:
+            return COL_NOTINIT;
+
+            case AGENT_MODULE_STATUS_NORMAL_ALERT:
+            case AGENT_MODULE_STATUS_NORMAL:
+            default:
+            return COL_NORMAL;
+        }
+    }
+
+
     /**
      * Return path to image representing last status.
      *
diff --git a/pandora_console/include/styles/tree.css b/pandora_console/include/styles/tree.css
index d9a4f00c2c..61ad75716d 100644
--- a/pandora_console/include/styles/tree.css
+++ b/pandora_console/include/styles/tree.css
@@ -55,11 +55,11 @@
   position: absolute;
   border-radius: 8px;
   width: 18px;
-  height: 18px;
-  top: 6px;
+  height: 20px;
+  top: 5px;
   margin: 0;
   padding: 0;
-  left: 13px;
+  left: 6px;
 }
 .tree-node .node-name {
   position: relative;
@@ -236,18 +236,20 @@ div.tree-node span {
 }
 
 .node-content.module:not(.module-only-caption) .module-name {
-  margin-left: 3em;
+  margin-left: 1.5em;
   font-weight: normal;
 }
-/*.node-content.module.module-only-caption:not(:first-of-type) {
-  margin-top: 8px;
-}*/
 
+.tree-node > .node-content > .status_balls,
+.tree-node > .node-content > .status_small_balls {
+  width: 6px;
+  border-radius: 4px;
+}
 .tree-node > .node-content > .module-name-alias {
   font-size: 14px;
   font-weight: normal;
   top: 4px;
-  margin-left: 3.3em;
+  margin-left: 1.1em;
 }
 
 .tree-node > .node-content.module-only-caption > .module-name-alias {
@@ -306,7 +308,7 @@ div.tree-node span {
 
 .tree-node > .node-content > .tree-node-counters > .tree-node-counter {
   font-weight: bold;
-  font-size: 0.9em;
+  font-size: 1em;
   cursor: default;
 }
 
@@ -326,6 +328,12 @@ div#tree-controller-recipient {
   /*margin-left: 3px;*/
 }
 
+.tree-node .node-service div.node-service-status {
+  width: 6px;
+  height: 20px;
+  margin-left: 10px;
+  border-radius: 5px;
+}
 .tree-node .disabled {
   filter: opacity(0.3);
 }