mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Fixed agents count in tree view. Ticket#3248
This commit is contained in:
parent
a837e110d0
commit
0984a06f25
@ -1132,28 +1132,31 @@ class Tree {
|
|||||||
}
|
}
|
||||||
// Build the group hierarchy
|
// Build the group hierarchy
|
||||||
foreach ($groups as $id => $group) {
|
foreach ($groups as $id => $group) {
|
||||||
if (!isset($groups[$id]['parent']))
|
if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) {
|
||||||
continue;
|
|
||||||
$parent = $groups[$id]['parent'];
|
$parent = $groups[$id]['parent'];
|
||||||
// Parent exists
|
// Parent exists
|
||||||
if (isset($groups[$parent])) {
|
if (!isset($groups[$parent]['children'])) {
|
||||||
if (!isset($groups[$parent]['children']))
|
|
||||||
$groups[$parent]['children'] = array();
|
$groups[$parent]['children'] = array();
|
||||||
|
}
|
||||||
// Store a reference to the group into the parent
|
// Store a reference to the group into the parent
|
||||||
$groups[$parent]['children'][] = &$groups[$id];
|
$groups[$parent]['children'][] = &$groups[$id];
|
||||||
|
|
||||||
// Add the child counters to the parent
|
|
||||||
if (isset($groups[$id]['counters']) && !empty($groups[$id]['counters'])) {
|
|
||||||
foreach ($groups[$id]['counters'] as $type => $value) {
|
|
||||||
if (isset($groups[$parent]['counters'][$type]))
|
|
||||||
$groups[$parent]['counters'][$type] += $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This group was introduced into a parent
|
// This group was introduced into a parent
|
||||||
$groups[$id]['have_parent'] = true;
|
$groups[$id]['have_parent'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Sort the children groups
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (isset($groups[$id]['children'])) {
|
||||||
|
usort($groups[$id]['children'], array("Tree", "cmpSortNames"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Filter groups and eliminates the reference to children groups out of her parent
|
||||||
|
$groups = array_filter($groups, function ($group) {
|
||||||
|
return !$group['have_parent'];
|
||||||
|
});
|
||||||
|
// Propagate child counters to her parents
|
||||||
|
Tree::processCounters($groups);
|
||||||
|
// Filter groups and eliminates the reference to empty groups
|
||||||
if ($remove_empty) {
|
if ($remove_empty) {
|
||||||
// Filter empty groups
|
// Filter empty groups
|
||||||
$groups = array_filter($groups, function ($group) {
|
$groups = array_filter($groups, function ($group) {
|
||||||
@ -1162,27 +1165,7 @@ class Tree {
|
|||||||
!empty($group['counters']['total']));
|
!empty($group['counters']['total']));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Sort the children groups
|
return $groups;
|
||||||
foreach ($groups as $id => $group) {
|
|
||||||
if (isset($groups[$id]['children'])) {
|
|
||||||
if ($remove_empty) {
|
|
||||||
// Remove empty childs
|
|
||||||
$groups[$id]['children'] = array_filter($groups[$id]['children'], function ($g) use ($groups) {
|
|
||||||
return (!empty($g) && isset($g['id']) && isset($groups[$g['id']]));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
usort($groups[$id]['children'], array("Tree", "cmpSortNames"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Extract the root groups
|
|
||||||
foreach ($groups as $group) {
|
|
||||||
if (!$group['have_parent'])
|
|
||||||
$processed_groups[] = $group;
|
|
||||||
}
|
|
||||||
// Sort the root groups
|
|
||||||
usort($processed_groups, array("Tree", "cmpSortNames"));
|
|
||||||
|
|
||||||
return $processed_groups;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getProcessedItem ($item, $server = false, &$items = array(), &$items_tmp = array(), $remove_empty = false) {
|
protected function getProcessedItem ($item, $server = false, &$items = array(), &$items_tmp = array(), $remove_empty = false) {
|
||||||
@ -2556,5 +2539,25 @@ class Tree {
|
|||||||
|
|
||||||
return $this->tree;
|
return $this->tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function processCounters(&$groups) {
|
||||||
|
$all_counters = [];
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
$child_counters = [];
|
||||||
|
if (!empty($groups[$id]['children'])) {
|
||||||
|
$child_counters = Tree::processCounters($groups[$id]['children']);
|
||||||
|
}
|
||||||
|
if (!empty($child_counters)) {
|
||||||
|
foreach($child_counters as $type => $value) {
|
||||||
|
$groups[$id]['counters'][$type] += $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($groups[$id]['counters'] as $type => $value) {
|
||||||
|
$all_counters[$type] += $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $all_counters;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -488,7 +488,10 @@ var TreeController = {
|
|||||||
|
|
||||||
// Load the status counters
|
// Load the status counters
|
||||||
var hasCounters = _processNodeCounters($content, element.counters, element.type);
|
var hasCounters = _processNodeCounters($content, element.counters, element.type);
|
||||||
|
//Don't show empty groups
|
||||||
|
if (!hasCounters) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// If exist the detail container, show the data
|
// If exist the detail container, show the data
|
||||||
if (typeof controller.detailRecipient !== 'undefined') {
|
if (typeof controller.detailRecipient !== 'undefined') {
|
||||||
if (element.type == 'agent' || element.type == 'module') {
|
if (element.type == 'agent' || element.type == 'module') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user