From 6cfba947d6eac491708717988b7b091cb0ecf36c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 3 Mar 2015 10:50:19 +0100 Subject: [PATCH] process/show: render errors - if any --- application/controllers/NodeController.php | 1 + application/controllers/ProcessController.php | 11 +++++++++- application/forms/ProcessForm.php | 22 ++++++++++++++++--- application/views/scripts/process/show.phtml | 7 ++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/application/controllers/NodeController.php b/application/controllers/NodeController.php index 1ecb6d6..eeca69d 100644 --- a/application/controllers/NodeController.php +++ b/application/controllers/NodeController.php @@ -14,6 +14,7 @@ class Businessprocess_NodeController extends Controller $form = new ProcessForm(); $form->setProcess($bp) + ->setSession($this->session()) ->setNode($node) ->handleRequest(); diff --git a/application/controllers/ProcessController.php b/application/controllers/ProcessController.php index 84c383e..098f96e 100644 --- a/application/controllers/ProcessController.php +++ b/application/controllers/ProcessController.php @@ -2,6 +2,7 @@ use Icinga\Module\Businessprocess\Controller; use Icinga\Module\Businessprocess\Storage\LegacyStorage; +use Exception; class Businessprocess_ProcessController extends Controller { @@ -18,7 +19,15 @@ class Businessprocess_ProcessController extends Controller $this->view->tabs = $this->tabs()->activate('show'); $this->view->title = 'Business Processes'; - $bp = $this->loadBp()->retrieveStatesFromBackend(); + + $bp = $this->loadBp(); + try { + $bp->retrieveStatesFromBackend(); + } catch (Exception $e) { + $this->view->errors = array( + 'Could not retrieve process state: ' . $e->getMessage() + ); + } if ($process = $this->params->get('process')) { $this->view->bp = $bp->getNode($process); } else { diff --git a/application/forms/ProcessForm.php b/application/forms/ProcessForm.php index 409fba7..c6c1bf7 100644 --- a/application/forms/ProcessForm.php +++ b/application/forms/ProcessForm.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Businessprocess\Forms; use Icinga\Web\Form; +use Icinga\Web\Notification; use Icinga\Web\Request; use Icinga\Module\Businessprocess\BpNode; @@ -18,6 +19,8 @@ class ProcessForm extends Form protected $processList = array(); + protected $session; + public function __construct($options = null) { parent::__construct($options); @@ -35,8 +38,8 @@ class ProcessForm extends Form 'label' => $this->translate('Operator'), 'required' => true, 'multiOptions' => array( - 'and' => $this->translate('AND'), - 'or ' => $this->translate('OR'), + '&' => $this->translate('AND'), + '|' => $this->translate('OR'), 'min' => $this->translate('min') ) )); @@ -129,8 +132,21 @@ class ProcessForm extends Form return $this; } + public function setSession($session) + { + $this->session = $session; + return $this; + } + public function onSuccess() { - Notification::success(sprintf($message, $this->getElement('name')->getValue())); + $modifications = $this->session->get('modifications', array()); + $node = $this->process->getNode($this->getValue('name')); + $node->setChildNames($this->getValue('children')); + $node->setOperator($this->getValue('operator')); + $modifications[$this->process->getName()] = $this->process->toLegacyConfigString(); + $this->session->set('modifications', $modifications); + $message = 'Process %s has been modified'; + Notification::success(sprintf($message, $this->process->getName())); } } diff --git a/application/views/scripts/process/show.phtml b/application/views/scripts/process/show.phtml index 80fa83e..45cc53f 100644 --- a/application/views/scripts/process/show.phtml +++ b/application/views/scripts/process/show.phtml @@ -11,6 +11,13 @@
formSelect('processName', $this->processName, array('class' => 'autosubmit'), $this->processList) ?>
+errors)): ?> + + bp->renderHtml($this) ?> render('warnings.phtml') ?>