From d3eff54603b334e6670aa5700eb637bf892ccbd1 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 28 Nov 2016 22:15:20 +0100 Subject: [PATCH] Controller: take over view tasks, move to parent --- application/controllers/NodeController.php | 3 +- application/controllers/ProcessController.php | 53 +++++++++++------- library/Businessprocess/Controller.php | 54 +++++++++++++++++++ 3 files changed, 89 insertions(+), 21 deletions(-) diff --git a/application/controllers/NodeController.php b/application/controllers/NodeController.php index 54d619d..c3d6a20 100644 --- a/application/controllers/NodeController.php +++ b/application/controllers/NodeController.php @@ -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(); } diff --git a/application/controllers/ProcessController.php b/application/controllers/ProcessController.php index c03ada2..25071e5 100644 --- a/application/controllers/ProcessController.php +++ b/application/controllers/ProcessController.php @@ -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(); diff --git a/library/Businessprocess/Controller.php b/library/Businessprocess/Controller.php index 1161806..da4b3ed 100644 --- a/library/Businessprocess/Controller.php +++ b/library/Businessprocess/Controller.php @@ -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()