mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-05 13:19:35 -05:00
Save user defined order of processes/nodes
This commit is contained in:
parent
0707d1d7e7
commit
08bfbc462b
2 changed files with 155 additions and 0 deletions
|
|
@ -250,6 +250,14 @@ class ProcessController extends Controller
|
|||
->setNode($bp->getNode($this->params->get('simulationnode')))
|
||||
->setSimulation(Simulation::fromSession($this->session()))
|
||||
->handleRequest();
|
||||
} elseif ($action === 'move') {
|
||||
$form = $this->loadForm('MoveNode')
|
||||
->setProcess($bp)
|
||||
->setParentNode($node)
|
||||
->setSession($this->session())
|
||||
->setNode($bp->getNode($this->params->get('movenode')))
|
||||
->setSuccessUrl(Url::fromRequest()->without(['action', 'movenode']))
|
||||
->handleRequest();
|
||||
}
|
||||
|
||||
if ($form) {
|
||||
|
|
|
|||
147
application/forms/MoveNodeForm.php
Normal file
147
application/forms/MoveNodeForm.php
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\Forms;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Exception\Http\HttpException;
|
||||
use Icinga\Module\Businessprocess\BpConfig;
|
||||
use Icinga\Module\Businessprocess\BpNode;
|
||||
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
|
||||
use Icinga\Module\Businessprocess\Node;
|
||||
use Icinga\Module\Businessprocess\Web\Form\CsrfToken;
|
||||
use Icinga\Module\Businessprocess\Web\Form\QuickForm;
|
||||
use Icinga\Web\Session\SessionNamespace;
|
||||
|
||||
class MoveNodeForm extends QuickForm
|
||||
{
|
||||
/** @var BpConfig */
|
||||
protected $bp;
|
||||
|
||||
/** @var Node */
|
||||
protected $node;
|
||||
|
||||
/** @var BpNode */
|
||||
protected $parentNode;
|
||||
|
||||
/** @var SessionNamespace */
|
||||
protected $session;
|
||||
|
||||
public function __construct($options = null)
|
||||
{
|
||||
parent::__construct($options);
|
||||
|
||||
// Zend's plugin loader reverses the order of added prefix paths thus trying our paths first before trying
|
||||
// Zend paths
|
||||
$this->addPrefixPaths(array(
|
||||
array(
|
||||
'prefix' => 'Icinga\\Web\\Form\\Element\\',
|
||||
'path' => Icinga::app()->getLibraryDir('Icinga/Web/Form/Element'),
|
||||
'type' => static::ELEMENT
|
||||
),
|
||||
array(
|
||||
'prefix' => 'Icinga\\Web\\Form\\Decorator\\',
|
||||
'path' => Icinga::app()->getLibraryDir('Icinga/Web/Form/Decorator'),
|
||||
'type' => static::DECORATOR
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->addElement(
|
||||
'number',
|
||||
'from',
|
||||
[
|
||||
'required' => true,
|
||||
'min' => 0
|
||||
]
|
||||
);
|
||||
$this->addElement(
|
||||
'number',
|
||||
'to',
|
||||
[
|
||||
'required' => true,
|
||||
'min' => 0
|
||||
]
|
||||
);
|
||||
$this->addElement(
|
||||
'hidden',
|
||||
'csrfToken',
|
||||
[
|
||||
'required' => true
|
||||
]
|
||||
);
|
||||
|
||||
$this->setSubmitLabel('movenode');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BpConfig $process
|
||||
* @return $this
|
||||
*/
|
||||
public function setProcess(BpConfig $process)
|
||||
{
|
||||
$this->bp = $process;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node $node
|
||||
* @return $this
|
||||
*/
|
||||
public function setNode(Node $node)
|
||||
{
|
||||
$this->node = $node;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BpNode|null $node
|
||||
* @return $this
|
||||
*/
|
||||
public function setParentNode(BpNode $node = null)
|
||||
{
|
||||
$this->parentNode = $node;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SessionNamespace $session
|
||||
* @return $this
|
||||
*/
|
||||
public function setSession(SessionNamespace $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function onSuccess()
|
||||
{
|
||||
if (! CsrfToken::isValid($this->getValue('csrfToken'))) {
|
||||
throw new HttpException(403, 'nope');
|
||||
}
|
||||
|
||||
$changes = ProcessChanges::construct($this->bp, $this->session);
|
||||
if (! $this->bp->getMetadata()->isManuallyOrdered()) {
|
||||
$changes->applyManualOrder();
|
||||
}
|
||||
|
||||
$changes->moveNode(
|
||||
$this->node,
|
||||
$this->getValue('from'),
|
||||
$this->getValue('to'),
|
||||
$this->parentNode !== null ? $this->parentNode->getName() : null
|
||||
);
|
||||
|
||||
// Trigger session destruction to make sure it get's stored.
|
||||
unset($changes);
|
||||
|
||||
$this->setSuccessMessage($this->translate('Node order updated'));
|
||||
parent::onSuccess();
|
||||
}
|
||||
|
||||
public function hasBeenSent()
|
||||
{
|
||||
return true; // This form has no id
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue