process/show: render errors - if any

This commit is contained in:
Thomas Gelf 2015-03-03 10:50:19 +01:00
parent 33dde6e7d8
commit 6cfba947d6
4 changed files with 37 additions and 4 deletions

View file

@ -14,6 +14,7 @@ class Businessprocess_NodeController extends Controller
$form = new ProcessForm();
$form->setProcess($bp)
->setSession($this->session())
->setNode($node)
->handleRequest();

View file

@ -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 {

View file

@ -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()));
}
}

View file

@ -11,6 +11,13 @@
<form method="post" action="<?= $this->url()->without('process') ?>" data-base-target="_self">
<?= $this->formSelect('processName', $this->processName, array('class' => 'autosubmit'), $this->processList) ?>
</form>
<?php if (! empty($this->errors)): ?>
<ul class="error">
<?php foreach ($this->errors as $error): ?>
<li><?= $this->escape($error) ?></li>
<?php endforeach ?>
</ul>
<?php endif ?>
<?= $this->bp->renderHtml($this) ?>
<?= $this->render('warnings.phtml') ?>
</div>