Dependency: prepare var rendering, cleanup

This commit is contained in:
Thomas Gelf 2019-07-04 08:26:31 +02:00
parent 8f4a93dd08
commit adace00df4
2 changed files with 77 additions and 57 deletions

View File

@ -188,60 +188,57 @@ class IcingaDependencyForm extends DirectorObjectForm
*/ */
protected function addObjectsElement() protected function addObjectsElement()
{ {
$this->addElement( $dependency = $this->getObject();
'text', $parentHost = $dependency->get('parent_host');
'parent_host', if ($parentHost === null) {
array( $parentHost = $dependency->get('parent_host_var');
'label' => $this->translate('Parent Host'), }
'description' => $this->translate( $this->addElement('text', 'parent_host', [
'The parent host.' 'label' => $this->translate('Parent Host'),
), 'description' => $this->translate(
'class' => "autosubmit director-suggest", 'The parent host.'
'data-suggestion-context' => 'hostnames', ),
'order' => 10, 'class' => "autosubmit director-suggest",
'required' => $this->isObject(), 'data-suggestion-context' => 'hostnames',
'value' => $this->getObject()->get('parent_host') 'order' => 10,
'required' => $this->isObject(),
'value' => $parentHost
]);
$sentParent = $this->getSentOrObjectValue('parent_host');
) if (!empty($sentParent) || $dependency->isApplyRule()) {
); $parentService = $dependency->get('parent_service');
$sent_parent=$this->getSentOrObjectValue("parent_host"); if ($parentService === null) {
$parentService = $dependency->get('parent_service_var');
if (!empty($sent_parent) || $this->object->isApplyRule()) { }
$this->addElement( $this->addElement('text', 'parent_service', [
'text',
'parent_service',
array(
'label' => $this->translate('Parent Service'), 'label' => $this->translate('Parent Service'),
'description' => $this->translate( 'description' => $this->translate(
'Optional. The parent service. If omitted this dependency object is treated as host dependency.' 'Optional. The parent service. If omitted this dependency'
. ' object is treated as host dependency.'
), ),
'class' => "autosubmit director-suggest", 'class' => "autosubmit director-suggest",
'data-suggestion-context' => 'servicenames', 'data-suggestion-context' => 'servicenames',
'data-suggestion-for-host' => $sent_parent, 'data-suggestion-for-host' => $sentParent,
'order' => 20, 'order' => 20,
'value' => $this->getObject()->get('parent_service') 'value' => $parentService
) ]);
);
} }
// If configuring Object, allow selection of child host and/or service, // If configuring Object, allow selection of child host and/or service,
// otherwise apply rules will determine child object. // otherwise apply rules will determine child object.
if ($this->isObject()) { if ($dependency->isObject()) {
$this->addElement( $this->addElement('text', 'child_host', [
'text', 'label' => $this->translate('Child Host'),
'child_host', 'description' => $this->translate(
array( 'The child host.'
'label' => $this->translate('Child Host'), ),
'description' => $this->translate( 'value' => $dependency->get('child_host'),
'The child host.' 'order' => 30,
), 'class' => "autosubmit director-suggest",
'value' => $this->getObject()->get('child_host'), 'required' => $this->isObject(),
'order' => 30, 'data-suggestion-context' => 'hostnames',
'class' => "autosubmit director-suggest", ]);
'required' => $this->isObject(),
'data-suggestion-context' => 'hostnames',
)
);
$sent_child=$this->getSentOrObjectValue("child_host"); $sent_child=$this->getSentOrObjectValue("child_host");

View File

@ -60,6 +60,13 @@ class IcingaDependency extends IcingaObject implements ExportInterface
'ignore_soft_states' => 'ignore_soft_states' 'ignore_soft_states' => 'ignore_soft_states'
]; ];
protected $propertiesNotForRendering = [
'id',
'object_name',
'object_type',
'apply_to',
];
public function getUniqueIdentifier() public function getUniqueIdentifier()
{ {
return $this->getObjectName(); return $this->getObjectName();
@ -107,20 +114,6 @@ class IcingaDependency extends IcingaObject implements ExportInterface
return $object; return $object;
} }
/**
* Do not render internal property apply_to
*
* Avoid complaints for method names with underscore:
* @codingStandardsIgnoreStart
*
* @return string
*/
public function renderApply_to()
{
// @codingStandardsIgnoreEnd
return '';
}
/** /**
* @return string * @return string
* @throws ConfigurationError * @throws ConfigurationError
@ -318,6 +311,21 @@ class IcingaDependency extends IcingaObject implements ExportInterface
); );
} }
/**
* Render parent_host_var as parent_host
* @codingStandardsIgnoreStart
*
* @return string
*/
public function renderParent_host_var()
{
// @codingStandardsIgnoreEnd
return c::renderKeyValue(
'parent_host',
$this->get('parent_host_var')
);
}
/** /**
* Render child_service_id as host_name * Render child_service_id as host_name
* *
@ -360,6 +368,21 @@ class IcingaDependency extends IcingaObject implements ExportInterface
); );
} }
/**
* Render parent_service_var as parent_service_name
* @codingStandardsIgnoreStart
*
* @return string
*/
public function renderParent_service_var()
{
// @codingStandardsIgnoreEnd
return c::renderKeyValue(
'parent_service',
$this->get('parent_host_var')
);
}
//special case for parent service set as plain string for Apply rules //special case for parent service set as plain string for Apply rules
public function renderParent_service_by_name() public function renderParent_service_by_name()
{ {