From d8b14cb772a13f54f711cd39d535b8271df56fe5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Sat, 27 Feb 2016 15:51:13 +0100 Subject: [PATCH 1/5] Control whether a filter editor should be rendered via setVisible() We (may) have situations where a controller or view has to access the filter editor being created via Controller::setupFilterControl(). This is impossible if the view is compact because the filterEditor will be unset. This change introduces FilterEditor::setVisible() for giving the responsibility of rendering to the filter editor. Controller::setupFilterControl() will be adapted accordingly. refs #10778 --- library/Icinga/Web/Widget/FilterEditor.php | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/library/Icinga/Web/Widget/FilterEditor.php b/library/Icinga/Web/Widget/FilterEditor.php index d6f186fdd..f512ffe67 100644 --- a/library/Icinga/Web/Widget/FilterEditor.php +++ b/library/Icinga/Web/Widget/FilterEditor.php @@ -55,6 +55,13 @@ class FilterEditor extends AbstractWidget */ private $selectedIdx; + /** + * Whether the filter control is visible + * + * @var bool + */ + protected $visible = true; + /** * Create a new FilterWidget * @@ -144,6 +151,30 @@ class FilterEditor extends AbstractWidget return $this; } + /** + * Get whether the filter control is visible + * + * @return bool + */ + public function isVisible() + { + return $this->visible; + } + + /** + * Set whether the filter control is visible + * + * @param bool $visible + * + * @return $this + */ + public function setVisible($visible) + { + $this->visible = (bool) $visible; + + return $this; + } + protected function redirectNow($url) { $response = Icinga::app()->getFrontController()->getResponse(); @@ -731,6 +762,9 @@ class FilterEditor extends AbstractWidget public function render() { + if (! $this->visible) { + return ''; + } if (! $this->preservedUrl()->getParam('modifyFilter')) { return '
' . $this->renderSearch() . $this->view()->escape($this->shorten($this->filter, 50)) . '
'; } From 8433bf1fc157db0a2ed431fba28215957f4e8821 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Sat, 27 Feb 2016 15:57:00 +0100 Subject: [PATCH 2/5] Don't hide the filter editor from the view if the view is compact refs #10778 --- library/Icinga/Web/Controller.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/Controller.php b/library/Icinga/Web/Controller.php index b31b4fb61..f15e4913b 100644 --- a/library/Icinga/Web/Controller.php +++ b/library/Icinga/Web/Controller.php @@ -209,6 +209,7 @@ class Controller extends ModuleActionController ); $editor = Widget::create('filterEditor'); + /** @var \Icinga\Web\Widget\FilterEditor $editor */ call_user_func_array( array($editor, 'preserveParams'), array_merge($defaultPreservedParams, $preserveParams ?: array()) @@ -221,10 +222,12 @@ class Controller extends ModuleActionController ->setSearchColumns($searchColumns) ->handleRequest($this->getRequest()); - if (! $this->view->compact) { - $this->view->filterEditor = $editor; + if ($this->view->compact) { + $editor->setVisible(false); } + $this->view->filterEditor = $editor; + return $this; } } From f6e4b0aed03aca24f2c13fd1ae89752f0c33cd7f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Sat, 27 Feb 2016 16:22:44 +0100 Subject: [PATCH 3/5] Respect filter in state links in group overviews refs #10778 --- .../monitoring/application/views/scripts/list/hostgroups.phtml | 1 + .../application/views/scripts/list/servicegroups.phtml | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index e90b9fd7b..c39a80d33 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -50,6 +50,7 @@ if (! $this->compact): ?> $stateBadges = new StateBadges(); $stateBadges ->setUrl('monitoring/list/hosts') + ->setBaseFilter($this->filterEditor->getFilter()) ->add( StateBadges::STATE_UP, $hostgroup->hosts_up, diff --git a/modules/monitoring/application/views/scripts/list/servicegroups.phtml b/modules/monitoring/application/views/scripts/list/servicegroups.phtml index 398f2042f..6f39a90ff 100644 --- a/modules/monitoring/application/views/scripts/list/servicegroups.phtml +++ b/modules/monitoring/application/views/scripts/list/servicegroups.phtml @@ -43,6 +43,7 @@ if (! $this->compact): ?> $stateBadges = new StateBadges(); $stateBadges ->setUrl('monitoring/list/services') + ->setBaseFilter($this->filterEditor->getFilter()) ->add( StateBadges::STATE_OK, $serviceGroup->services_ok, From 5b0730574dc09546d700643a7c60820882e18398 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 16 Dec 2015 19:39:03 +0100 Subject: [PATCH 4/5] Simplify Url::addFilter() This changes the rendered resulting Url from x&(y&z) to x&y&z. refs #10778 --- library/Icinga/Web/Url.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index ac8e7af22..4f978370b 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -219,10 +219,9 @@ class Url public function addFilter($and) { $this->setQueryString( - Filter::matchAll( - $and, - Filter::fromQueryString($this->getQueryString()) - )->toQueryString() + Filter::fromQueryString($this->getQueryString()) + ->andFilter($and) + ->toQueryString() ); return $this; } From bf7d0825765a400e054ad028000f63254b9cb3f9 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Sat, 27 Feb 2016 16:25:04 +0100 Subject: [PATCH 5/5] Fix PHPDoc of Url::addFilter() --- library/Icinga/Web/Url.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index 4f978370b..b61fd990f 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -212,9 +212,11 @@ class Url } /** - * Set the new Filter of the url to be the current filter and the given filter + * Add the given filter to the current filter of the URL * - * @param Filter $and + * @param Filter $and + * + * @return $this */ public function addFilter($and) {