2014-10-20 10:26:06 -04:00
|
|
|
<?php
|
|
|
|
|
|
2015-11-17 08:21:59 -05:00
|
|
|
namespace Icinga\Module\Businessprocess\Controllers;
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
use Icinga\Module\Businessprocess\Controller;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Module\Businessprocess\ConfigDiff;
|
2016-11-28 10:02:21 -05:00
|
|
|
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
|
2016-11-27 18:46:53 -05:00
|
|
|
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Module\Businessprocess\Simulation;
|
2016-11-27 18:46:53 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\Link;
|
|
|
|
|
use Icinga\Module\Businessprocess\Web\Url;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Web\Notification;
|
|
|
|
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
|
|
|
|
|
2015-11-17 08:21:59 -05:00
|
|
|
class ProcessController extends Controller
|
2014-10-20 10:26:06 -04:00
|
|
|
{
|
2016-11-27 18:46:53 -05:00
|
|
|
protected function currentProcessParams()
|
|
|
|
|
{
|
|
|
|
|
$params = array();
|
|
|
|
|
foreach (array('config', 'node') as $name) {
|
|
|
|
|
if ($value = $this->params->get($name)) {
|
|
|
|
|
$params[$name] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Create a new business process configuration
|
|
|
|
|
*/
|
|
|
|
|
public function createAction()
|
2015-03-03 11:38:40 -05:00
|
|
|
{
|
2015-11-17 08:46:50 -05:00
|
|
|
$this->assertPermission('businessprocess/create');
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->setTitle($this->translate('Create a new business process'));
|
|
|
|
|
$this->tabsForCreate()->activate('create');
|
2015-03-03 11:38:40 -05:00
|
|
|
|
2015-11-17 09:46:55 -05:00
|
|
|
$this->view->form = $this->loadForm('bpConfig')
|
2015-03-16 04:08:00 -04:00
|
|
|
->setStorage($this->storage())
|
2015-11-17 09:46:55 -05:00
|
|
|
->setSuccessUrl('businessprocess/process/show')
|
2015-03-16 04:08:00 -04:00
|
|
|
->handleRequest();
|
2015-03-03 11:38:40 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Upload an existing business process configuration
|
|
|
|
|
*/
|
|
|
|
|
public function uploadAction()
|
|
|
|
|
{
|
|
|
|
|
$this->setTitle($this->translate('Upload a business process config file'));
|
|
|
|
|
$this->tabsForCreate()->activate('upload');
|
2016-11-27 20:13:41 -05:00
|
|
|
$this->view->form = $this->loadForm('BpUpload')
|
|
|
|
|
->setStorage($this->storage())
|
|
|
|
|
->setSuccessUrl('businessprocess/process/show')
|
|
|
|
|
->handleRequest();
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show a business process tree
|
|
|
|
|
*/
|
2014-11-30 06:04:18 -05:00
|
|
|
public function showAction()
|
2014-10-20 10:26:06 -04:00
|
|
|
{
|
2016-11-27 18:46:53 -05:00
|
|
|
$mode = $this->params->get('mode');
|
|
|
|
|
$unlocked = (bool) $this->params->get('unlocked');
|
2016-11-28 10:02:21 -05:00
|
|
|
$this->prepareProcessActions();
|
2016-11-27 18:46:53 -05:00
|
|
|
$this->prepareProcess();
|
2015-11-17 08:20:26 -05:00
|
|
|
$this->redirectOnConfigSwitch();
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2016-11-27 18:46:53 -05:00
|
|
|
if ($unlocked) {
|
2015-03-16 04:08:00 -04:00
|
|
|
$bp = $this->loadModifiedBpConfig();
|
|
|
|
|
$bp->unlock();
|
|
|
|
|
} else {
|
|
|
|
|
$bp = $this->loadBpConfig();
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do not lock empty configs
|
|
|
|
|
if ($bp->isEmpty() && ! $this->view->compact && $bp->isLocked()) {
|
|
|
|
|
$this->redirectNow($this->url()->with('unlocked', true));
|
2015-03-03 04:50:19 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
|
|
|
|
|
if ($node = $this->params->get('node')) {
|
|
|
|
|
// Render a specific node
|
2016-11-27 18:46:53 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->view->nodeName = $node;
|
2016-11-27 18:46:53 -05:00
|
|
|
$bpNode = $this->view->bp = $bp->getNode($node);
|
2014-11-30 06:04:18 -05:00
|
|
|
} else {
|
2015-03-16 04:08:00 -04:00
|
|
|
// Render a single process
|
2014-11-30 06:04:18 -05:00
|
|
|
$this->view->bp = $bp;
|
|
|
|
|
if ($bp->hasWarnings()) {
|
2015-01-28 13:50:52 -05:00
|
|
|
$this->view->warnings = $bp->getWarnings();
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2016-11-27 18:46:53 -05:00
|
|
|
$bpNode = null;
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2014-11-30 06:11:46 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$bp->retrieveStatesFromBackend();
|
2016-11-27 18:46:53 -05:00
|
|
|
if ($this->params->get('addSimulation')) {
|
|
|
|
|
$this->simulationForm();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 10:02:21 -05:00
|
|
|
|
|
|
|
|
$this->setTitle('Business Process "%s"', $bp->getTitle());
|
|
|
|
|
$this->tabsForShow()->activate('show');
|
2014-11-30 06:14:11 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
if ($bp->isLocked()) {
|
|
|
|
|
$this->tabs()->extend(new DashboardAction());
|
|
|
|
|
} else {
|
2016-11-28 10:02:21 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$simulation = new Simulation($bp, $this->session());
|
|
|
|
|
if ($this->params->get('dismissSimulations')) {
|
|
|
|
|
Notification::success(
|
|
|
|
|
sprintf(
|
|
|
|
|
$this->translate('%d applied simulation(s) have been dropped'),
|
|
|
|
|
$simulation->count()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$simulation->clear();
|
|
|
|
|
$this->redirectNow($this->url()->without('dismissSimulations')->without('unlocked'));
|
|
|
|
|
}
|
2014-11-30 06:20:39 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$bp->applySimulation($simulation);
|
2015-03-02 12:23:19 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-28 10:02:21 -05:00
|
|
|
// TODO: ...
|
|
|
|
|
$renderer = new TileRenderer($this->view, $bp, $bpNode);
|
|
|
|
|
$renderer->setBaseUrl($this->url())
|
|
|
|
|
->setPath($this->params->getValues('path'));
|
|
|
|
|
$this->view->bpRenderer = $renderer;
|
|
|
|
|
$this->view->breadcrumb = Breadcrumb::create($renderer);
|
|
|
|
|
|
|
|
|
|
if (! $bp->isLocked()) {
|
|
|
|
|
$renderer->unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 03:16:39 -04:00
|
|
|
if ($this->isXhr()) {
|
2016-11-27 18:46:53 -05:00
|
|
|
if ($this->params->get('addSimulation')) {
|
|
|
|
|
$this->setAutorefreshInterval(30);
|
|
|
|
|
} else {
|
|
|
|
|
$this->setAutorefreshInterval(10);
|
|
|
|
|
}
|
2015-10-06 03:16:39 -04:00
|
|
|
} else {
|
|
|
|
|
// This will trigger the very first XHR refresh immediately on page
|
|
|
|
|
// load. Please not that this may hammer the server in case we would
|
|
|
|
|
// decide to use autorefreshInterval for HTML meta-refreshes also.
|
|
|
|
|
$this->setAutorefreshInterval(1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 18:46:53 -05:00
|
|
|
if ($mode === 'tile') {
|
|
|
|
|
$this->setViewScript('process/bprenderer');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function prepareProcess()
|
|
|
|
|
{
|
|
|
|
|
if ($this->params->get('unlocked')) {
|
|
|
|
|
$bp = $this->loadModifiedBpConfig();
|
|
|
|
|
$bp->unlock();
|
|
|
|
|
} else {
|
|
|
|
|
$bp = $this->loadBpConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($node = $this->params->get('node')) {
|
|
|
|
|
// Render a specific node
|
|
|
|
|
$this->view->nodeName = $node;
|
|
|
|
|
$this->view->bp = $bp->getNode($node);
|
2014-11-30 06:20:39 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
2016-11-27 18:46:53 -05:00
|
|
|
protected function simulationForm()
|
|
|
|
|
{
|
|
|
|
|
$this->prepareProcess();
|
|
|
|
|
$bp = $this->loadBpConfig();
|
|
|
|
|
$nodename = $this->getParam('simulationNode');
|
|
|
|
|
$node = $bp->getNode($nodename);
|
|
|
|
|
|
|
|
|
|
$url = $this->getRequest()->getUrl()->without('addSimulation')->without('simulationNode');
|
|
|
|
|
$this->view->form = $this->loadForm('simulation')
|
|
|
|
|
->setSimulation(new Simulation($bp, $this->session()))
|
|
|
|
|
->setNode($node)
|
|
|
|
|
->setSuccessUrl($url)
|
|
|
|
|
->handleRequest();
|
|
|
|
|
|
|
|
|
|
$this->view->node = $node;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Show the source code for a process
|
|
|
|
|
*/
|
|
|
|
|
public function sourceAction()
|
|
|
|
|
{
|
2016-11-27 18:46:53 -05:00
|
|
|
$this->prepareProcess();
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->tabsForConfig()->activate('source');
|
|
|
|
|
$bp = $this->loadModifiedBpConfig();
|
|
|
|
|
|
|
|
|
|
$this->view->source = $bp->toLegacyConfigString();
|
|
|
|
|
$this->view->showDiff = (bool) $this->params->get('showDiff', false);
|
|
|
|
|
|
|
|
|
|
if ($this->view->showDiff) {
|
|
|
|
|
$this->view->diff = ConfigDiff::create(
|
|
|
|
|
$this->storage()->getSource($this->view->configName),
|
|
|
|
|
$this->view->source
|
|
|
|
|
);
|
|
|
|
|
$this->view->title = sprintf(
|
|
|
|
|
$this->translate('%s: Source Code Differences'),
|
|
|
|
|
$bp->getTitle()
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$this->view->title = sprintf(
|
|
|
|
|
$this->translate('%s: Source Code'),
|
|
|
|
|
$bp->getTitle()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Download a process configuration file
|
|
|
|
|
*/
|
|
|
|
|
public function downloadAction()
|
|
|
|
|
{
|
2016-11-27 18:46:53 -05:00
|
|
|
$this->prepareProcess();
|
2015-03-16 04:08:00 -04:00
|
|
|
$bp = $this->loadModifiedBpConfig();
|
|
|
|
|
|
|
|
|
|
header(
|
|
|
|
|
sprintf(
|
|
|
|
|
'Content-Disposition: attachment; filename="%s.conf";',
|
|
|
|
|
$bp->getName()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
header('Content-Type: text/plain');
|
|
|
|
|
|
|
|
|
|
echo $bp->toLegacyConfigString();
|
|
|
|
|
// Didn't have time to lookup how to correctly disable our renderers
|
|
|
|
|
// TODO: no exit :)
|
|
|
|
|
$this->doNotRender();
|
|
|
|
|
}
|
2014-11-30 06:20:39 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Modify a business process configuration
|
|
|
|
|
*/
|
|
|
|
|
public function configAction()
|
|
|
|
|
{
|
2016-11-27 18:46:53 -05:00
|
|
|
$this->prepareProcess();
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->tabsForConfig()->activate('config');
|
|
|
|
|
$bp = $this->loadModifiedBpConfig();
|
|
|
|
|
|
|
|
|
|
$this->setTitle(
|
|
|
|
|
$this->translate('%s: Configuration'),
|
|
|
|
|
$bp->getTitle()
|
|
|
|
|
);
|
|
|
|
|
|
2015-11-17 09:46:55 -05:00
|
|
|
$url = Url::fromPath(
|
|
|
|
|
'businessprocess/process/show?unlocked',
|
|
|
|
|
array('config' => $bp->getName())
|
2015-03-16 04:08:00 -04:00
|
|
|
);
|
|
|
|
|
|
2015-11-17 09:46:55 -05:00
|
|
|
$this->view->form = $this->loadForm('bpConfig')
|
|
|
|
|
->setProcessConfig($bp)
|
2015-03-16 04:08:00 -04:00
|
|
|
->setStorage($this->storage())
|
2015-11-17 09:46:55 -05:00
|
|
|
->setSuccessUrl($url)
|
2015-03-16 04:08:00 -04:00
|
|
|
->handleRequest();
|
2014-11-30 06:18:04 -05:00
|
|
|
}
|
2014-11-30 06:14:11 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Redirect to our URL plus the chosen config if someone switched the
|
|
|
|
|
* config in the appropriate dropdown list
|
|
|
|
|
*/
|
2015-11-17 08:20:26 -05:00
|
|
|
protected function redirectOnConfigSwitch()
|
2014-11-30 06:18:04 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
$request = $this->getRequest();
|
2016-11-27 18:49:21 -05:00
|
|
|
if ($request->isPost() && $request->getPost('action') === 'switchConfig') {
|
2015-03-16 04:08:00 -04:00
|
|
|
// We switched the process in the config dropdown list
|
|
|
|
|
$params = array(
|
|
|
|
|
'config' => $request->getPost('config')
|
|
|
|
|
);
|
|
|
|
|
$this->redirectNow($this->url()->with($params));
|
2014-11-30 06:18:04 -05:00
|
|
|
}
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
|
|
|
|
|
protected function tabsForShow()
|
|
|
|
|
{
|
|
|
|
|
return $this->tabs()->add('show', array(
|
|
|
|
|
'label' => $this->translate('Business Process'),
|
|
|
|
|
'url' => $this->url()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tabsForCreate()
|
|
|
|
|
{
|
|
|
|
|
return $this->tabs()->add('create', array(
|
|
|
|
|
'label' => $this->translate('Create'),
|
|
|
|
|
'url' => 'businessprocess/process/create'
|
|
|
|
|
))->add('upload', array(
|
|
|
|
|
'label' => $this->translate('Upload'),
|
|
|
|
|
'url' => 'businessprocess/process/upload'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tabsForConfig()
|
|
|
|
|
{
|
|
|
|
|
return $this->tabs()->add('config', array(
|
|
|
|
|
'label' => $this->translate('Process Configuration'),
|
|
|
|
|
'url' => $this->getRequest()->getUrl()->without('nix')->setPath('businessprocess/process/config')
|
|
|
|
|
))->add('source', array(
|
|
|
|
|
'label' => $this->translate('Source'),
|
|
|
|
|
'url' => $this->getRequest()->getUrl()->without('nix')->setPath('businessprocess/process/source')
|
|
|
|
|
));
|
|
|
|
|
}
|
2015-01-28 13:50:52 -05:00
|
|
|
}
|