2014-11-30 05:54:46 -05:00
|
|
|
<?php
|
|
|
|
|
|
2016-12-09 07:57:07 -05:00
|
|
|
namespace Icinga\Module\Businessprocess\Web;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
2015-01-21 03:22:25 -05:00
|
|
|
use Icinga\Application\Icinga;
|
2016-12-09 07:57:07 -05:00
|
|
|
use Icinga\Module\Businessprocess\BusinessProcess;
|
2017-01-10 10:49:53 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\HtmlTag;
|
2016-11-23 06:27:55 -05:00
|
|
|
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
2016-11-26 15:18:18 -05:00
|
|
|
use Icinga\Module\Businessprocess\Storage\Storage;
|
2016-11-22 09:28:37 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Component\ActionBar;
|
2016-11-28 16:15:20 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Component\Controls;
|
|
|
|
|
use Icinga\Module\Businessprocess\Web\Component\Content;
|
2016-12-09 10:10:32 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Component\Tabs;
|
2016-11-23 06:27:55 -05:00
|
|
|
use Icinga\Module\Businessprocess\Web\Form\FormLoader;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Web\Controller as ModuleController;
|
|
|
|
|
use Icinga\Web\Notification;
|
2016-11-26 15:18:18 -05:00
|
|
|
use Icinga\Web\View;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
class Controller extends ModuleController
|
2014-11-30 05:54:46 -05:00
|
|
|
{
|
2016-12-09 03:53:36 -05:00
|
|
|
/** @var View */
|
|
|
|
|
public $view;
|
|
|
|
|
|
2016-11-26 15:18:18 -05:00
|
|
|
/** @var BusinessProcess */
|
2015-11-17 09:47:29 -05:00
|
|
|
protected $bp;
|
|
|
|
|
|
2016-12-09 03:53:36 -05:00
|
|
|
/** @var Tabs */
|
2016-12-09 10:10:32 -05:00
|
|
|
protected $mytabs;
|
2016-11-26 15:18:18 -05:00
|
|
|
|
|
|
|
|
/** @var Storage */
|
2015-03-16 04:08:00 -04:00
|
|
|
private $storage;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
2016-11-26 15:18:18 -05:00
|
|
|
/** @var bool */
|
2016-11-28 18:50:20 -05:00
|
|
|
protected $showFullscreen;
|
2016-11-26 15:18:18 -05:00
|
|
|
|
|
|
|
|
/** @var Url */
|
2015-03-16 04:08:00 -04:00
|
|
|
private $url;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
2015-01-21 03:22:25 -05:00
|
|
|
$m = Icinga::app()->getModuleManager();
|
|
|
|
|
if (! $m->hasLoaded('monitoring') && $m->hasInstalled('monitoring')) {
|
|
|
|
|
$m->loadModule('monitoring');
|
|
|
|
|
}
|
2017-01-10 10:49:53 -05:00
|
|
|
$this->controls();
|
|
|
|
|
$this->content();
|
2016-11-26 15:18:18 -05:00
|
|
|
$this->url();
|
|
|
|
|
$this->view->showFullscreen
|
|
|
|
|
= $this->showFullscreen
|
|
|
|
|
= (bool) $this->_helper->layout()->showFullscreen;
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->view->compact = $this->params->get('view') === 'compact';
|
2017-01-08 17:09:01 -05:00
|
|
|
$this->setViewScript('default');
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-26 15:18:18 -05:00
|
|
|
/**
|
|
|
|
|
* @return Url
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function url()
|
2014-11-30 05:54:46 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
if ($this->url === null) {
|
2016-11-26 15:18:18 -05:00
|
|
|
$this->url = Url::fromPath(
|
|
|
|
|
$this->getRequest()->getUrl()->getPath()
|
|
|
|
|
)->setParams($this->params);
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
2016-11-26 15:18:18 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
return $this->url;
|
|
|
|
|
}
|
2015-02-12 19:53:28 -05:00
|
|
|
|
2016-11-26 15:18:18 -05:00
|
|
|
/**
|
|
|
|
|
* @return ActionBar
|
|
|
|
|
*/
|
2016-11-22 09:28:37 -05:00
|
|
|
protected function actions()
|
|
|
|
|
{
|
|
|
|
|
if ($this->view->actions === null) {
|
2017-01-03 05:28:58 -05:00
|
|
|
$this->view->actions = new ActionBar();
|
2016-11-22 09:28:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->view->actions;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 17:15:12 -05:00
|
|
|
/**
|
|
|
|
|
* @return Controls
|
|
|
|
|
*/
|
2016-11-28 16:15:20 -05:00
|
|
|
protected function controls()
|
|
|
|
|
{
|
|
|
|
|
if ($this->view->controls === null) {
|
|
|
|
|
$this->view->controls = Controls::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->view->controls;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 09:32:56 -05:00
|
|
|
/**
|
|
|
|
|
* @return Content
|
|
|
|
|
*/
|
2016-11-28 16:15:20 -05:00
|
|
|
protected function content()
|
|
|
|
|
{
|
|
|
|
|
if ($this->view->content === null) {
|
|
|
|
|
$this->view->content = Content::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->view->content;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 17:15:12 -05:00
|
|
|
/**
|
|
|
|
|
* @param $label
|
|
|
|
|
* @return Tabs
|
|
|
|
|
*/
|
2016-11-28 16:15:20 -05:00
|
|
|
protected function singleTab($label)
|
|
|
|
|
{
|
2016-12-09 03:53:36 -05:00
|
|
|
return $this->tabs()->add(
|
2016-11-28 16:15:20 -05:00
|
|
|
'tab',
|
|
|
|
|
array(
|
|
|
|
|
'label' => $label,
|
|
|
|
|
'url' => $this->getRequest()->getUrl()
|
|
|
|
|
)
|
|
|
|
|
)->activate('tab');
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 17:15:12 -05:00
|
|
|
/**
|
|
|
|
|
* @return Tabs
|
|
|
|
|
*/
|
2016-11-28 16:15:20 -05:00
|
|
|
protected function defaultTab()
|
|
|
|
|
{
|
|
|
|
|
return $this->singleTab($this->translate('Business Process'));
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 03:53:36 -05:00
|
|
|
/**
|
|
|
|
|
* @return Tabs
|
|
|
|
|
*/
|
|
|
|
|
protected function overviewTab()
|
|
|
|
|
{
|
|
|
|
|
return $this->tabs()->add(
|
|
|
|
|
'overview',
|
|
|
|
|
array(
|
|
|
|
|
'label' => $this->translate('Business Process'),
|
|
|
|
|
'url' => 'businessprocess'
|
|
|
|
|
)
|
|
|
|
|
)->activate('overview');
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 07:57:07 -05:00
|
|
|
/**
|
|
|
|
|
* @return Tabs
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function tabs()
|
|
|
|
|
{
|
2016-12-09 03:53:36 -05:00
|
|
|
// Todo: do not add to view once all of them render controls()
|
2016-12-09 10:10:32 -05:00
|
|
|
if ($this->mytabs === null) {
|
|
|
|
|
$tabs = new Tabs();
|
|
|
|
|
//$this->controls()->add($tabs);
|
|
|
|
|
$this->mytabs = $tabs;
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
2016-12-09 03:53:36 -05:00
|
|
|
|
2016-12-09 10:10:32 -05:00
|
|
|
return $this->mytabs;
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function session()
|
|
|
|
|
{
|
2014-11-30 09:56:58 -05:00
|
|
|
return $this->Window()->getSessionNamespace('businessprocess');
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-26 15:18:18 -05:00
|
|
|
protected function setViewScript($name)
|
|
|
|
|
{
|
|
|
|
|
$this->_helper->viewRenderer->setNoController(true);
|
|
|
|
|
$this->_helper->viewRenderer->setScriptAction($name);
|
2016-11-28 16:15:20 -05:00
|
|
|
return $this;
|
2016-11-26 15:18:18 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function setTitle($title)
|
2014-11-30 05:54:46 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
$args = func_get_args();
|
|
|
|
|
array_shift($args);
|
|
|
|
|
$this->view->title = vsprintf($title, $args);
|
2016-11-28 16:15:20 -05:00
|
|
|
return $this;
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-10 10:49:53 -05:00
|
|
|
protected function addTitle($title)
|
|
|
|
|
{
|
|
|
|
|
$args = func_get_args();
|
|
|
|
|
array_shift($args);
|
|
|
|
|
$this->view->title = vsprintf($title, $args);
|
|
|
|
|
$this->controls()->add(HtmlTag::h1($this->view->title));
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function loadModifiedBpConfig()
|
|
|
|
|
{
|
|
|
|
|
$bp = $this->loadBpConfig();
|
|
|
|
|
$changes = ProcessChanges::construct($bp, $this->session());
|
|
|
|
|
if ($this->params->get('dismissChanges')) {
|
|
|
|
|
Notification::success(
|
|
|
|
|
sprintf(
|
|
|
|
|
$this->translate('%d pending change(s) have been dropped'),
|
|
|
|
|
$changes->count()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$changes->clear();
|
|
|
|
|
$this->redirectNow($this->url()->without('dismissChanges')->without('unlocked'));
|
|
|
|
|
}
|
|
|
|
|
$bp->applyChanges($changes);
|
|
|
|
|
return $bp;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 05:28:58 -05:00
|
|
|
protected function doNotRender()
|
|
|
|
|
{
|
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
|
$this->_helper->viewRenderer->setNoRender(true);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function loadBpConfig()
|
|
|
|
|
{
|
2016-12-16 13:37:39 -05:00
|
|
|
$name = $this->params->get('config');
|
2015-03-16 04:08:00 -04:00
|
|
|
$storage = $this->storage();
|
2015-11-17 08:46:50 -05:00
|
|
|
|
2015-11-22 18:44:14 -05:00
|
|
|
if (! $storage->hasProcess($name)) {
|
|
|
|
|
$this->httpNotFound(
|
|
|
|
|
$this->translate('No such process config: "%s"'),
|
|
|
|
|
$name
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$modifications = $this->session()->get('modifications', array());
|
|
|
|
|
if (array_key_exists($name, $modifications)) {
|
|
|
|
|
$bp = $storage->loadFromString($name, $modifications[$name]);
|
|
|
|
|
} else {
|
|
|
|
|
$bp = $storage->loadProcess($name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// allow URL parameter to override configured state type
|
2015-02-06 18:36:01 -05:00
|
|
|
if (null !== ($stateType = $this->params->get('state_type'))) {
|
|
|
|
|
if ($stateType === 'soft') {
|
|
|
|
|
$bp->useSoftStates();
|
|
|
|
|
}
|
2015-02-06 19:28:06 -05:00
|
|
|
if ($stateType === 'hard') {
|
2015-02-06 18:36:01 -05:00
|
|
|
$bp->useHardStates();
|
|
|
|
|
}
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
2015-02-06 18:36:01 -05:00
|
|
|
|
2015-11-17 09:47:29 -05:00
|
|
|
$this->view->bpconfig = $this->bp = $bp;
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->view->configName = $bp->getName();
|
|
|
|
|
|
2014-11-30 05:54:46 -05:00
|
|
|
return $bp;
|
|
|
|
|
}
|
2015-02-06 18:36:01 -05:00
|
|
|
|
2015-10-06 16:35:44 -04:00
|
|
|
public function loadForm($name)
|
|
|
|
|
{
|
|
|
|
|
return FormLoader::load($name, $this->Module());
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 10:10:32 -05:00
|
|
|
/**
|
|
|
|
|
* @return LegacyStorage|Storage
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function storage()
|
|
|
|
|
{
|
|
|
|
|
if ($this->storage === null) {
|
|
|
|
|
$this->storage = new LegacyStorage(
|
|
|
|
|
$this->Config()->getSection('global')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->storage;
|
|
|
|
|
}
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|