Merge branch 'ent-7757-12115-anadir-ruta-completa-en-nombre-de-servicio-en-consola-visual-dashboard' into 'develop'

Service tree view with local scope parents

See merge request artica/pandorafms!4826
This commit is contained in:
Daniel Rodriguez 2022-06-07 10:47:26 +00:00
commit bf7941ddd2
5 changed files with 75 additions and 3 deletions

View File

@ -954,7 +954,7 @@ echo sprintf('<div id="header_table" class="header_table_%s">', $menuTypeClass);
$("a.autorefresh").click (function () {
$("a.autorefresh_txt").toggle ();
$("#combo_refr").toggle ();
$("#combo_refr").toggle();
$("select#ref").change (function () {
href = $("a.autorefresh").attr ("href");

View File

@ -523,6 +523,14 @@ class TreeService extends Tree
continue 2;
}
$title = get_parameter('title', '');
if (empty($title) === true) {
$tmp['title'] = '';
} else {
$tmp['title'] = $title.'/';
}
$tmp['title'] .= $service->name();
$tmp['id'] = (int) $item->service()->id();
$tmp['name'] = $item->service()->name();
$tmp['alias'] = $item->service()->name();

View File

@ -5986,6 +5986,56 @@ function send_test_email(
}
/**
* Return array of ancestors of item, given array.
*
* @param integer $item From index.
* @param array $data Array data.
* @param string $key Pivot key (identifies the parent).
* @param string|null $extract Extract certain column or index.
* @param array $visited Cycle detection.
*
* @return array Array of ancestors.
*/
function get_ancestors(
int $item,
array $data,
string $key,
?string $extract=null,
array &$visited=[]
) :array {
if (isset($visited[$item]) === true) {
return [];
}
$visited[$item] = 1;
if (isset($data[$item]) === false) {
return [];
}
if (isset($data[$item][$key]) === false) {
if ($extract !== null) {
return [$data[$item][$extract]];
}
return [$item];
}
if ($extract !== null) {
return array_merge(
get_ancestors($data[$item][$key], $data, $key, $extract, $visited),
[$data[$item][$extract]]
);
}
return array_merge(
get_ancestors($data[$item][$key], $data, $key, $extract, $visited),
[$item]
);
}
if (function_exists('str_contains') === false) {

View File

@ -861,7 +861,7 @@ var TreeController = {
'<span><img class="invert_filter" src="' +
(controller.baseURL.length > 0 ? controller.baseURL : "") +
'images/help.png" class="img_help" title="' +
element.name +
(element.title ? element.title : element.name) +
'" alt="' +
element.name +
'"/></span> ';
@ -1314,6 +1314,7 @@ var TreeController = {
serverID: element.serverID,
rootType: element.rootType,
metaID: element.metaID,
title: element.title,
filter: controller.filter,
auth_class: controller.auth_class,
id_user: controller.id_user,

View File

@ -272,7 +272,20 @@ class ServiceMapWidget extends Widget
$fields = array_reduce(
$services_res,
function ($carry, $item) {
$carry[$item['id']] = $item['name'];
$parents = '';
if (class_exists('\PandoraFMS\Enterprise\Service') === true) {
try {
$service = new \PandoraFMS\Enterprise\Service($item['id']);
$ancestors = $service->getAncestors();
if (empty($ancestors) === false) {
$parents = '('.join('/', $ancestors).')';
}
} catch (\Exception $e) {
$parents = '';
}
}
$carry[$item['id']] = $item['name'].' '.$parents;
return $carry;
},
[]