Implement DetailviewExtensionHook

refs #2104
This commit is contained in:
Alexander A. Klimov 2017-01-24 16:44:00 +01:00
parent 59cadde485
commit 0a9aa20dfa
4 changed files with 52 additions and 0 deletions

View File

@ -1,6 +1,7 @@
<div class="content" data-base-target="_next">
<?= $this->render('show/components/output.phtml') ?>
<?= $this->render('show/components/grapher.phtml') ?>
<?= $this->render('show/components/extensions.phtml') ?>
<h2><?= $this->translate('Problem handling') ?></h2>
<table class="name-value-table">

View File

@ -0,0 +1,4 @@
<?php
foreach ($extensionsHtml as $extensionHtml) {
echo $extensionHtml;
}

View File

@ -0,0 +1,40 @@
<?php
/* Icinga Web 2 | (c) 2017 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Hook;
use Icinga\Module\Monitoring\Object\MonitoredObject;
/**
* Base class for hooks extending the detail view of monitored objects
*
* Extend this class if you want to extend the detail view of monitored objects with custom HTML.
*/
abstract class DetailviewExtensionHook
{
/**
* Create a new hook
*
* @see init() For hook initialization.
*/
final public function __construct()
{
$this->init();
}
/**
* Overwrite this function for hook initialization, e.g. loading the hook's config
*/
protected function init()
{
}
/**
* Shall return valid HTML to include in the detail view
*
* @param MonitoredObject $object The object to generate HTML for
*
* @return string
*/
abstract public function getHtmlForObject(MonitoredObject $object);
}

View File

@ -10,6 +10,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ToggleObjectFeaturesCommandForm;
use Icinga\Module\Monitoring\Hook\DetailviewExtensionHook;
use Icinga\Web\Hook;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
@ -96,6 +97,12 @@ abstract class MonitoredObjectController extends Controller
}
$this->view->showInstance = $this->backend->select()->from('instance')->count() > 1;
$this->view->object = $this->object;
$this->view->extensionsHtml = array();
foreach (Hook::all('Monitoring\DetailviewExtension') as $hook) {
/** @var DetailviewExtensionHook $hook */
$this->view->extensionsHtml[] = $hook->getHtmlForObject($this->object);
}
}
/**