mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-02-04 01:09:25 -05:00
NodeCreateAction: allow to add root nodes
This commit is contained in:
parent
03605cac52
commit
a784b384f4
2 changed files with 40 additions and 9 deletions
|
|
@ -41,6 +41,9 @@ class AddNodeForm extends QuickForm
|
|||
case 'process':
|
||||
$this->selectProcess();
|
||||
break;
|
||||
case 'new-process':
|
||||
$this->addNewProcess();
|
||||
break;
|
||||
case null:
|
||||
$this->setSubmitLabel($this->translate('Next'));
|
||||
return;
|
||||
|
|
@ -98,7 +101,7 @@ class AddNodeForm extends QuickForm
|
|||
)
|
||||
));
|
||||
|
||||
$this->addElement('text', 'url', array(
|
||||
$this->addElement('text', 'infoUrl', array(
|
||||
'label' => $this->translate('Info URL'),
|
||||
'description' => $this->translate(
|
||||
'URL pointing to more information about this node'
|
||||
|
|
@ -116,7 +119,12 @@ class AddNodeForm extends QuickForm
|
|||
$types['host'] = $this->translate('Host');
|
||||
$types['service'] = $this->translate('Service');
|
||||
}
|
||||
$types['process'] = $this->translate('Process');
|
||||
|
||||
if ($this->hasProcesses()) {
|
||||
$types['process'] = $this->translate('Existing Process');
|
||||
}
|
||||
|
||||
$types['new-process'] = $this->translate('New Process Node');
|
||||
|
||||
$this->addElement('select', 'node_type', array(
|
||||
'label' => $this->translate('Node type'),
|
||||
|
|
@ -124,6 +132,7 @@ class AddNodeForm extends QuickForm
|
|||
'description' => $this->translate(
|
||||
'The node type you want to add'
|
||||
),
|
||||
'ignore' => true,
|
||||
'class' => 'autosubmit',
|
||||
'multiOptions' => $this->optionalEnum($types)
|
||||
));
|
||||
|
|
@ -269,6 +278,11 @@ class AddNodeForm extends QuickForm
|
|||
return $services;
|
||||
}
|
||||
|
||||
protected function hasProcesses()
|
||||
{
|
||||
return count($this->enumProcesses()) > 0;
|
||||
}
|
||||
|
||||
protected function enumProcesses()
|
||||
{
|
||||
$list = array();
|
||||
|
|
@ -320,7 +334,19 @@ class AddNodeForm extends QuickForm
|
|||
public function onSuccess()
|
||||
{
|
||||
$changes = ProcessChanges::construct($this->bp, $this->session);
|
||||
$changes->addChildrenToNode($this->parent, $this->bp);
|
||||
switch ($this->getValue('node_type')) {
|
||||
case 'host':
|
||||
case 'service':
|
||||
case 'process':
|
||||
$changes->addChildrenToNode($this->getValue('children'), $this->parent);
|
||||
break;
|
||||
case 'new-process':
|
||||
$properties = $this->getValues();
|
||||
unset($properties['name']);
|
||||
$changes->createNode($this->getValue('name'), $properties);
|
||||
break;
|
||||
}
|
||||
|
||||
parent::onSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,12 +58,12 @@ class NodeCreateAction extends NodeAction
|
|||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $properties
|
||||
* @param array $properties
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperties(stdClass $properties)
|
||||
public function setProperties($properties)
|
||||
{
|
||||
$this->properties = $properties;
|
||||
$this->properties = (array) $properties;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -82,11 +82,16 @@ class NodeCreateAction extends NodeAction
|
|||
{
|
||||
$name = $this->getNodeName();
|
||||
|
||||
$node = new BpNode($bp, (object) array(
|
||||
$properties = array(
|
||||
'name' => $name,
|
||||
'operator' => $this->properties['operator'],
|
||||
'child_names' => $this->properties['childNames']
|
||||
));
|
||||
);
|
||||
if (array_key_exists('childNames', $this->properties)) {
|
||||
$properties['child_names'] = $this->properties['childNames'];
|
||||
} else {
|
||||
$properties['child_names'] = array();
|
||||
}
|
||||
$node = new BpNode($bp, (object) $properties);
|
||||
|
||||
foreach ($this->getProperties() as $key => $val) {
|
||||
$func = 'set' . ucfirst($key);
|
||||
|
|
|
|||
Loading…
Reference in a new issue