mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 23:00:16 -05:00
BpConfigForm: deal with new Metadata object
This commit is contained in:
parent
d24d0237f4
commit
791a0286b8
1 changed files with 54 additions and 58 deletions
|
|
@ -3,18 +3,19 @@
|
||||||
namespace Icinga\Module\Businessprocess\Forms;
|
namespace Icinga\Module\Businessprocess\Forms;
|
||||||
|
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Authentication\Auth;
|
||||||
use Icinga\Module\Businessprocess\BusinessProcess;
|
use Icinga\Module\Businessprocess\BusinessProcess;
|
||||||
|
use Icinga\Module\Businessprocess\Storage\Storage;
|
||||||
use Icinga\Module\Businessprocess\Web\Form\QuickForm;
|
use Icinga\Module\Businessprocess\Web\Form\QuickForm;
|
||||||
use Icinga\Web\Notification;
|
|
||||||
use Icinga\Web\Request;
|
|
||||||
use Icinga\Web\Url;
|
|
||||||
|
|
||||||
class BpConfigForm extends QuickForm
|
class BpConfigForm extends QuickForm
|
||||||
{
|
{
|
||||||
|
/** @var Storage */
|
||||||
protected $storage;
|
protected $storage;
|
||||||
|
|
||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
|
/** @var BusinessProcess */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
protected $node;
|
protected $node;
|
||||||
|
|
@ -27,16 +28,15 @@ class BpConfigForm extends QuickForm
|
||||||
|
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->addElement('text', 'name', array(
|
$this->addElement('text', 'name', array(
|
||||||
'label' => $this->translate('Name'),
|
'label' => $this->translate('Name'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'This is the unique identifier of this process'
|
'This is the unique identifier of this process'
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->addElement('text', 'title', array(
|
$this->addElement('text', 'Title', array(
|
||||||
'label' => $this->translate('Title'),
|
'label' => $this->translate('Title'),
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'Usually this title will be shown for this process. Equals name'
|
'Usually this title will be shown for this process. Equals name'
|
||||||
|
|
@ -44,7 +44,15 @@ class BpConfigForm extends QuickForm
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->addElement('select', 'backend_name', array(
|
$this->addElement('textarea', 'Description', array(
|
||||||
|
'label' => $this->translate('Description'),
|
||||||
|
'description' => $this->translate(
|
||||||
|
'A slightly more detailed description for this process, about 100-150 characters long '
|
||||||
|
),
|
||||||
|
'rows' => 4,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->addElement('select', 'Backend', array(
|
||||||
'label' => $this->translate('Backend'),
|
'label' => $this->translate('Backend'),
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'Icinga Web Monitoring Backend where current object states for'
|
'Icinga Web Monitoring Backend where current object states for'
|
||||||
|
|
@ -55,15 +63,27 @@ class BpConfigForm extends QuickForm
|
||||||
) + $this->listAvailableBackends()
|
) + $this->listAvailableBackends()
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->addElement('select', 'state_type', array(
|
$this->addElement('select', 'Statetype', array(
|
||||||
'label' => $this->translate('State Type'),
|
'label' => $this->translate('State Type'),
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'Whether this process should be based on Icinga hard or soft states'
|
'Whether this process should be based on Icinga hard or soft states'
|
||||||
),
|
),
|
||||||
'multiOptions' => array(
|
'multiOptions' => array(
|
||||||
'hard' => $this->translate('Use HARD states'),
|
|
||||||
'soft' => $this->translate('Use SOFT states'),
|
'soft' => $this->translate('Use SOFT states'),
|
||||||
|
'hard' => $this->translate('Use HARD states'),
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->addElement('select', 'AddToMenu', array(
|
||||||
|
'label' => $this->translate('Add to menu'),
|
||||||
|
'required' => true,
|
||||||
|
'description' => $this->translate(
|
||||||
|
'Whether this process should be linked in the main Icinga Web 2 menu'
|
||||||
|
),
|
||||||
|
'multiOptions' => array(
|
||||||
|
'yes' => $this->translate('Yes'),
|
||||||
|
'no' => $this->translate('No'),
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
@ -74,28 +94,20 @@ class BpConfigForm extends QuickForm
|
||||||
} else {
|
} else {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
|
|
||||||
|
$meta = $config->getMetadata();
|
||||||
|
foreach ($meta->getProperties() as $k => $v) {
|
||||||
|
if ($el = $this->getElement($k)) {
|
||||||
|
$el->setValue($v);
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->getElement('name')
|
$this->getElement('name')
|
||||||
->setValue($config->getName())
|
->setValue($config->getName())
|
||||||
->setAttrib('readonly', true);
|
->setAttrib('readonly', true);
|
||||||
|
|
||||||
if ($config->hasTitle()) {
|
|
||||||
$this->getElement('title')->setValue($config->getTitle());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($config->hasBackend()) {
|
|
||||||
$this->getElement('backend_name')->setValue(
|
|
||||||
$config->getBackend()->getName()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ($config->usesSoftStates()) {
|
|
||||||
$this->getElement('state_type')->setValue('soft');
|
|
||||||
} else {
|
|
||||||
$this->getElement('state_type')->setValue('hard');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setSubmitLabel(
|
$this->setSubmitLabel(
|
||||||
$this->translate('Store')
|
$this->translate('Store')
|
||||||
);
|
);
|
||||||
|
|
||||||
$label = $this->translate('Delete');
|
$label = $this->translate('Delete');
|
||||||
$el = $this->createElement('submit', $label)
|
$el = $this->createElement('submit', $label)
|
||||||
->setLabel($label)
|
->setLabel($label)
|
||||||
|
|
@ -121,7 +133,6 @@ class BpConfigForm extends QuickForm
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
return $this;
|
return $this;
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onRequest()
|
protected function onRequest()
|
||||||
|
|
@ -138,53 +149,38 @@ class BpConfigForm extends QuickForm
|
||||||
|
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
$name = $this->getValue('name');
|
$name = $this->getValue('name');
|
||||||
$title = $this->getValue('title');
|
|
||||||
$backend = $this->getValue('backend');
|
|
||||||
|
|
||||||
if ($this->config === null) {
|
if ($this->config === null) {
|
||||||
// New config
|
// New config
|
||||||
$config = new BusinessProcess();
|
$config = new BusinessProcess();
|
||||||
$config->setName($name);
|
$config->setName($name);
|
||||||
if ($title) {
|
$config->getMetadata()->set('Owner', Auth::getInstance()->getUser()->getUsername());
|
||||||
$config->setTitle($title);
|
|
||||||
}
|
|
||||||
if ($backend) {
|
|
||||||
$config->setBackendName($backend);
|
|
||||||
}
|
|
||||||
if ($this->getValue('state_type') === 'soft') {
|
|
||||||
$config->useSoftStates();
|
|
||||||
} else {
|
|
||||||
$config->useHardStates();
|
|
||||||
}
|
|
||||||
$this->storage->storeProcess($config);
|
|
||||||
$config->clearAppliedChanges();
|
|
||||||
$this->setSuccessUrl(
|
$this->setSuccessUrl(
|
||||||
$this->getSuccessUrl()->setParams(
|
$this->getSuccessUrl()->setParams(
|
||||||
array('config' => $name, 'unlocked' => true)
|
array('config' => $name, 'unlocked' => true)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->setSuccessMessage(sprintf('Process %s has been created', $name));
|
||||||
|
|
||||||
$this->redirectOnSuccess(sprintf('Process %s has been created', $name));
|
|
||||||
} else {
|
} else {
|
||||||
$config = $this->config;
|
$config = $this->config;
|
||||||
if ($title) {
|
$this->setSuccessMessage(sprintf('Process %s has been stored', $name));
|
||||||
$config->setTitle($title);
|
|
||||||
}
|
|
||||||
if ($backend) {
|
|
||||||
$config->setBackendName($backend);
|
|
||||||
}
|
|
||||||
if ($this->getValue('state_type') === 'soft') {
|
|
||||||
$config->useSoftStates();
|
|
||||||
} else {
|
|
||||||
$config->useHardStates();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->storage->storeProcess($config);
|
|
||||||
$config->clearAppliedChanges();
|
|
||||||
$this->getSuccessUrl()->setParam('config', $name);
|
|
||||||
Notification::success(sprintf('Process %s has been stored', $name));
|
|
||||||
}
|
}
|
||||||
|
$meta = $config->getMetadata();
|
||||||
|
foreach ($this->getValues() as $key => $value) {
|
||||||
|
if ($value === null || $value === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($meta->hasKey($key)) {
|
||||||
|
$meta->set($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->storage->storeProcess($config);
|
||||||
|
$config->clearAppliedChanges();
|
||||||
|
$this->setSuccessUrl('businessprocess/process/show', array('config' => $name));
|
||||||
|
parent::onSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasDeleteButton()
|
public function hasDeleteButton()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue