Action: Accept and apply option "filter"

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-17 11:00:40 +02:00
parent f4032988bf
commit bf4e492fa1
2 changed files with 48 additions and 1 deletions

View File

@ -124,7 +124,6 @@ class NavigationItem implements IteratorAggregate
public function __construct($name, array $properties = null)
{
$this->setName($name);
$this->render = true;
$this->priority = 100;
$this->children = new Navigation();
@ -717,6 +716,10 @@ class NavigationItem implements IteratorAggregate
*/
public function getRender()
{
if ($this->render === null) {
return true;
}
return $this->render;
}

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Web\Navigation;
use Icinga\Data\Filter\Filter;
use Icinga\Web\Navigation\NavigationItem;
use Icinga\Module\Monitoring\Object\Macro;
use Icinga\Module\Monitoring\Object\MonitoredObject;
@ -26,6 +27,13 @@ class Action extends NavigationItem
*/
protected $object;
/**
* The filter to use when being asked whether to render this action
*
* @var string
*/
protected $filter;
/**
* Set this action's object
*
@ -49,6 +57,29 @@ class Action extends NavigationItem
return $this->object;
}
/**
* Set the filter to use when being asked whether to render this action
*
* @param string $filter
*
* @return $this
*/
public function setFilter($filter)
{
$this->filter = $filter;
return $this;
}
/**
* Return the filter to use when being asked whether to render this action
*
* @return string
*/
public function getFilter()
{
return $this->filter;
}
/**
* {@inheritdoc}
*/
@ -62,4 +93,17 @@ class Action extends NavigationItem
return $url;
}
/**
* {@inheritdoc}
*/
public function getRender()
{
if ($this->render === null) {
$filter = $this->getFilter();
$this->render = $filter ? $this->getObject()->matches(Filter::fromQueryString($filter)) : true;
}
return $this->render;
}
}