diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index aa7f652a3..9f31447ea 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -207,6 +207,22 @@ class Url return $url->setQueryString($f->toQueryString()); } + /** + * Set the new Filter of the url to be the current filter and the given filter + * + * @param Filter $and + */ + public function addFilter($and) + { + $this->setQueryString( + Filter::matchAll( + $and, + Filter::fromQueryString($this->getQueryString()) + )->toQueryString() + ); + return $this; + } + /** * Overwrite the baseUrl * diff --git a/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml b/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml index 058620dc4..68d67b882 100644 --- a/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml +++ b/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml @@ -19,6 +19,7 @@ if (! $stats instanceof stdClass) { setBaseFilter(isset($baseFilter) ? $baseFilter : null) ->setUrl('monitoring/list/hosts') ->add( StateBadges::STATE_UP, diff --git a/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml b/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml index 50dbf0dd2..1f3cfa402 100644 --- a/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml +++ b/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml @@ -22,6 +22,7 @@ if (! $stats instanceof stdClass) { setBaseFilter(isset($baseFilter) ? $baseFilter : null) ->setUrl('monitoring/list/services') ->add( StateBadges::STATE_OK, diff --git a/modules/monitoring/library/Monitoring/Web/Widget/StateBadges.php b/modules/monitoring/library/Monitoring/Web/Widget/StateBadges.php index 73d4169d6..1feb29d00 100644 --- a/modules/monitoring/library/Monitoring/Web/Widget/StateBadges.php +++ b/modules/monitoring/library/Monitoring/Web/Widget/StateBadges.php @@ -8,6 +8,7 @@ use Icinga\Web\Navigation\Navigation; use Icinga\Web\Navigation\NavigationItem; use Icinga\Web\Url; use Icinga\Web\Widget\AbstractWidget; +use Icinga\Data\Filter\Filter; class StateBadges extends AbstractWidget { @@ -123,6 +124,13 @@ class StateBadges extends AbstractWidget */ protected $priority = 1; + /** + * The base filter applied to any badge link + * + * @var Filter + */ + protected $baseFilter; + /** * Base URL * @@ -156,6 +164,29 @@ class StateBadges extends AbstractWidget return $this; } + /** + * Get the base filter + * + * @return Filter + */ + public function getBaseFilter() + { + return $this->baseFilter; + } + + /** + * Set the base filter + * + * @param Filter $baseFilter + * + * @return $this + */ + public function setBaseFilter($baseFilter) + { + $this->baseFilter = $baseFilter; + return $this; + } + /** * Add a state badge * @@ -193,6 +224,10 @@ class StateBadges extends AbstractWidget { if ($this->has($state)) { $badge = $this->get($state); + $url = clone $this->url->setParams($badge->filter); + if (isset($this->baseFilter)) { + $url->addFilter($this->baseFilter); + } $badges->addItem(new NavigationItem($state, array( 'attributes' => array('class' => 'badge ' . $state), 'label' => $badge->count, @@ -201,7 +236,7 @@ class StateBadges extends AbstractWidget mtp('monitoring', $badge->translateSingular, $badge->translatePlural, $badge->count), $badge->translateArgs ), - 'url' => clone $this->url->setParams($badge->filter) + 'url' => $url ))); } return $this;