mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 00:04:05 +02:00
IcingaDependency: fix form and rendering
This commit is contained in:
parent
8de93a1a9a
commit
aad07b3d1d
@ -94,6 +94,7 @@ class IcingaDependencyForm extends DirectorObjectForm
|
|||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'Whether this dependency should affect hosts or services'
|
'Whether this dependency should affect hosts or services'
|
||||||
),
|
),
|
||||||
|
'required' => true,
|
||||||
'class' => 'autosubmit',
|
'class' => 'autosubmit',
|
||||||
'multiOptions' => $this->optionalEnum([
|
'multiOptions' => $this->optionalEnum([
|
||||||
'host' => $this->translate('Hosts'),
|
'host' => $this->translate('Hosts'),
|
||||||
@ -110,7 +111,6 @@ class IcingaDependencyForm extends DirectorObjectForm
|
|||||||
$suggestionContext = ucfirst($applyTo) . 'FilterColumns';
|
$suggestionContext = ucfirst($applyTo) . 'FilterColumns';
|
||||||
$this->addAssignFilter([
|
$this->addAssignFilter([
|
||||||
'suggestionContext' => $suggestionContext,
|
'suggestionContext' => $suggestionContext,
|
||||||
'required' => true,
|
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'This allows you to configure an assignment filter. Please feel'
|
'This allows you to configure an assignment filter. Please feel'
|
||||||
. ' free to combine as many nested operators as you want. The'
|
. ' free to combine as many nested operators as you want. The'
|
||||||
@ -191,7 +191,10 @@ class IcingaDependencyForm extends DirectorObjectForm
|
|||||||
$dependency = $this->getObject();
|
$dependency = $this->getObject();
|
||||||
$parentHost = $dependency->get('parent_host');
|
$parentHost = $dependency->get('parent_host');
|
||||||
if ($parentHost === null) {
|
if ($parentHost === null) {
|
||||||
$parentHost = '$' . $dependency->get('parent_host_var') . '$';
|
$parentHostVar = $dependency->get('parent_host_var');
|
||||||
|
if (\strlen($parentHostVar) > 0) {
|
||||||
|
$parentHost = '$' . $dependency->get('parent_host_var') . '$';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->addElement('text', 'parent_host', [
|
$this->addElement('text', 'parent_host', [
|
||||||
'label' => $this->translate('Parent Host'),
|
'label' => $this->translate('Parent Host'),
|
||||||
|
@ -176,11 +176,23 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
*/
|
*/
|
||||||
protected function renderSuffix()
|
protected function renderSuffix()
|
||||||
{
|
{
|
||||||
if ($this->parentHostIsVar() && ! $this->renderForArray) {
|
if (! $this->parentHostIsVar()) {
|
||||||
return parent::renderSuffix() . $this->renderCloneForArray();
|
|
||||||
} else {
|
|
||||||
return parent::renderSuffix();
|
return parent::renderSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\strlen($this->get('assign_filter')) > 0) {
|
||||||
|
$suffix = parent::renderSuffix();
|
||||||
|
} else {
|
||||||
|
$suffix = ' assign where ' . $this->renderAssignFilterExtension('')
|
||||||
|
. "\n" . parent::renderSuffix();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($this->renderForArray) {
|
||||||
|
return $suffix;
|
||||||
|
} else {
|
||||||
|
return $suffix . $this->renderCloneForArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderCloneForArray()
|
protected function renderCloneForArray()
|
||||||
@ -197,19 +209,26 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
|||||||
public function renderAssign_Filter()
|
public function renderAssign_Filter()
|
||||||
{
|
{
|
||||||
if ($this->parentHostIsVar()) {
|
if ($this->parentHostIsVar()) {
|
||||||
$varName = $this->get('parent_host_var');
|
return preg_replace(
|
||||||
if ($this->renderForArray) {
|
'/\n$/m',
|
||||||
$suffix = sprintf(' && typeof(%s) == Array', $varName);
|
$this->renderAssignFilterExtension(),
|
||||||
} else {
|
parent::renderAssign_Filter() . "\n"
|
||||||
$suffix = sprintf(' && typeof(%s) == String', $varName);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return preg_replace('/\n$/m', $suffix, parent::renderAssign_Filter() . "\n");
|
|
||||||
} else {
|
} else {
|
||||||
return parent::renderAssign_Filter();
|
return parent::renderAssign_Filter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function renderAssignFilterExtension($pre = ' && ')
|
||||||
|
{
|
||||||
|
$varName = $this->get('parent_host_var');
|
||||||
|
if ($this->renderForArray) {
|
||||||
|
return sprintf('%stypeof(%s) == Array', $pre, $varName);
|
||||||
|
} else {
|
||||||
|
return sprintf('%stypeof(%s) == String', $pre, $varName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function setKey($key)
|
protected function setKey($key)
|
||||||
{
|
{
|
||||||
// TODO: Check if this method can be removed
|
// TODO: Check if this method can be removed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user