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(
|
||||
'Whether this dependency should affect hosts or services'
|
||||
),
|
||||
'required' => true,
|
||||
'class' => 'autosubmit',
|
||||
'multiOptions' => $this->optionalEnum([
|
||||
'host' => $this->translate('Hosts'),
|
||||
@ -110,7 +111,6 @@ class IcingaDependencyForm extends DirectorObjectForm
|
||||
$suggestionContext = ucfirst($applyTo) . 'FilterColumns';
|
||||
$this->addAssignFilter([
|
||||
'suggestionContext' => $suggestionContext,
|
||||
'required' => true,
|
||||
'description' => $this->translate(
|
||||
'This allows you to configure an assignment filter. Please feel'
|
||||
. ' free to combine as many nested operators as you want. The'
|
||||
@ -191,8 +191,11 @@ class IcingaDependencyForm extends DirectorObjectForm
|
||||
$dependency = $this->getObject();
|
||||
$parentHost = $dependency->get('parent_host');
|
||||
if ($parentHost === null) {
|
||||
$parentHostVar = $dependency->get('parent_host_var');
|
||||
if (\strlen($parentHostVar) > 0) {
|
||||
$parentHost = '$' . $dependency->get('parent_host_var') . '$';
|
||||
}
|
||||
}
|
||||
$this->addElement('text', 'parent_host', [
|
||||
'label' => $this->translate('Parent Host'),
|
||||
'description' => $this->translate(
|
||||
|
@ -176,11 +176,23 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
||||
*/
|
||||
protected function renderSuffix()
|
||||
{
|
||||
if ($this->parentHostIsVar() && ! $this->renderForArray) {
|
||||
return parent::renderSuffix() . $this->renderCloneForArray();
|
||||
} else {
|
||||
if (! $this->parentHostIsVar()) {
|
||||
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()
|
||||
@ -197,19 +209,26 @@ class IcingaDependency extends IcingaObject implements ExportInterface
|
||||
public function renderAssign_Filter()
|
||||
{
|
||||
if ($this->parentHostIsVar()) {
|
||||
$varName = $this->get('parent_host_var');
|
||||
if ($this->renderForArray) {
|
||||
$suffix = sprintf(' && typeof(%s) == Array', $varName);
|
||||
} else {
|
||||
$suffix = sprintf(' && typeof(%s) == String', $varName);
|
||||
}
|
||||
|
||||
return preg_replace('/\n$/m', $suffix, parent::renderAssign_Filter() . "\n");
|
||||
return preg_replace(
|
||||
'/\n$/m',
|
||||
$this->renderAssignFilterExtension(),
|
||||
parent::renderAssign_Filter() . "\n"
|
||||
);
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
// TODO: Check if this method can be removed
|
||||
|
Loading…
x
Reference in New Issue
Block a user