mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-26 05:52:54 -05:00
ActionBar: take over logic from controller
This commit is contained in:
parent
b11fbf5211
commit
18dc398dca
3 changed files with 109 additions and 93 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess;
|
||||
namespace Icinga\Module\Businessprocess\Web;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Module\Businessprocess\BusinessProcess;
|
||||
use Icinga\Module\Businessprocess\Html\HtmlString;
|
||||
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
|
|
@ -11,7 +12,6 @@ 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;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Web\View;
|
||||
|
|
@ -71,18 +71,6 @@ 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
|
||||
*/
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue