monitoring: Use class Navigation for hook actions

This commit is contained in:
Johannes Meyer 2016-01-11 17:03:46 +01:00
parent 8b03a647ba
commit 1fe1f23031
5 changed files with 53 additions and 14 deletions

View File

@ -3,6 +3,8 @@
namespace Icinga\Module\Monitoring\Controllers;
use Icinga\Web\Hook;
use Icinga\Web\Navigation\Navigation;
use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
@ -11,7 +13,6 @@ use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandFor
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Web\Controller\MonitoredObjectController;
use Icinga\Web\Hook;
class HostController extends MonitoredObjectController
{
@ -43,15 +44,12 @@ class HostController extends MonitoredObjectController
*/
protected function getHostActions()
{
$urls = array();
$navigation = new Navigation();
foreach (Hook::all('Monitoring\\HostActions') as $hook) {
foreach ($hook->getActionsForHost($this->object) as $id => $url) {
$urls[$id] = $url;
}
$navigation->merge($hook->getNavigation($this->object));
}
return $urls;
return $navigation;
}
/**

View File

@ -8,8 +8,6 @@ foreach ($navigation as $item) {
$item->setObject($object);
}
foreach ($object->getActionUrls() as $i => $link) {
$navigation->addItem(
@ -31,9 +29,7 @@ foreach ($object->getActionUrls() as $i => $link) {
}
if (isset($this->actions)) {
foreach ($this->actions as $id => $action) {
$navigation->addItem($id, array('url' => $action));
}
$navigation->merge($this->actions);
}
if ($navigation->isEmpty() || !$navigation->hasRenderableItems()) {

View File

@ -8,7 +8,7 @@ use Icinga\Module\Monitoring\Object\Host;
/**
* Base class for host action hooks
*/
abstract class HostActionsHook
abstract class HostActionsHook extends ObjectActionsHook
{
/**
* Implementors of this method should return an array containing

View File

@ -0,0 +1,45 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Hook;
use Icinga\Web\Navigation\Navigation;
use Icinga\Module\Monitoring\Object\MonitoredObject;
/**
* Base class for object action hooks
*/
abstract class ObjectActionsHook
{
/**
* Return the action navigation for the given object
*
* @return Navigation
*/
public function getNavigation(MonitoredObject $object)
{
$urls = $this->getActionsForHost($object);
if (is_array($urls)) {
$navigation = new Navigation();
foreach ($urls as $label => $url) {
$navigation->addItem($label, array('url' => $url));
}
} else {
$navigation = $urls;
}
return $navigation;
}
/**
* Create and return a new Navigation object
*
* @param array $actions Optional array of actions to add to the returned object
*
* @return Navigation
*/
protected function createNavigation(array $actions = null)
{
return empty($actions) ? new Navigation() : Navigation::fromArray($actions);
}
}

View File

@ -8,7 +8,7 @@ use Icinga\Module\Monitoring\Object\Service;
/**
* Base class for host action hooks
*/
abstract class ServiceActionsHook
abstract class ServiceActionsHook extends ObjectActionsHook
{
/**
* Implementors of this method should return an array containing