IcingaServiceForm: Change the nested key suggestions to list

This commit is contained in:
raviks789 2025-05-26 14:03:24 +02:00
parent a28a508e5e
commit 79a4e32b3e
No known key found for this signature in database
2 changed files with 77 additions and 7 deletions

View File

@ -14,11 +14,12 @@ use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Objects\IcingaServiceSet;
use Icinga\Module\Director\Web\Table\ObjectsTableHost; use Icinga\Module\Director\Web\Table\ObjectsTableHost;
use ipl\Html\Attributes;
use ipl\Html\Html; use ipl\Html\Html;
use gipfl\IcingaWeb2\Link; use gipfl\IcingaWeb2\Link;
use ipl\Html\HtmlElement; use ipl\Html\HtmlElement;
use ipl\Html\Table;
use ipl\Html\Text; use ipl\Html\Text;
use PDO;
use RuntimeException; use RuntimeException;
class IcingaServiceForm extends DirectorObjectForm class IcingaServiceForm extends DirectorObjectForm
@ -656,12 +657,14 @@ class IcingaServiceForm extends DirectorObjectForm
->from( ->from(
['dp' => 'director_property'], ['dp' => 'director_property'],
[ [
'key_name' => 'dp.label', 'uuid' => 'dp.uuid',
'label' => 'dp.key_name', 'key_name' => 'dp.key_name',
'label' => 'dp.label',
'value_type' => 'dp.value_type'
] ]
)->where("parent_uuid = ?", $dictionaryUuid); )->where("parent_uuid = ?", $dictionaryUuid);
return $this->db->getDbAdapter()->fetchPairs($query); return $this->db->getDbAdapter()->fetchAll($query, fetchMode: PDO::FETCH_ASSOC);
} }
/** /**
@ -696,9 +699,63 @@ class IcingaServiceForm extends DirectorObjectForm
$dictionaryKeys = $this->fetchNestedDictionaryKeys($this->dictionaryUuidMap[$applyFor]); $dictionaryKeys = $this->fetchNestedDictionaryKeys($this->dictionaryUuidMap[$applyFor]);
if (! empty($dictionaryKeys)) { if (! empty($dictionaryKeys)) {
$configVariables = new Table(); $configVariables = new HtmlElement('ul', Attributes::create(['class' => 'nested-key-list']));
foreach ($dictionaryKeys as $label => $key) { foreach ($dictionaryKeys as $keyAttributes) {
$configVariables->add([$label . ' (' . $key . ')', '=>', '$value.' . $key . '$']); $content = [
new HtmlElement('div', null, Text::create(
$keyAttributes['label']
. ' ('
. $keyAttributes['key_name']
. ')'
)),
new HtmlElement('div', null, Text::create('=>'))
];
if ($keyAttributes['value_type'] === 'dict') {
$nestedContent = [];
foreach ($this->fetchNestedDictionaryKeys($keyAttributes['uuid']) as $nestedKeyAttributes) {
$nestedContent = [
new HtmlElement('div', null, Text::create(
$nestedKeyAttributes['label']
. ' ('
. $nestedKeyAttributes['key_name']
. ')'
)),
new HtmlElement('div', null, Text::create('=>')),
new HtmlElement('div', null, Text::create(
'$value.'
. $keyAttributes['key_name']
. '.'
. $nestedKeyAttributes['key_name']
. '$'
))
];
}
$content[] = new HtmlElement(
'div',
null,
new HtmlElement('div', null, Text::create(
'$value.'
. $keyAttributes['key_name']
. '$'
)),
new HtmlElement(
'ul',
null,
new HtmlElement('li', null, ...$nestedContent)
)
);
} else {
$content[] = new HtmlElement('div', null, Text::create(
'$value.'
. $keyAttributes['key_name']
. '$'
));
}
$configVariables->addHtml(new HtmlElement('li', null, ...$content));
} }

View File

@ -17,6 +17,19 @@ table.common-table td {
} }
} }
.nested-key-list, .nested-key-list ul {
list-style-type: none;
padding: 0;
margin: 0;
li {
display: grid;
grid-template-columns: repeat(3, 1fr);
justify-items: center;
width: 100%;
}
}
#layout.minimal-layout table.common-table td { #layout.minimal-layout table.common-table td {
padding-top: 0.5em; padding-top: 0.5em;
padding-bottom: 0.5em; padding-bottom: 0.5em;