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 16:15:20 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\Element;
|
|
|
|
|
use Icinga\Module\Businessprocess\Html\HtmlString;
|
|
|
|
|
use Icinga\Module\Businessprocess\Html\Icon;
|
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;
|
2016-11-28 16:15:20 -05:00
|
|
|
use Icinga\Module\Businessprocess\Renderer\TreeRenderer;
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-11-28 16:15:20 -05:00
|
|
|
* Show a business process
|
2015-03-16 04:08:00 -04:00
|
|
|
*/
|
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 16:15:20 -05:00
|
|
|
$title = sprintf('Business Process "%s"', $bp->getTitle());
|
|
|
|
|
$this->setTitle($title);
|
2016-11-28 10:02:21 -05:00
|
|
|
$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 16:15:20 -05:00
|
|
|
if ($mode === 'tile') {
|
|
|
|
|
$renderer = new TileRenderer($bp, $bpNode);
|
|
|
|
|
} else {
|
|
|
|
|
$renderer = new TreeRenderer($bp, $bpNode);
|
|
|
|
|
}
|
2016-11-28 10:02:21 -05:00
|
|
|
$renderer->setBaseUrl($this->url())
|
|
|
|
|
->setPath($this->params->getValues('path'));
|
2016-11-28 16:15:20 -05:00
|
|
|
$this->content()->add($renderer);
|
|
|
|
|
$controls = $this->controls();
|
|
|
|
|
|
|
|
|
|
if ($this->showFullscreen) {
|
|
|
|
|
$controls->attributes()->add('class', 'want-fullscreen');
|
|
|
|
|
$controls->add(
|
|
|
|
|
Link::create(
|
|
|
|
|
Icon::create('resize-small'),
|
|
|
|
|
$this->url()->without('showFullscreen')->without('view'),
|
|
|
|
|
null,
|
|
|
|
|
array('style' => 'float: right')
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$controls->add(HtmlString::create($this->getTabs()));
|
|
|
|
|
}
|
|
|
|
|
$controls->add(Element::create('h1')->setContent($title));
|
|
|
|
|
$controls->add(Breadcrumb::create($renderer));
|
|
|
|
|
if (! $this->showFullscreen) {
|
|
|
|
|
$controls->add($this->actions());
|
|
|
|
|
}
|
2016-11-28 10:02:21 -05:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-28 11:28:58 -05:00
|
|
|
protected function prepareProcessActions()
|
|
|
|
|
{
|
|
|
|
|
$mode = $this->params->get('mode');
|
|
|
|
|
$unlocked = (bool) $this->params->get('unlocked');
|
|
|
|
|
|
|
|
|
|
if ($mode === 'tile') {
|
|
|
|
|
$this->actions()->add(
|
|
|
|
|
Link::create(
|
|
|
|
|
$this->translate('Tree'),
|
|
|
|
|
'businessprocess/process/show',
|
|
|
|
|
$this->currentProcessParams(),
|
|
|
|
|
array('class' => 'icon-sitemap')
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$this->actions()->add(
|
|
|
|
|
Link::create(
|
|
|
|
|
$this->translate('Tiles'),
|
|
|
|
|
$this->url()->with('mode', 'tile'),
|
|
|
|
|
null,
|
|
|
|
|
array('class' => 'icon-dashboard')
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($unlocked) {
|
|
|
|
|
$this->actions()->add(
|
|
|
|
|
Link::create(
|
|
|
|
|
$this->translate('Lock'),
|
|
|
|
|
$this->url()->without('unlocked'),
|
|
|
|
|
null,
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'icon-lock',
|
|
|
|
|
'title' => $this->translate('Lock this process'),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$this->actions()->add(
|
|
|
|
|
Link::create(
|
|
|
|
|
$this->translate('Unlock'),
|
|
|
|
|
$this->url()->with('unlocked', true),
|
|
|
|
|
null,
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'icon-lock-open',
|
|
|
|
|
'title' => $this->translate('Unlock this process'),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->actions()->add(
|
|
|
|
|
Link::create(
|
|
|
|
|
$this->translate('Store'),
|
|
|
|
|
'businessprocess/process/config',
|
|
|
|
|
$this->currentProcessParams(),
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'icon-wrench',
|
|
|
|
|
'title' => $this->translate('Modify this process'),
|
|
|
|
|
'data-base-target' => '_next',
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-11-28 18:50:20 -05:00
|
|
|
|
|
|
|
|
$this->actions()->add(
|
|
|
|
|
Link::create(
|
|
|
|
|
$this->translate('Fullscreen'),
|
|
|
|
|
$this->url()->with('showFullscreen', true),
|
|
|
|
|
null,
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'icon-resize-full-alt',
|
|
|
|
|
'title' => $this->translate('Switch to fullscreen mode'),
|
|
|
|
|
'data-base-target' => '_main',
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-11-28 11:28:58 -05: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
|
|
|
}
|