From bf4e492fa1c5b102a3cc97edb32d94d2097db1b8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 17 Sep 2015 11:00:40 +0200 Subject: [PATCH] Action: Accept and apply option "filter" refs #5600 --- .../Icinga/Web/Navigation/NavigationItem.php | 5 ++- .../Monitoring/Web/Navigation/Action.php | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Navigation/NavigationItem.php b/library/Icinga/Web/Navigation/NavigationItem.php index a72390e48..c1e8b46b0 100644 --- a/library/Icinga/Web/Navigation/NavigationItem.php +++ b/library/Icinga/Web/Navigation/NavigationItem.php @@ -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; } diff --git a/modules/monitoring/library/Monitoring/Web/Navigation/Action.php b/modules/monitoring/library/Monitoring/Web/Navigation/Action.php index 59de17c29..505229abb 100644 --- a/modules/monitoring/library/Monitoring/Web/Navigation/Action.php +++ b/modules/monitoring/library/Monitoring/Web/Navigation/Action.php @@ -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; + } }