Deduplicate and clean up service summary component
Remove redundant component view script and streamline subFilter handling in all views that render it. Remove heading from component to allow embedding in different types of views. refs #10033
This commit is contained in:
parent
1b7b0c7232
commit
ca33e71f2d
|
@ -6,7 +6,7 @@ namespace Icinga\Web;
|
|||
use Icinga\Application\Icinga;
|
||||
use Icinga\Cli\FakeRequest;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\UrlParams;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
/**
|
||||
* Url class that provides convenient access to parameters, allows to modify query parameters and
|
||||
|
@ -156,6 +156,26 @@ class Url
|
|||
return $urlObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new filter that needs to fullfill the base filter and the optional filter (if it exists)
|
||||
*
|
||||
* @param string $url The url to apply the new filter to
|
||||
* @param Filter $filter The base filter
|
||||
* @param Filter $optional The optional filter
|
||||
*
|
||||
* @return Url The altered URL containing the new filter
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public static function urlAddFilterOptional($url, $filter, $optional)
|
||||
{
|
||||
$url = Url::fromPath($url);
|
||||
$f = $filter;
|
||||
if (isset($optional)) {
|
||||
$f = Filter::matchAll($filter, $optional);
|
||||
}
|
||||
return $url->setQueryString($f->toQueryString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the baseUrl
|
||||
*
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
<?php use Icinga\Data\Filter\Filter; ?>
|
||||
|
||||
<div class="controls">
|
||||
<?php if (! $this->compact): ?>
|
||||
<?= $this->tabs; ?>
|
||||
<?php endif ?>
|
||||
<?= $this->render('partials/host/object-header.phtml') ?>
|
||||
<?= $this->render('partials/host/servicesummary.phtml') ?>
|
||||
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>
|
||||
<?php
|
||||
$this->baseFilter = Filter::where('host', $object->host_name);
|
||||
$this->stats = $object->stats;
|
||||
echo $this->render('list/components/servicesummary.phtml');
|
||||
?>
|
||||
</h2>
|
||||
</div>
|
||||
<?= $this->partial(
|
||||
'list/services.phtml',
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
<?php use Icinga\Data\Filter\Filter; ?>
|
||||
|
||||
<div class="controls separated">
|
||||
<?php if (! $this->compact): ?>
|
||||
<?= $this->tabs; ?>
|
||||
<?php endif ?>
|
||||
<?= $this->render('partials/host/object-header.phtml') ?>
|
||||
<?= $this->render('partials/host/servicesummary.phtml') ?>
|
||||
<h3 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
|
||||
<?php
|
||||
$this->stats = $object->stats;
|
||||
$this->baseFilter = Filter::where('host', $object->host_name);
|
||||
echo $this->render('list/components/servicesummary.phtml');
|
||||
?>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="content" data-base-target="_next">
|
||||
<?= $this->render('show/components/output.phtml') ?>
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
<?= $tabs; ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $this->render('list/components/hostssummary.phtml') ?>
|
||||
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>
|
||||
<?= $this->render('list/components/hostssummary.phtml') ?>
|
||||
</h2>
|
||||
<?= $this->render('partials/host/objects-header.phtml'); ?>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -3,20 +3,16 @@
|
|||
use Icinga\Web\Url;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
|
||||
function urlAddFilterOptional($url, $filter, $optional) {
|
||||
$url = Url::fromPath($url);
|
||||
$f = $filter;
|
||||
if (isset($optional)) {
|
||||
$f = Filter::matchAll($filter, $optional);
|
||||
}
|
||||
return $url->setQueryString($f->toQueryString());
|
||||
}
|
||||
$this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null;
|
||||
|
||||
$stats = $stats->fetchRow();
|
||||
// don't fetch rows until they are actually needed to improve dashlet performance
|
||||
if (!$stats instanceof stdClass) {
|
||||
$stats = $stats->fetchRow();
|
||||
}
|
||||
|
||||
$selfUrl = 'monitoring/list/hosts';
|
||||
$currentUrl = Url::fromRequest()->getRelativeUrl();
|
||||
?><h1 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
|
||||
?>
|
||||
<?= $this->qlink(
|
||||
sprintf($this->translatePlural('%u Host', '%u Hosts', $stats->hosts_total), $stats->hosts_total),
|
||||
$selfUrl,
|
||||
|
@ -31,7 +27,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->qlink(
|
||||
$stats->hosts_up,
|
||||
urlAddFilterOptional(
|
||||
Url::urlAddFilterOptional(
|
||||
$selfUrl,
|
||||
Filter::where('host_state', 0),
|
||||
$this->baseFilter
|
||||
|
@ -54,7 +50,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
<span class="state critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->qlink(
|
||||
$stats->hosts_down_unhandled,
|
||||
urlAddFilterOptional(
|
||||
Url::urlAddFilterOptional(
|
||||
$selfUrl,
|
||||
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)),
|
||||
$this->baseFilter
|
||||
|
@ -75,7 +71,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
<span class="state handled critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' =>0))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->qlink(
|
||||
$stats->hosts_down_handled,
|
||||
urlAddFilterOptional(
|
||||
Url::urlAddFilterOptional(
|
||||
$selfUrl,
|
||||
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 0)),
|
||||
$this->baseFilter
|
||||
|
@ -101,7 +97,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
<span class="state unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->qlink(
|
||||
$stats->hosts_unreachable_unhandled,
|
||||
urlAddFilterOptional(
|
||||
Url::urlAddFilterOptional(
|
||||
$selfUrl,
|
||||
Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 1)),
|
||||
$this->baseFilter
|
||||
|
@ -122,7 +118,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
<span class="state handled unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 0))->getRelativeUrl() ? ' active' : '' ?>">
|
||||
<?= $this->qlink(
|
||||
$stats->hosts_unreachable_handled,
|
||||
urlAddFilterOptional(
|
||||
Url::urlAddFilterOptional(
|
||||
$selfUrl,
|
||||
Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 0)),
|
||||
$this->baseFilter
|
||||
|
@ -148,7 +144,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->qlink(
|
||||
$stats->hosts_pending,
|
||||
urlAddFilterOptional(
|
||||
Url::urlAddFilterOptional(
|
||||
$selfUrl,
|
||||
Filter::where('host_state', 99),
|
||||
$this->baseFilter
|
||||
|
@ -166,4 +162,3 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
</span>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</h1>
|
||||
|
|
|
@ -4,21 +4,16 @@ use Icinga\Data\Filter\Filter;
|
|||
use Icinga\Web\Url;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
|
||||
function urlAddFilterOptional($url, $filter, $optional) {
|
||||
$url = Url::fromPath($url);
|
||||
$f = $filter;
|
||||
if (isset($optional)) {
|
||||
$f = Filter::matchAll($filter, $optional);
|
||||
}
|
||||
return $url->setQueryString($f->toQueryString());
|
||||
}
|
||||
$this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null;
|
||||
|
||||
$stats = $stats->fetchRow();
|
||||
// don't fetch rows until they are actually needed, to improve dashlet performance
|
||||
if (!$stats instanceof stdClass) {
|
||||
$stats = $stats->fetchRow();
|
||||
};
|
||||
$selfUrl = 'monitoring/list/services';
|
||||
$currentUrl = Url::fromRequest()->getRelativeUrl();
|
||||
?><h1 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
|
||||
<?= $this->qlink(
|
||||
|
||||
echo $this->qlink(
|
||||
sprintf($this->translatePlural(
|
||||
'%u Service', '%u Services', $stats->services_total),
|
||||
$stats->services_total
|
||||
|
@ -36,7 +31,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl();
|
|||
<?=
|
||||
$this->qlink(
|
||||
$stats->services_ok,
|
||||
urlAddFilterOptional($selfUrl, Filter::where('service_state', 0), $this->baseFilter),
|
||||
Url::urlAddFilterOptional($selfUrl, Filter::where('service_state', 0), $this->baseFilter),
|
||||
null,
|
||||
array('title' => sprintf(
|
||||
$this->translatePlural(
|
||||
|
@ -81,7 +76,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
|
|||
|
||||
echo $this->qlink(
|
||||
$stats->$unhandled,
|
||||
urlAddFilterOptional($selfUrl, $paramsUnhandled, $this->baseFilter),
|
||||
Url::urlAddFilterOptional($selfUrl, $paramsUnhandled, $this->baseFilter),
|
||||
null,
|
||||
array('title' => sprintf(
|
||||
$this->translatePlural(
|
||||
|
@ -106,7 +101,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
|
|||
}
|
||||
echo $this->qlink(
|
||||
$stats->$handled,
|
||||
urlAddFilterOptional($selfUrl, $paramsHandled, $this->baseFilter),
|
||||
Url::urlAddFilterOptional($selfUrl, $paramsHandled, $this->baseFilter),
|
||||
null,
|
||||
array('title' => sprintf(
|
||||
$this->translatePlural(
|
||||
|
@ -130,7 +125,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
|
|||
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->qlink(
|
||||
$stats->services_pending,
|
||||
urlAddFilterOptional($selfUrl, Filter::where('service_state', 99), $this->baseFilter),
|
||||
Url::urlAddFilterOptional($selfUrl, Filter::where('service_state', 99), $this->baseFilter),
|
||||
null,
|
||||
array('title' => sprintf(
|
||||
$this->translatePlural(
|
||||
|
@ -144,4 +139,3 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
|
|||
</span>
|
||||
<?php endif ?>
|
||||
</span>
|
||||
</h1>
|
||||
|
|
|
@ -8,7 +8,9 @@ if (! $this->compact): ?>
|
|||
<?= $this->tabs; ?>
|
||||
<div class="dontprint">
|
||||
<?= $this->render('list/components/selectioninfo.phtml'); ?>
|
||||
<?= $this->render('list/components/hostssummary.phtml'); ?>
|
||||
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>
|
||||
<?= $this->render('list/components/hostssummary.phtml'); ?>
|
||||
</h2>
|
||||
</div>
|
||||
<?= $this->sortBox; ?>
|
||||
<?= $this->limiter; ?>
|
||||
|
|
|
@ -10,7 +10,9 @@ if (! $this->compact): ?>
|
|||
<?= $this->tabs ?>
|
||||
<div class="dontprint">
|
||||
<?= $this->render('list/components/selectioninfo.phtml') ?>
|
||||
<?= $this->render('list/components/servicesummary.phtml') ?>
|
||||
<h1 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
|
||||
<?= $this->render('list/components/servicesummary.phtml') ?>
|
||||
</h1>
|
||||
</div>
|
||||
<?= $this->sortBox ?>
|
||||
<?= $this->limiter ?>
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
<?php use Icinga\Data\Filter\Filter; ?>
|
||||
|
||||
<div class="controls">
|
||||
<?php if (! $this->compact): ?>
|
||||
<?= $this->tabs; ?>
|
||||
<?php endif ?>
|
||||
<?php if ($object->getType() === $object::TYPE_HOST): ?>
|
||||
<?= $this->render('partials/host/object-header.phtml'); ?>
|
||||
<?= $this->render('partials/host/servicesummary.phtml'); ?>
|
||||
<h3 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>">
|
||||
<?php
|
||||
$this->baseFilter = Filter::where('host', $object->host_name);
|
||||
$this->stats = $object->stats;
|
||||
echo $this->render('list/components/servicesummary.phtml');
|
||||
?>
|
||||
</h3>
|
||||
<?php else: ?>
|
||||
<?= $this->render('partials/service/object-header.phtml'); ?>
|
||||
<hr class="command-separator">
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
<?php use Icinga\Data\Filter\Filter; ?>
|
||||
|
||||
<div class="controls">
|
||||
|
||||
<?php if (! $this->compact): ?>
|
||||
|
@ -5,10 +7,14 @@
|
|||
<?php endif ?>
|
||||
|
||||
<?php if (isset($serviceStates)): ?>
|
||||
<?= $this->render('list/components/servicesummary.phtml') ?>
|
||||
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>
|
||||
<?= $this->render('list/components/servicesummary.phtml'); ?>
|
||||
</h2>
|
||||
<?= $this->render('partials/service/objects-header.phtml'); ?>
|
||||
<?php else: ?>
|
||||
<?= $this->render('list/components/hostssummary.phtml') ?>
|
||||
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>
|
||||
<?= $this->render('list/components/hostssummary.phtml') ?>
|
||||
</h2>
|
||||
<?= $this->render('partials/host/objects-header.phtml'); ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
|
|
@ -1,150 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Module\Monitoring\Object\Service;
|
||||
|
||||
function urlAddFilterOptional($url, $filter, $optional) {
|
||||
$url = Url::fromPath($url);
|
||||
$f = $filter;
|
||||
if (isset($optional)) {
|
||||
$f = Filter::matchAll($filter, $optional);
|
||||
}
|
||||
return $url->setQueryString($f->toQueryString());
|
||||
}
|
||||
|
||||
$selfUrl = Url::fromPath('monitoring/list/services', array('host' => $object->host_name));
|
||||
?><h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
|
||||
<?php if ($object->stats->services_total): ?>
|
||||
<?= $this->qlink(
|
||||
sprintf(
|
||||
$this->translatePlural(
|
||||
'%u configured service:',
|
||||
'%u configured services:',
|
||||
$object->stats->services_total
|
||||
),
|
||||
$object->stats->services_total
|
||||
),
|
||||
$selfUrl,
|
||||
null,
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translatePlural(
|
||||
'List all %u service on host %s',
|
||||
'List all %u services on host %s',
|
||||
$object->stats->services_total
|
||||
),
|
||||
$object->stats->services_total,
|
||||
$object->host_name
|
||||
),
|
||||
'data-base-target' => '_next'
|
||||
)
|
||||
); ?>
|
||||
<?php else: ?>
|
||||
<?= $this->translate('No services configured on this host'); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<span class="badges">
|
||||
<?php if ($object->stats->services_ok): ?>
|
||||
<span class="state ok">
|
||||
<?= $this->qlink(
|
||||
$object->stats->services_ok,
|
||||
$selfUrl,
|
||||
array('service_state' => 0),
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translatePlural(
|
||||
'List %u service that is currently in state OK on host %s',
|
||||
'List %u services which are currently in state OK on host %s',
|
||||
$object->stats->services_ok
|
||||
),
|
||||
$object->stats->services_ok,
|
||||
$object->host_name
|
||||
),
|
||||
'data-base-target' => '_next'
|
||||
)
|
||||
); ?>
|
||||
</span>
|
||||
<?php endif ?>
|
||||
<?php
|
||||
foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $state) {
|
||||
$pre = 'services_' . $state;
|
||||
if ($object->stats->$pre) {
|
||||
$handled = $pre . '_handled';
|
||||
$unhandled = $pre . '_unhandled';
|
||||
$paramsHandled = array('service_state' => $stateId, 'service_handled' => 1);
|
||||
$paramsUnhandled = array('service_state' => $stateId, 'service_handled' => 0);
|
||||
echo '<span class="state ' . $state . ($object->stats->$unhandled ? '' : ' handled') . '">';
|
||||
if ($object->stats->$unhandled) {
|
||||
|
||||
echo $this->qlink(
|
||||
$object->stats->$unhandled,
|
||||
$selfUrl,
|
||||
$paramsUnhandled,
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translatePlural(
|
||||
'List %u service that is currently in state %s on host %s',
|
||||
'List %u services which are currently in state %s on host %s',
|
||||
$object->stats->$unhandled
|
||||
),
|
||||
$object->stats->$unhandled,
|
||||
Service::getStateText($stateId, true),
|
||||
$object->host_name
|
||||
),
|
||||
'data-base-target' => '_next'
|
||||
)
|
||||
);
|
||||
}
|
||||
if ($object->stats->$handled) {
|
||||
if ($object->stats->$unhandled) {
|
||||
echo '<span class="state handled ' . $state . '">';
|
||||
}
|
||||
echo $this->qlink(
|
||||
$object->stats->$handled,
|
||||
$selfUrl,
|
||||
$paramsHandled,
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translatePlural(
|
||||
'List %u service that is currently in state %s (Acknowledged) on host %s',
|
||||
'List %u services which are currently in state %s (Acknowledged) on host %s',
|
||||
$object->stats->$handled
|
||||
),
|
||||
$object->stats->$handled,
|
||||
Service::getStateText($stateId, true),
|
||||
$object->host_name
|
||||
),
|
||||
'data-base-target' => '_next'
|
||||
)
|
||||
);
|
||||
if ($object->stats->$unhandled) {
|
||||
echo "</span>\n";
|
||||
}
|
||||
}
|
||||
echo "</span>\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if ($object->stats->services_pending): ?>
|
||||
<span class="state pending">
|
||||
<?= $this->qlink(
|
||||
$object->stats->services_pending,
|
||||
$selfUrl,
|
||||
array('service_state' => 99),
|
||||
array(
|
||||
'title' => sprintf(
|
||||
$this->translatePlural(
|
||||
'List %u service that is currently in state PENDING on host %s',
|
||||
'List %u services which are currently in state PENDING on host %s',
|
||||
$object->stats->services_pending
|
||||
),
|
||||
$object->stats->services_pending,
|
||||
$object->host_name
|
||||
),
|
||||
'data-base-target' => '_next'
|
||||
)
|
||||
) ?>
|
||||
</span>
|
||||
<?php endif ?>
|
||||
</span>
|
||||
</h2>
|
|
@ -4,7 +4,10 @@
|
|||
<?= $tabs; ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $this->render('list/components/servicesummary.phtml') ?>
|
||||
|
||||
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>
|
||||
<?= $this->render('list/components/servicesummary.phtml') ?>
|
||||
</h2>
|
||||
<?= $this->render('partials/service/objects-header.phtml'); ?>
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue