DetailviewExtension: Integrate into multi-select views

refs #3072
This commit is contained in:
Markus Frosch 2018-01-23 17:27:04 +01:00
parent ecbfafd25a
commit 4753262589
6 changed files with 65 additions and 5 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Controllers;
use Exception;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterEqual;
use Icinga\Module\Monitoring\Controller;
@ -16,7 +17,9 @@ use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostCheckCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleHostDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ToggleObjectFeaturesCommandForm;
use Icinga\Module\Monitoring\Hook\DetailviewExtensionHook;
use Icinga\Module\Monitoring\Object\HostList;
use Icinga\Web\Hook;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
@ -151,6 +154,24 @@ class HostsController extends Controller
$this->view->commentsLink = Url::fromRequest()->setPath('monitoring/list/comments');
$this->view->sendCustomNotificationLink = Url::fromRequest()
->setPath('monitoring/hosts/send-custom-notification');
$this->view->extensionsHtml = array();
foreach (Hook::all('Monitoring\DetailviewExtension') as $hook) {
/** @var DetailviewExtensionHook $hook */
try {
$html = $hook->setView($this->view)->getHtmlForObjects($this->hostList);
} catch (Exception $e) {
$html = $this->view->escape($e->getMessage());
}
if ($html) {
$module = $this->view->escape($hook->getModule()->getName());
$this->view->extensionsHtml[] =
'<div class="icinga-module module-' . $module . '" data-icinga-module="' . $module . '">'
. $html
. '</div>';
}
}
}
/**

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Controllers;
use Exception;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm;
@ -15,7 +16,9 @@ use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceCheckCommandFor
use Icinga\Module\Monitoring\Forms\Command\Object\ScheduleServiceDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ToggleObjectFeaturesCommandForm;
use Icinga\Module\Monitoring\Hook\DetailviewExtensionHook;
use Icinga\Module\Monitoring\Object\ServiceList;
use Icinga\Web\Hook;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
@ -153,6 +156,24 @@ class ServicesController extends Controller
$this->view->sendCustomNotificationLink = Url::fromRequest()->setPath(
'monitoring/services/send-custom-notification'
);
$this->view->extensionsHtml = array();
foreach (Hook::all('Monitoring\DetailviewExtension') as $hook) {
/** @var DetailviewExtensionHook $hook */
try {
$html = $hook->setView($this->view)->getHtmlForObjects($this->serviceList);
} catch (Exception $e) {
$html = $this->view->escape($e->getMessage());
}
if ($html) {
$module = $this->view->escape($hook->getModule()->getName());
$this->view->extensionsHtml[] =
'<div class="icinga-module module-' . $module . '" data-icinga-module="' . $module . '">'
. $html
. '</div>';
}
}
}
/**

View File

@ -17,6 +17,7 @@
<?php if ($hostCount === 0): ?>
<?= $this->translate('No hosts found matching the filter'); ?>
<?php else: ?>
<?= $this->render('show/components/extensions.phtml') ?>
<h2><?= $this->translate('Problem Handling') ?></h2>
<table class="name-value-table">
<tbody>

View File

@ -19,6 +19,7 @@
<?php if ($serviceCount === 0): ?>
<?= $this->translate('No services found matching the filter') ?>
<?php else: ?>
<?= $this->render('show/components/extensions.phtml') ?>
<h2> <?= $this->translate('Problem handling') ?> </h2>
<table class="name-value-table">
<tbody>

View File

@ -7,6 +7,7 @@ use Icinga\Application\ClassLoader;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Module\Monitoring\Object\ObjectList;
use Icinga\Web\View;
/**
@ -56,6 +57,19 @@ abstract class DetailviewExtensionHook
*/
abstract public function getHtmlForObject(MonitoredObject $object);
/**
* Shall return valid HTML to include in the detail view of a multi-select view
*
* @param ObjectList $objects A list of objects shown in the multi-select view
*
* @return string
*/
public function getHtmlForObjects($objects)
{
// For compatibility empty by default
return '';
}
/**
* Get {@link view}
*

View File

@ -92,11 +92,13 @@ abstract class MonitoredObjectController extends Controller
$html = $this->view->escape($e->getMessage());
}
$module = $this->view->escape($hook->getModule()->getName());
$this->view->extensionsHtml[] =
'<div class="icinga-module module-' . $module . '" data-icinga-module="' . $module . '">'
. $html
. '</div>';
if ($html) {
$module = $this->view->escape($hook->getModule()->getName());
$this->view->extensionsHtml[] =
'<div class="icinga-module module-' . $module . '" data-icinga-module="' . $module . '">'
. $html
. '</div>';
}
}
}