From 1fe1f230317b73a159b7dd144bbca6a3ea6d028e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 11 Jan 2016 17:03:46 +0100 Subject: [PATCH] monitoring: Use class Navigation for hook actions --- .../controllers/HostController.php | 12 +++-- .../scripts/show/components/actions.phtml | 6 +-- .../Monitoring/Hook/HostActionsHook.php | 2 +- .../Monitoring/Hook/ObjectActionsHook.php | 45 +++++++++++++++++++ .../Monitoring/Hook/ServiceActionsHook.php | 2 +- 5 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 modules/monitoring/library/Monitoring/Hook/ObjectActionsHook.php diff --git a/modules/monitoring/application/controllers/HostController.php b/modules/monitoring/application/controllers/HostController.php index b8516b32f..3bdb26097 100644 --- a/modules/monitoring/application/controllers/HostController.php +++ b/modules/monitoring/application/controllers/HostController.php @@ -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; } /** diff --git a/modules/monitoring/application/views/scripts/show/components/actions.phtml b/modules/monitoring/application/views/scripts/show/components/actions.phtml index f6e6975a3..0e13da551 100644 --- a/modules/monitoring/application/views/scripts/show/components/actions.phtml +++ b/modules/monitoring/application/views/scripts/show/components/actions.phtml @@ -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()) { diff --git a/modules/monitoring/library/Monitoring/Hook/HostActionsHook.php b/modules/monitoring/library/Monitoring/Hook/HostActionsHook.php index b7923bcc8..c81612851 100644 --- a/modules/monitoring/library/Monitoring/Hook/HostActionsHook.php +++ b/modules/monitoring/library/Monitoring/Hook/HostActionsHook.php @@ -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 diff --git a/modules/monitoring/library/Monitoring/Hook/ObjectActionsHook.php b/modules/monitoring/library/Monitoring/Hook/ObjectActionsHook.php new file mode 100644 index 000000000..e6996886c --- /dev/null +++ b/modules/monitoring/library/Monitoring/Hook/ObjectActionsHook.php @@ -0,0 +1,45 @@ +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); + } +} diff --git a/modules/monitoring/library/Monitoring/Hook/ServiceActionsHook.php b/modules/monitoring/library/Monitoring/Hook/ServiceActionsHook.php index 6c1ef25ce..e40299a7a 100644 --- a/modules/monitoring/library/Monitoring/Hook/ServiceActionsHook.php +++ b/modules/monitoring/library/Monitoring/Hook/ServiceActionsHook.php @@ -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