2014-10-20 10:26:06 -04:00
|
|
|
<?php
|
|
|
|
|
|
2015-11-17 08:21:59 -05:00
|
|
|
namespace Icinga\Module\Businessprocess\Controllers;
|
|
|
|
|
|
2018-07-31 07:34:25 -04:00
|
|
|
use Icinga\Date\DateFormatter;
|
2017-01-11 08:04:45 -05:00
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
2018-07-31 07:34:25 -04:00
|
|
|
use Icinga\Module\Businessprocess\BpNode;
|
2016-11-29 10:58:03 -05:00
|
|
|
use Icinga\Module\Businessprocess\Node;
|
2016-11-28 10:02:21 -05:00
|
|
|
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
|
2016-11-29 10:58:03 -05:00
|
|
|
use Icinga\Module\Businessprocess\Renderer\Renderer;
|
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;
|
2018-07-31 07:34:25 -04:00
|
|
|
use Icinga\Module\Businessprocess\State\MonitoringState;
|
|
|
|
|
use Icinga\Module\Businessprocess\Storage\ConfigDiff;
|
2017-01-11 07:39:36 -05:00
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyConfigRenderer;
|
2016-12-09 07:57:07 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Component\ActionBar;
|
2017-01-03 05:12:20 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Component\RenderedProcessActionBar;
|
2016-12-16 13:44:48 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Component\Tabs;
|
2016-12-09 03:53:36 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Controller;
|
2018-07-31 07:34:25 -04:00
|
|
|
use Icinga\Util\Json;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Web\Notification;
|
2019-01-17 07:21:46 -05:00
|
|
|
use Icinga\Web\Url;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
2018-07-31 07:34:25 -04:00
|
|
|
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
2019-01-17 07:21:46 -05:00
|
|
|
use ipl\Html\Html;
|
|
|
|
|
use ipl\Html\HtmlString;
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2015-11-17 08:21:59 -05:00
|
|
|
class ProcessController extends Controller
|
2014-10-20 10:26:06 -04:00
|
|
|
{
|
2016-11-29 10:58:03 -05:00
|
|
|
/** @var Renderer */
|
|
|
|
|
protected $renderer;
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
2017-01-25 03:11:25 -05:00
|
|
|
* Create a new Business Process Configuration
|
2015-03-16 04:08:00 -04:00
|
|
|
*/
|
|
|
|
|
public function createAction()
|
2015-03-03 11:38:40 -05:00
|
|
|
{
|
2015-11-17 08:46:50 -05:00
|
|
|
$this->assertPermission('businessprocess/create');
|
|
|
|
|
|
2017-01-25 03:11:25 -05:00
|
|
|
$title = $this->translate('Create a new Business Process');
|
2016-12-16 13:44:48 -05:00
|
|
|
$this->setTitle($title);
|
|
|
|
|
$this->controls()
|
|
|
|
|
->add($this->tabsForCreate()->activate('create'))
|
2019-01-17 07:21:46 -05:00
|
|
|
->add(Html::tag('h1', null, $title));
|
2015-03-03 11:38:40 -05:00
|
|
|
|
2016-12-16 13:44:48 -05:00
|
|
|
$this->content()->add(
|
|
|
|
|
$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')
|
2016-12-16 13:44:48 -05:00
|
|
|
->handleRequest()
|
|
|
|
|
);
|
2015-03-03 11:38:40 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
2017-01-25 03:11:25 -05:00
|
|
|
* Upload an existing Business Process Configuration
|
2015-03-16 04:08:00 -04:00
|
|
|
*/
|
|
|
|
|
public function uploadAction()
|
|
|
|
|
{
|
2017-02-08 11:39:22 -05:00
|
|
|
$this->assertPermission('businessprocess/create');
|
|
|
|
|
|
2017-01-25 03:11:25 -05:00
|
|
|
$title = $this->translate('Upload a Business Process Config file');
|
2016-12-16 13:44:48 -05:00
|
|
|
$this->setTitle($title);
|
|
|
|
|
$this->controls()
|
|
|
|
|
->add($this->tabsForCreate()->activate('upload'))
|
2019-01-17 07:21:46 -05:00
|
|
|
->add(Html::tag('h1', null, $title));
|
2016-12-16 13:44:48 -05:00
|
|
|
|
|
|
|
|
$this->content()->add(
|
|
|
|
|
$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-12-09 08:36:09 -05:00
|
|
|
$bp = $this->loadModifiedBpConfig();
|
2016-11-29 10:58:03 -05:00
|
|
|
$node = $this->getNode($bp);
|
2017-01-12 03:18:44 -05:00
|
|
|
|
2017-01-11 03:51:39 -05:00
|
|
|
MonitoringState::apply($bp);
|
2016-11-29 10:58:03 -05:00
|
|
|
$this->handleSimulations($bp);
|
2014-11-30 06:14:11 -05:00
|
|
|
|
2016-12-17 13:15:50 -05:00
|
|
|
$this->setTitle($this->translate('Business Process "%s"'), $bp->getTitle());
|
2015-03-02 12:23:19 -05:00
|
|
|
|
2016-11-29 10:58:03 -05:00
|
|
|
$renderer = $this->prepareRenderer($bp, $node);
|
2016-12-09 08:23:28 -05:00
|
|
|
|
|
|
|
|
if ($this->params->get('unlocked')) {
|
|
|
|
|
$renderer->unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($bp->isEmpty() && $renderer->isLocked()) {
|
|
|
|
|
$this->redirectNow($this->url()->with('unlocked', true));
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 07:34:25 -04:00
|
|
|
$this->handleFormatRequest($bp, $node);
|
|
|
|
|
|
2016-11-29 10:58:03 -05:00
|
|
|
$this->prepareControls($bp, $renderer);
|
2018-07-31 07:34:25 -04:00
|
|
|
|
|
|
|
|
$this->tabs()->extend(new OutputFormat());
|
|
|
|
|
|
2017-02-20 08:41:15 -05:00
|
|
|
$missing = $bp->getMissingChildren();
|
|
|
|
|
if (! empty($missing)) {
|
2017-05-31 06:22:41 -04:00
|
|
|
if (($count = count($missing)) > 10) {
|
|
|
|
|
$missing = array_slice($missing, 0, 10);
|
|
|
|
|
$missing[] = '...';
|
|
|
|
|
}
|
|
|
|
|
$bp->addError(sprintf('There are %d missing nodes: %s', $count, implode(', ', $missing)));
|
2017-02-20 08:41:15 -05:00
|
|
|
}
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->content()->add($this->showHints($bp));
|
|
|
|
|
$this->content()->add($this->showWarnings($bp));
|
|
|
|
|
$this->content()->add($this->showErrors($bp));
|
2016-11-28 16:15:20 -05:00
|
|
|
$this->content()->add($renderer);
|
2016-11-29 10:58:03 -05:00
|
|
|
$this->loadActionForm($bp, $node);
|
|
|
|
|
$this->setDynamicAutorefresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function prepareControls($bp, $renderer)
|
|
|
|
|
{
|
2016-11-28 16:15:20 -05:00
|
|
|
$controls = $this->controls();
|
2019-01-22 06:57:29 -05:00
|
|
|
$controls->getAttributes()->add('class', 'separated');
|
2016-11-28 16:15:20 -05:00
|
|
|
|
|
|
|
|
if ($this->showFullscreen) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$controls->getAttributes()->add('class', 'want-fullscreen');
|
|
|
|
|
$controls->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => $this->url()->without('showFullscreen')->without('view'),
|
|
|
|
|
'title' => $this->translate('Leave full screen and switch back to normal mode'),
|
|
|
|
|
'style' => 'float: right'
|
|
|
|
|
],
|
|
|
|
|
Html::tag('i', ['class' => 'icon icon-resize-small'])
|
|
|
|
|
));
|
2016-11-28 16:15:20 -05:00
|
|
|
}
|
2016-11-29 10:58:03 -05:00
|
|
|
|
2016-12-09 10:59:25 -05:00
|
|
|
if (! ($this->showFullscreen || $this->view->compact)) {
|
|
|
|
|
$controls->add($this->getProcessTabs($bp, $renderer));
|
|
|
|
|
}
|
2016-11-28 16:15:20 -05:00
|
|
|
$controls->add(Breadcrumb::create($renderer));
|
2016-11-29 03:16:17 -05:00
|
|
|
if (! $this->showFullscreen && ! $this->view->compact) {
|
2017-01-03 05:12:20 -05:00
|
|
|
$controls->add(
|
|
|
|
|
new RenderedProcessActionBar($bp, $renderer, $this->Auth(), $this->url())
|
|
|
|
|
);
|
2016-11-28 16:15:20 -05:00
|
|
|
}
|
2016-11-29 10:58:03 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
protected function getNode(BpConfig $bp)
|
2016-11-29 10:58:03 -05:00
|
|
|
{
|
|
|
|
|
if ($nodeName = $this->params->get('node')) {
|
|
|
|
|
return $bp->getNode($nodeName);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function prepareRenderer($bp, $node)
|
|
|
|
|
{
|
|
|
|
|
if ($this->renderer === null) {
|
2016-12-09 08:37:24 -05:00
|
|
|
if ($this->params->get('mode') === 'tree') {
|
2016-11-29 10:58:03 -05:00
|
|
|
$renderer = new TreeRenderer($bp, $node);
|
2016-12-09 08:37:24 -05:00
|
|
|
} else {
|
|
|
|
|
$renderer = new TileRenderer($bp, $node);
|
2016-11-29 10:58:03 -05:00
|
|
|
}
|
|
|
|
|
$renderer->setUrl($this->url())
|
|
|
|
|
->setPath($this->params->getValues('path'));
|
|
|
|
|
|
|
|
|
|
$this->renderer = $renderer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->renderer;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
protected function getProcessTabs(BpConfig $bp, Renderer $renderer)
|
2016-11-29 10:58:03 -05:00
|
|
|
{
|
2016-12-09 10:10:32 -05:00
|
|
|
$tabs = $this->singleTab($bp->getTitle());
|
2016-12-17 13:18:58 -05:00
|
|
|
if ($renderer->isLocked()) {
|
2016-11-29 10:58:03 -05:00
|
|
|
$tabs->extend(new DashboardAction());
|
|
|
|
|
}
|
2016-12-09 10:10:32 -05:00
|
|
|
|
|
|
|
|
return $tabs;
|
2016-11-29 10:58:03 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
protected function handleSimulations(BpConfig $bp)
|
2016-11-29 10:58:03 -05:00
|
|
|
{
|
2017-01-26 15:37:09 -05:00
|
|
|
$simulation = Simulation::fromSession($this->session());
|
2016-11-29 10:58:03 -05:00
|
|
|
|
|
|
|
|
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'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bp->applySimulation($simulation);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
protected function loadActionForm(BpConfig $bp, Node $node = null)
|
2016-11-29 10:58:03 -05:00
|
|
|
{
|
|
|
|
|
$action = $this->params->get('action');
|
|
|
|
|
$form = null;
|
2016-12-09 10:59:25 -05:00
|
|
|
if ($this->showFullscreen) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-12-09 03:53:36 -05:00
|
|
|
|
2017-02-08 11:56:38 -05:00
|
|
|
$canEdit = $bp->getMetadata()->canModify();
|
|
|
|
|
|
|
|
|
|
if ($action === 'add' && $canEdit) {
|
2016-12-17 13:15:50 -05:00
|
|
|
$form = $this->loadForm('AddNode')
|
2018-07-31 06:49:13 -04:00
|
|
|
->setSuccessUrl(Url::fromRequest()->without('action'))
|
2019-01-16 04:25:11 -05:00
|
|
|
->setStorage($this->storage())
|
2016-11-29 10:58:03 -05:00
|
|
|
->setProcess($bp)
|
|
|
|
|
->setParentNode($node)
|
|
|
|
|
->setSession($this->session())
|
|
|
|
|
->handleRequest();
|
2018-06-28 03:01:26 -04:00
|
|
|
} elseif ($action === 'editmonitored' && $canEdit) {
|
|
|
|
|
$form = $this->loadForm('EditNode')
|
2018-07-31 06:49:13 -04:00
|
|
|
->setSuccessUrl(Url::fromRequest()->without('action'))
|
2018-06-28 03:01:26 -04:00
|
|
|
->setProcess($bp)
|
|
|
|
|
->setNode($bp->getNode($this->params->get('editmonitorednode')))
|
|
|
|
|
->setParentNode($node)
|
|
|
|
|
->setSession($this->session())
|
|
|
|
|
->handleRequest();
|
2017-02-08 11:56:38 -05:00
|
|
|
} elseif ($action === 'delete' && $canEdit) {
|
2018-06-28 03:01:26 -04:00
|
|
|
$form = $this->loadForm('DeleteNode')
|
2018-07-31 06:49:13 -04:00
|
|
|
->setSuccessUrl(Url::fromRequest()->without('action'))
|
2018-06-28 03:01:26 -04:00
|
|
|
->setProcess($bp)
|
|
|
|
|
->setNode($bp->getNode($this->params->get('deletenode')))
|
|
|
|
|
->setParentNode($node)
|
|
|
|
|
->setSession($this->session())
|
|
|
|
|
->handleRequest();
|
2017-02-08 11:56:38 -05:00
|
|
|
} elseif ($action === 'edit' && $canEdit) {
|
2018-06-28 03:01:26 -04:00
|
|
|
$form = $this->loadForm('Process')
|
2018-07-31 06:49:13 -04:00
|
|
|
->setSuccessUrl(Url::fromRequest()->without('action'))
|
2017-01-03 05:38:17 -05:00
|
|
|
->setProcess($bp)
|
|
|
|
|
->setNode($bp->getNode($this->params->get('editnode')))
|
|
|
|
|
->setSession($this->session())
|
|
|
|
|
->handleRequest();
|
2016-11-29 09:32:56 -05:00
|
|
|
} elseif ($action === 'simulation') {
|
2016-11-29 10:58:03 -05:00
|
|
|
$form = $this->loadForm('simulation')
|
2018-07-31 06:49:13 -04:00
|
|
|
->setSuccessUrl(Url::fromRequest()->without('action'))
|
2016-11-30 08:37:07 -05:00
|
|
|
->setNode($bp->getNode($this->params->get('simulationnode')))
|
2017-01-26 15:37:09 -05:00
|
|
|
->setSimulation(Simulation::fromSession($this->session()))
|
2016-11-29 10:58:03 -05:00
|
|
|
->handleRequest();
|
2018-12-17 08:49:26 -05:00
|
|
|
} elseif ($action === 'move') {
|
2019-01-10 09:44:50 -05:00
|
|
|
$url = Url::fromPath('businessprocess/process/show', ['config' => $bp->getName()]);
|
|
|
|
|
if ($this->url()->hasParam('unlocked')) {
|
|
|
|
|
$url->setParam('unlocked', $this->url()->getParam('unlocked'));
|
|
|
|
|
}
|
|
|
|
|
if ($this->url()->hasParam('mode')) {
|
|
|
|
|
$url->setParam('mode', $this->url()->getParam('mode'));
|
|
|
|
|
} elseif ($this->url()->hasParam('node')) {
|
|
|
|
|
$url->setParam('node', $this->url()->getParam('node'));
|
2018-12-20 04:56:05 -05:00
|
|
|
}
|
|
|
|
|
|
2018-12-17 08:49:26 -05:00
|
|
|
$form = $this->loadForm('MoveNode')
|
|
|
|
|
->setProcess($bp)
|
|
|
|
|
->setParentNode($node)
|
|
|
|
|
->setSession($this->session())
|
|
|
|
|
->setNode($bp->getNode($this->params->get('movenode')))
|
2018-12-20 04:56:05 -05:00
|
|
|
->setSuccessUrl($url)
|
2018-12-17 08:49:26 -05:00
|
|
|
->handleRequest();
|
2016-11-29 10:58:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($form) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->content()->prepend(HtmlString::create((string) $form));
|
2016-11-29 09:32:56 -05:00
|
|
|
}
|
2016-11-29 10:58:03 -05:00
|
|
|
}
|
2016-11-29 09:32:56 -05:00
|
|
|
|
2016-11-29 10:58:03 -05:00
|
|
|
protected function setDynamicAutorefresh()
|
|
|
|
|
{
|
2016-11-30 08:37:07 -05:00
|
|
|
if (! $this->isXhr()) {
|
|
|
|
|
// 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-29 09:32:56 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 08:37:07 -05:00
|
|
|
if ($this->params->get('action')) {
|
|
|
|
|
$this->setAutorefreshInterval(45);
|
|
|
|
|
} else {
|
|
|
|
|
$this->setAutorefreshInterval(10);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
protected function showWarnings(BpConfig $bp)
|
2016-11-30 08:37:07 -05:00
|
|
|
{
|
|
|
|
|
if ($bp->hasWarnings()) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$ul = Html::tag('ul', array('class' => 'warning'));
|
2016-11-30 08:37:07 -05:00
|
|
|
foreach ($bp->getWarnings() as $warning) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$ul->add(Html::tag('li')->setContent($warning));
|
2016-11-27 18:46:53 -05:00
|
|
|
}
|
2016-11-30 08:37:07 -05:00
|
|
|
|
|
|
|
|
return $ul;
|
2015-10-06 03:16:39 -04:00
|
|
|
} else {
|
2016-11-30 08:37:07 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 08:41:15 -05:00
|
|
|
protected function showErrors(BpConfig $bp)
|
|
|
|
|
{
|
|
|
|
|
if ($bp->hasWarnings()) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$ul = Html::tag('ul', array('class' => 'error'));
|
2017-02-20 08:41:15 -05:00
|
|
|
foreach ($bp->getErrors() as $msg) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$ul->add(Html::tag('li')->setContent($msg));
|
2017-02-20 08:41:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ul;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
protected function showHints(BpConfig $bp)
|
2016-11-30 08:37:07 -05:00
|
|
|
{
|
2019-01-17 07:21:46 -05:00
|
|
|
$ul = Html::tag('ul', ['class' => 'error']);
|
2016-11-30 08:37:07 -05:00
|
|
|
foreach ($bp->getErrors() as $error) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$ul->add(Html::tag('li')->setContent($error));
|
2016-11-30 08:37:07 -05:00
|
|
|
}
|
|
|
|
|
if ($bp->hasChanges()) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$li = Html::tag('li')->setSeparator(' ');
|
|
|
|
|
$li->add(sprintf(
|
2016-11-30 08:37:07 -05:00
|
|
|
$this->translate('This process has %d pending change(s).'),
|
|
|
|
|
$bp->countChanges()
|
2019-01-17 07:21:46 -05:00
|
|
|
))->add(Html::tag(
|
|
|
|
|
'a',
|
2019-01-08 07:50:51 -05:00
|
|
|
[
|
2019-02-14 08:26:20 -05:00
|
|
|
'href' => Url::fromPath('businessprocess/process/config')
|
|
|
|
|
->setParams($this->getRequest()->getUrl()->getParams())
|
2019-01-08 07:50:51 -05:00
|
|
|
],
|
2019-01-17 07:21:46 -05:00
|
|
|
$this->translate('Store')
|
|
|
|
|
))->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
['href' => $this->url()->with('dismissChanges', true)],
|
|
|
|
|
$this->translate('Dismiss')
|
|
|
|
|
));
|
|
|
|
|
$ul->add($li);
|
2016-11-30 08:37:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($bp->hasSimulations()) {
|
2019-01-17 07:21:46 -05:00
|
|
|
$li = Html::tag('li')->setSeparator(' ');
|
|
|
|
|
$li->add(sprintf(
|
2016-11-30 08:37:07 -05:00
|
|
|
$this->translate('This process shows %d simulated state(s).'),
|
|
|
|
|
$bp->countSimulations()
|
2019-01-17 07:21:46 -05:00
|
|
|
))->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
['href' => $this->url()->with('dismissSimulations', true)],
|
|
|
|
|
$this->translate('Dismiss')
|
2016-11-30 08:37:07 -05:00
|
|
|
));
|
2019-01-17 07:21:46 -05:00
|
|
|
$ul->add($li);
|
2016-11-30 08:37:07 -05:00
|
|
|
}
|
|
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
if (! $ul->isEmpty()) {
|
2016-11-30 08:37:07 -05:00
|
|
|
return $ul;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
2015-10-06 03:16:39 -04:00
|
|
|
}
|
2016-11-27 18:46:53 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
/**
|
|
|
|
|
* Show the source code for a process
|
|
|
|
|
*/
|
|
|
|
|
public function sourceAction()
|
|
|
|
|
{
|
2017-02-08 11:39:22 -05:00
|
|
|
$this->assertPermission('businessprocess/modify');
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$bp = $this->loadModifiedBpConfig();
|
2017-01-03 05:32:02 -05:00
|
|
|
$this->view->showDiff = $showDiff = (bool) $this->params->get('showDiff', false);
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2017-01-11 07:39:36 -05:00
|
|
|
$this->view->source = LegacyConfigRenderer::renderConfig($bp);
|
2015-03-16 04:08:00 -04:00
|
|
|
if ($this->view->showDiff) {
|
|
|
|
|
$this->view->diff = ConfigDiff::create(
|
|
|
|
|
$this->storage()->getSource($this->view->configName),
|
|
|
|
|
$this->view->source
|
|
|
|
|
);
|
2017-01-03 05:32:02 -05:00
|
|
|
$title = sprintf(
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->translate('%s: Source Code Differences'),
|
|
|
|
|
$bp->getTitle()
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2017-01-03 05:32:02 -05:00
|
|
|
$title = sprintf(
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->translate('%s: Source Code'),
|
|
|
|
|
$bp->getTitle()
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-01-03 05:32:02 -05:00
|
|
|
|
|
|
|
|
$this->setTitle($title);
|
|
|
|
|
$this->controls()
|
2017-01-12 03:18:44 -05:00
|
|
|
->add($this->tabsForConfig($bp)->activate('source'))
|
2019-01-17 07:21:46 -05:00
|
|
|
->add(Html::tag('h1', null, $title))
|
2017-01-12 03:18:44 -05:00
|
|
|
->add($this->createConfigActionBar($bp, $showDiff));
|
2017-01-08 17:09:01 -05:00
|
|
|
|
|
|
|
|
$this->setViewScript('process/source');
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Download a process configuration file
|
|
|
|
|
*/
|
|
|
|
|
public function downloadAction()
|
|
|
|
|
{
|
2017-02-08 11:39:22 -05:00
|
|
|
$this->assertPermission('businessprocess/modify');
|
|
|
|
|
|
2017-01-12 03:18:44 -05:00
|
|
|
$config = $this->loadModifiedBpConfig();
|
2017-01-03 05:43:22 -05:00
|
|
|
$response = $this->getResponse();
|
|
|
|
|
$response->setHeader(
|
|
|
|
|
'Content-Disposition',
|
2015-03-16 04:08:00 -04:00
|
|
|
sprintf(
|
2017-01-03 05:43:22 -05:00
|
|
|
'attachment; filename="%s.conf";',
|
2017-01-12 03:18:44 -05:00
|
|
|
$config->getName()
|
2015-03-16 04:08:00 -04:00
|
|
|
)
|
|
|
|
|
);
|
2017-01-03 05:43:22 -05:00
|
|
|
$response->setHeader('Content-Type', 'text/plain');
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2017-01-12 03:18:44 -05:00
|
|
|
echo LegacyConfigRenderer::renderConfig($config);
|
2015-03-16 04:08:00 -04:00
|
|
|
$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()
|
|
|
|
|
{
|
2017-02-08 11:39:22 -05:00
|
|
|
$this->assertPermission('businessprocess/modify');
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$bp = $this->loadModifiedBpConfig();
|
|
|
|
|
|
2017-01-03 05:32:02 -05:00
|
|
|
$title = sprintf(
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->translate('%s: Configuration'),
|
|
|
|
|
$bp->getTitle()
|
|
|
|
|
);
|
2017-01-03 05:32:02 -05:00
|
|
|
$this->setTitle($title);
|
|
|
|
|
$this->controls()
|
2017-01-12 03:18:44 -05:00
|
|
|
->add($this->tabsForConfig($bp)->activate('config'))
|
2019-01-17 07:21:46 -05:00
|
|
|
->add(Html::tag('h1', null, $title))
|
2017-01-12 03:18:44 -05:00
|
|
|
->add($this->createConfigActionBar($bp));
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2019-02-14 08:26:20 -05:00
|
|
|
$url = Url::fromPath('businessprocess/process/show')
|
|
|
|
|
->setParams($this->getRequest()->getUrl()->getParams());
|
2017-01-03 05:32:02 -05:00
|
|
|
$this->content()->add(
|
|
|
|
|
$this->loadForm('bpConfig')
|
|
|
|
|
->setProcessConfig($bp)
|
|
|
|
|
->setStorage($this->storage())
|
|
|
|
|
->setSuccessUrl($url)
|
|
|
|
|
->handleRequest()
|
|
|
|
|
);
|
2014-11-30 06:18:04 -05:00
|
|
|
}
|
2014-11-30 06:14:11 -05:00
|
|
|
|
2017-01-12 03:18:44 -05:00
|
|
|
protected function createConfigActionBar(BpConfig $config, $showDiff = false)
|
2014-11-30 06:18:04 -05:00
|
|
|
{
|
2017-01-12 03:18:44 -05:00
|
|
|
$actionBar = new ActionBar();
|
|
|
|
|
|
|
|
|
|
if ($showDiff) {
|
|
|
|
|
$params = array('config' => $config->getName());
|
2019-01-17 07:21:46 -05:00
|
|
|
$actionBar->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => Url::fromPath('businessprocess/process/source', $params),
|
|
|
|
|
'class' => 'icon-doc-text',
|
|
|
|
|
'title' => $this->translate('Show source code')
|
|
|
|
|
],
|
|
|
|
|
$this->translate('Source')
|
|
|
|
|
));
|
2017-01-12 03:18:44 -05:00
|
|
|
} else {
|
2015-03-16 04:08:00 -04:00
|
|
|
$params = array(
|
2017-01-12 03:18:44 -05:00
|
|
|
'config' => $config->getName(),
|
|
|
|
|
'showDiff' => true
|
|
|
|
|
);
|
|
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
$actionBar->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => Url::fromPath('businessprocess/process/source', $params),
|
|
|
|
|
'class' => 'icon-flapping',
|
|
|
|
|
'title' => $this->translate('Highlight changes')
|
|
|
|
|
],
|
|
|
|
|
$this->translate('Diff')
|
|
|
|
|
));
|
2014-11-30 06:18:04 -05:00
|
|
|
}
|
2017-01-12 03:18:44 -05:00
|
|
|
|
2019-01-17 07:21:46 -05:00
|
|
|
$actionBar->add(Html::tag(
|
|
|
|
|
'a',
|
|
|
|
|
[
|
|
|
|
|
'href' => Url::fromPath('businessprocess/process/download', ['config' => $config->getName()]),
|
|
|
|
|
'class' => 'icon-download',
|
|
|
|
|
'target' => '_blank',
|
|
|
|
|
'title' => $this->translate('Download process configuration')
|
|
|
|
|
],
|
|
|
|
|
$this->translate('Download')
|
|
|
|
|
));
|
2017-01-12 03:18:44 -05:00
|
|
|
|
|
|
|
|
return $actionBar;
|
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()
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 10:10:32 -05:00
|
|
|
/**
|
|
|
|
|
* @return Tabs
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
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'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 03:18:44 -05:00
|
|
|
protected function tabsForConfig(BpConfig $config)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
2017-01-12 03:18:44 -05:00
|
|
|
$params = array(
|
|
|
|
|
'config' => $config->getName()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$tabs = $this->tabs()->add('config', array(
|
2015-03-16 04:08:00 -04:00
|
|
|
'label' => $this->translate('Process Configuration'),
|
2017-01-12 03:18:44 -05:00
|
|
|
'url' =>Url::fromPath('businessprocess/process/config', $params)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
if ($this->params->get('showDiff')) {
|
|
|
|
|
$params['showDiff'] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tabs->add('source', array(
|
2015-03-16 04:08:00 -04:00
|
|
|
'label' => $this->translate('Source'),
|
2017-01-12 03:18:44 -05:00
|
|
|
'url' =>Url::fromPath('businessprocess/process/source', $params)
|
2015-03-16 04:08:00 -04:00
|
|
|
));
|
2017-01-12 03:18:44 -05:00
|
|
|
|
|
|
|
|
return $tabs;
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
2018-07-31 07:34:25 -04:00
|
|
|
|
|
|
|
|
protected function handleFormatRequest(BpConfig $bp, BpNode $node = null)
|
|
|
|
|
{
|
|
|
|
|
$desiredContentType = $this->getRequest()->getHeader('Accept');
|
|
|
|
|
if ($desiredContentType === 'application/json') {
|
|
|
|
|
$desiredFormat = 'json';
|
|
|
|
|
} elseif ($desiredContentType === 'text/csv') {
|
|
|
|
|
$desiredFormat = 'csv';
|
|
|
|
|
} else {
|
|
|
|
|
$desiredFormat = strtolower($this->params->get('format', 'html'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($desiredFormat) {
|
|
|
|
|
case 'json':
|
|
|
|
|
$response = $this->getResponse();
|
|
|
|
|
$response
|
|
|
|
|
->setHeader('Content-Type', 'application/json')
|
|
|
|
|
->setHeader('Cache-Control', 'no-store')
|
|
|
|
|
->setHeader(
|
|
|
|
|
'Content-Disposition',
|
|
|
|
|
'inline; filename=' . $this->getRequest()->getActionName() . '.json'
|
|
|
|
|
)
|
|
|
|
|
->appendBody(Json::sanitize($node !== null ? $node->toArray() : $bp->toArray()))
|
|
|
|
|
->sendResponse();
|
|
|
|
|
exit;
|
|
|
|
|
case 'csv':
|
|
|
|
|
$csv = fopen('php://temp', 'w');
|
|
|
|
|
|
|
|
|
|
fputcsv($csv, ['Path', 'Name', 'State', 'Since']);
|
|
|
|
|
|
|
|
|
|
foreach ($node !== null ? $node->toArray(null, true) : $bp->toArray(true) as $node) {
|
|
|
|
|
$data = [$node['path'], $node['name']];
|
|
|
|
|
|
|
|
|
|
if (isset($node['state'])) {
|
|
|
|
|
$data[] = $node['state'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($node['since'])) {
|
|
|
|
|
$data[] = DateFormatter::formatDateTime($node['since']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputcsv($csv, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = $this->getResponse();
|
|
|
|
|
$response
|
|
|
|
|
->setHeader('Content-Type', 'text/csv')
|
|
|
|
|
->setHeader('Cache-Control', 'no-store')
|
|
|
|
|
->setHeader(
|
|
|
|
|
'Content-Disposition',
|
|
|
|
|
'attachment; filename=' . $this->getRequest()->getActionName() . '.csv'
|
|
|
|
|
)
|
|
|
|
|
->sendHeaders();
|
|
|
|
|
|
|
|
|
|
rewind($csv);
|
|
|
|
|
|
|
|
|
|
fpassthru($csv);
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-28 13:50:52 -05:00
|
|
|
}
|