mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 15:54:03 +02:00
Fix multi-view badge filters
Allow providing a base URL for StateBadges to display hosts and services based on a filter. refs #5543
This commit is contained in:
parent
5a6aa1c073
commit
7e81b00a96
@ -207,6 +207,22 @@ class Url
|
|||||||
return $url->setQueryString($f->toQueryString());
|
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
|
* Overwrite the baseUrl
|
||||||
*
|
*
|
||||||
|
@ -19,6 +19,7 @@ if (! $stats instanceof stdClass) {
|
|||||||
<?php
|
<?php
|
||||||
$stateBadges = new StateBadges();
|
$stateBadges = new StateBadges();
|
||||||
$stateBadges
|
$stateBadges
|
||||||
|
->setBaseFilter(isset($baseFilter) ? $baseFilter : null)
|
||||||
->setUrl('monitoring/list/hosts')
|
->setUrl('monitoring/list/hosts')
|
||||||
->add(
|
->add(
|
||||||
StateBadges::STATE_UP,
|
StateBadges::STATE_UP,
|
||||||
|
@ -22,6 +22,7 @@ if (! $stats instanceof stdClass) {
|
|||||||
<?php
|
<?php
|
||||||
$stateBadges = new StateBadges();
|
$stateBadges = new StateBadges();
|
||||||
$stateBadges
|
$stateBadges
|
||||||
|
->setBaseFilter(isset($baseFilter) ? $baseFilter : null)
|
||||||
->setUrl('monitoring/list/services')
|
->setUrl('monitoring/list/services')
|
||||||
->add(
|
->add(
|
||||||
StateBadges::STATE_OK,
|
StateBadges::STATE_OK,
|
||||||
|
@ -8,6 +8,7 @@ use Icinga\Web\Navigation\Navigation;
|
|||||||
use Icinga\Web\Navigation\NavigationItem;
|
use Icinga\Web\Navigation\NavigationItem;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\AbstractWidget;
|
use Icinga\Web\Widget\AbstractWidget;
|
||||||
|
use Icinga\Data\Filter\Filter;
|
||||||
|
|
||||||
class StateBadges extends AbstractWidget
|
class StateBadges extends AbstractWidget
|
||||||
{
|
{
|
||||||
@ -123,6 +124,13 @@ class StateBadges extends AbstractWidget
|
|||||||
*/
|
*/
|
||||||
protected $priority = 1;
|
protected $priority = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base filter applied to any badge link
|
||||||
|
*
|
||||||
|
* @var Filter
|
||||||
|
*/
|
||||||
|
protected $baseFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base URL
|
* Base URL
|
||||||
*
|
*
|
||||||
@ -156,6 +164,29 @@ class StateBadges extends AbstractWidget
|
|||||||
return $this;
|
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
|
* Add a state badge
|
||||||
*
|
*
|
||||||
@ -193,6 +224,10 @@ class StateBadges extends AbstractWidget
|
|||||||
{
|
{
|
||||||
if ($this->has($state)) {
|
if ($this->has($state)) {
|
||||||
$badge = $this->get($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(
|
$badges->addItem(new NavigationItem($state, array(
|
||||||
'attributes' => array('class' => 'badge ' . $state),
|
'attributes' => array('class' => 'badge ' . $state),
|
||||||
'label' => $badge->count,
|
'label' => $badge->count,
|
||||||
@ -201,7 +236,7 @@ class StateBadges extends AbstractWidget
|
|||||||
mtp('monitoring', $badge->translateSingular, $badge->translatePlural, $badge->count),
|
mtp('monitoring', $badge->translateSingular, $badge->translatePlural, $badge->count),
|
||||||
$badge->translateArgs
|
$badge->translateArgs
|
||||||
),
|
),
|
||||||
'url' => clone $this->url->setParams($badge->filter)
|
'url' => $url
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user