From a784b384f450fb3a95524237a21a19d02a7285da Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 7 Dec 2016 16:02:06 +0100 Subject: [PATCH] NodeCreateAction: allow to add root nodes --- application/forms/AddNodeForm.php | 32 +++++++++++++++++-- .../Modification/NodeCreateAction.php | 17 ++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/application/forms/AddNodeForm.php b/application/forms/AddNodeForm.php index 1627a1b..ecb583c 100644 --- a/application/forms/AddNodeForm.php +++ b/application/forms/AddNodeForm.php @@ -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(); } } diff --git a/library/Businessprocess/Modification/NodeCreateAction.php b/library/Businessprocess/Modification/NodeCreateAction.php index 4d970dc..04ab474 100644 --- a/library/Businessprocess/Modification/NodeCreateAction.php +++ b/library/Businessprocess/Modification/NodeCreateAction.php @@ -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);