Controller: take over view tasks, move to parent

This commit is contained in:
Thomas Gelf 2016-11-28 22:15:20 +01:00
parent e1d0996cef
commit d3eff54603
3 changed files with 89 additions and 21 deletions

View file

@ -54,6 +54,7 @@ class NodeController extends Controller
public function addAction()
{
$this->defaultTab();
$bp = $this->loadBpConfig();
$url = Url::fromPath(
@ -64,7 +65,7 @@ class NodeController extends Controller
$this->view->form = $this->loadForm('process')
->setProcess($bp)
->setSession($this->session())
->setRedirectUrl($url)
->setSuccessUrl($url)
->handleRequest();
}

View file

@ -4,8 +4,12 @@ namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Module\Businessprocess\Controller;
use Icinga\Module\Businessprocess\ConfigDiff;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
use Icinga\Module\Businessprocess\Renderer\TreeRenderer;
use Icinga\Module\Businessprocess\Simulation;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Web\Url;
@ -14,18 +18,6 @@ use Icinga\Web\Widget\Tabextension\DashboardAction;
class ProcessController extends Controller
{
protected function currentProcessParams()
{
$params = array();
foreach (array('config', 'node') as $name) {
if ($value = $this->params->get($name)) {
$params[$name] = $value;
}
}
return $params;
}
/**
* Create a new business process configuration
*/
@ -56,7 +48,7 @@ class ProcessController extends Controller
}
/**
* Show a business process tree
* Show a business process
*/
public function showAction()
{
@ -73,7 +65,6 @@ class ProcessController extends Controller
$bp = $this->loadBpConfig();
}
// Do not lock empty configs
if ($bp->isEmpty() && ! $this->view->compact && $bp->isLocked()) {
$this->redirectNow($this->url()->with('unlocked', true));
@ -98,8 +89,8 @@ class ProcessController extends Controller
$this->simulationForm();
}
$this->setTitle('Business Process "%s"', $bp->getTitle());
$title = sprintf('Business Process "%s"', $bp->getTitle());
$this->setTitle($title);
$this->tabsForShow()->activate('show');
if ($bp->isLocked()) {
@ -121,12 +112,34 @@ class ProcessController extends Controller
$bp->applySimulation($simulation);
}
// TODO: ...
$renderer = new TileRenderer($this->view, $bp, $bpNode);
if ($mode === 'tile') {
$renderer = new TileRenderer($bp, $bpNode);
} else {
$renderer = new TreeRenderer($bp, $bpNode);
}
$renderer->setBaseUrl($this->url())
->setPath($this->params->getValues('path'));
$this->view->bpRenderer = $renderer;
$this->view->breadcrumb = Breadcrumb::create($renderer);
$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());
}
if (! $bp->isLocked()) {
$renderer->unlock();

View file

@ -3,10 +3,13 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Application\Icinga;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Storage\Storage;
use Icinga\Module\Businessprocess\Web\Component\ActionBar;
use Icinga\Module\Businessprocess\Web\Component\Controls;
use Icinga\Module\Businessprocess\Web\Component\Content;
use Icinga\Module\Businessprocess\Web\Form\FormLoader;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Web\Controller as ModuleController;
@ -64,6 +67,18 @@ class Controller extends ModuleController
return $this->url;
}
protected function currentProcessParams()
{
$params = array();
foreach (array('config', 'node') as $name) {
if ($value = $this->params->get($name)) {
$params[$name] = $value;
}
}
return $params;
}
/**
* @return ActionBar
*/
@ -76,6 +91,43 @@ class Controller extends ModuleController
return $this->view->actions;
}
protected function controls()
{
if ($this->view->controls === null) {
$this->view->controls = Controls::create();
}
return $this->view->controls;
}
protected function content()
{
if ($this->view->content === null) {
$this->view->content = Content::create();
}
return $this->view->content;
}
protected function singleTab($label)
{
$tabs = Widget::create('tabs')->add(
'tab',
array(
'label' => $label,
'url' => $this->getRequest()->getUrl()
)
)->activate('tab');
$this->controls()->add(HtmlString::create($tabs));
return $tabs;
}
protected function defaultTab()
{
return $this->singleTab($this->translate('Business Process'));
}
protected function tabs()
{
if ($this->view->tabs === null) {
@ -93,6 +145,7 @@ class Controller extends ModuleController
{
$this->_helper->viewRenderer->setNoController(true);
$this->_helper->viewRenderer->setScriptAction($name);
return $this;
}
protected function setTitle($title)
@ -100,6 +153,7 @@ class Controller extends ModuleController
$args = func_get_args();
array_shift($args);
$this->view->title = vsprintf($title, $args);
return $this;
}
protected function loadModifiedBpConfig()