Service tree view with local scope parents

This commit is contained in:
fbsanchez 2022-04-20 14:10:23 +02:00
parent b2ea3d1d7a
commit 2ab1aa601c
4 changed files with 55 additions and 2 deletions

View File

@ -523,6 +523,8 @@ class TreeService extends Tree
continue 2;
}
$tmp['parents'] = $item->service()->getAncestors();
$tmp['title'] = join('/', $tmp['parents']);
$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

@ -848,6 +848,7 @@ var TreeController = {
break;
case "services":
console.log(element);
if (
typeof element.statusImageHTML != "undefined" &&
element.statusImageHTML.length > 0
@ -861,7 +862,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> ';