diff --git a/application/controllers/ProcessController.php b/application/controllers/ProcessController.php index a9620f2..5ac20e8 100644 --- a/application/controllers/ProcessController.php +++ b/application/controllers/ProcessController.php @@ -14,6 +14,7 @@ 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\Component\ActionBar; use Icinga\Module\Businessprocess\Web\Controller; use Icinga\Module\Businessprocess\Web\Url; use Icinga\Web\Notification; @@ -60,7 +61,6 @@ class ProcessController extends Controller { $bp = $this->prepareProcess(); $node = $this->getNode($bp); - $this->prepareActionBar(); $this->redirectOnConfigSwitch(); $bp->retrieveStatesFromBackend(); $this->handleSimulations($bp); @@ -275,83 +275,7 @@ class ProcessController extends Controller return $bp; } - protected function prepareActionBar() - { - $mode = $this->params->get('mode'); - $unlocked = (bool) $this->params->get('unlocked'); - if ($mode === 'tile') { - $this->actions()->add( - Link::create( - $this->translate('Tree'), - $this->url()->with('mode', 'tree'), - null, - 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')->without('action'), - 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('Config'), - 'businessprocess/process/config', - $this->currentProcessParams(), - array( - 'class' => 'icon-wrench', - 'title' => $this->translate('Modify this process'), - 'data-base-target' => '_next', - ) - ) - ); - - $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', - ) - ) - ); - } /** * Show the source code for a process diff --git a/library/Businessprocess/Web/Component/ActionBar.php b/library/Businessprocess/Web/Component/ActionBar.php index d44cccc..c30d554 100644 --- a/library/Businessprocess/Web/Component/ActionBar.php +++ b/library/Businessprocess/Web/Component/ActionBar.php @@ -2,11 +2,112 @@ namespace Icinga\Module\Businessprocess\Web\Component; -use Icinga\Module\Businessprocess\Html\Container; +use Icinga\Authentication\Auth; +use Icinga\Module\Businessprocess\BusinessProcess; +use Icinga\Module\Businessprocess\Html\BaseElement; +use Icinga\Module\Businessprocess\Html\Link; +use Icinga\Module\Businessprocess\Renderer\Renderer; +use Icinga\Module\Businessprocess\Renderer\TreeRenderer; -class ActionBar extends Container +class ActionBar extends BaseElement { protected $contentSeparator = ' '; + /** @var string */ + protected $tag = 'div'; + protected $defaultAttributes = array('class' => 'action-bar'); + + public function __construct(BusinessProcess $config, Renderer $renderer, Auth $auth, $url) + { + $meta = $config->getMetadata(); + + if ($renderer instanceof TreeRenderer) { + $this->add( + Link::create( + $this->translate('Tiles'), + $url->with('mode', 'tile'), + null, + array('class' => 'icon-dashboard') + ) + ); + } else { + $this->add( + Link::create( + $this->translate('Tree'), + $url->with('mode', 'tree'), + null, + array('class' => 'icon-sitemap') + ) + ); + } + $hasChanges = $config->hasSimulations() || $config->hasBeenChanged(); + + if ($renderer->isLocked()) { + $this->add( + Link::create( + $this->translate('Unlock'), + $url->with('unlocked', true), + null, + array( + 'class' => 'icon-lock-open', + 'title' => $this->translate('Unlock this process'), + ) + ) + ); + } elseif (! $hasChanges) { + $this->add( + Link::create( + $this->translate('Lock'), + $url->without('unlocked')->without('action'), + null, + array( + 'class' => 'icon-lock', + 'title' => $this->translate('Lock this process'), + ) + ) + ); + } + + if ($meta->canModify()) { + $this->add( + Link::create( + $this->translate('Config'), + 'businessprocess/process/config', + $this->currentProcessParams($url), + array( + 'class' => 'icon-wrench', + 'title' => $this->translate('Modify this process'), + 'data-base-target' => '_next', + ) + ) + ); + } + + $this->add( + Link::create( + $this->translate('Fullscreen'), + $url->with('showFullscreen', true), + null, + array( + 'class' => 'icon-resize-full-alt', + 'title' => $this->translate('Switch to fullscreen mode'), + 'data-base-target' => '_main', + ) + ) + ); + } + + protected function currentProcessParams($url) + { + $urlParams = $url->getParams(); + $params = array(); + foreach (array('config', 'node') as $name) { + if ($value = $urlParams->get($name)) { + $params[$name] = $value; + } + } + + return $params; + } } diff --git a/library/Businessprocess/Web/Controller.php b/library/Businessprocess/Web/Controller.php index 20e91c0..5ab5b0c 100644 --- a/library/Businessprocess/Web/Controller.php +++ b/library/Businessprocess/Web/Controller.php @@ -1,8 +1,9 @@ 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 */ @@ -156,6 +144,9 @@ class Controller extends ModuleController )->activate('overview'); } + /** + * @return Tabs + */ protected function tabs() { // Todo: do not add to view once all of them render controls()