From 46c6201a217db553f8bd7f1752b6dd3dcae54d68 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 3 Jun 2020 15:47:10 +0200 Subject: [PATCH 1/6] Url: Add method `onlyWith()` --- library/Icinga/Web/Url.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index 441819ce3..db7172283 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -828,6 +828,32 @@ class Url return $url; } + /** + * Return a copy of this url with only the given parameter(s) + * + * The argument can be either a single query parameter name or + * an array of parameter names to keep on on the query + * + * @param string|array $keyOrArrayOfKeys + * + * @return static + */ + public function onlyWith($keyOrArrayOfKeys) + { + if (! is_array($keyOrArrayOfKeys)) { + $keyOrArrayOfKeys = [$keyOrArrayOfKeys]; + } + + $url = clone $this; + foreach ($url->getParams()->toArray(false) as $key => $_) { + if (! in_array($key, $keyOrArrayOfKeys, true)) { + $url->remove($key); + } + } + + return $url; + } + public function __clone() { $this->params = clone $this->params; From 60c3fd64063445bf1a7fd02e64d941589ff3913d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 3 Jun 2020 15:47:57 +0200 Subject: [PATCH 2/6] FilterEditor: Use a new url from request when redirecting searches Creating a new url has the benefit that all framework params are still there. `$this->url()` however returns a url that's already mangled and parameter preservation does not work for framework params. This is not quite the correct fix. But the entire parameter handling here is way too convoluted. --- library/Icinga/Web/Widget/FilterEditor.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/library/Icinga/Web/Widget/FilterEditor.php b/library/Icinga/Web/Widget/FilterEditor.php index b2fc563b9..89e1a0bbd 100644 --- a/library/Icinga/Web/Widget/FilterEditor.php +++ b/library/Icinga/Web/Widget/FilterEditor.php @@ -285,12 +285,10 @@ class FilterEditor extends AbstractWidget } } - $url = $this->url()->setQueryString( - $filter->toQueryString() - )->addParams($preserve); - if ($modify) { - $url->getParams()->add('modifyFilter'); - } + $url = Url::fromRequest()->onlyWith($this->preserveParams); + $urlParams = $url->getParams(); + $url->setQueryString($filter->toQueryString()); + $url->getParams()->mergeValues($urlParams->toArray(false)); $this->redirectNow($url); } From 6cf9f190481dced474922a797c5a63d598137149 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 3 Jun 2020 15:57:08 +0200 Subject: [PATCH 3/6] ActionController: Shift parameter `view` if its value is `compact` --- library/Icinga/Web/Controller/ActionController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index df6dce1a1..44ebbc512 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -129,7 +129,10 @@ class ActionController extends Zend_Controller_Action $this->_helper->layout()->showFullscreen = $request->getUrl()->shift('showFullscreen'); $this->_helper->layout()->moduleName = $moduleName; - $this->view->compact = $request->getParam('view') === 'compact'; + if ($request->getUrl()->getParam('view') === 'compact') { + $request->getUrl()->remove('view'); + $this->view->compact = true; + } if ($request->getUrl()->shift('showCompact')) { $this->view->compact = true; } From a240e306ede8573da1a79c2eeb5d47261cfeffa9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 3 Jun 2020 15:59:06 +0200 Subject: [PATCH 4/6] Preserve/Remove param `showCompact` instead of `view` --- library/Icinga/Web/Controller.php | 2 +- modules/monitoring/application/controllers/ListController.php | 2 +- .../monitoring/application/controllers/ServicesController.php | 2 +- .../monitoring/application/views/scripts/list/comments.phtml | 2 +- .../monitoring/application/views/scripts/list/contacts.phtml | 2 +- .../monitoring/application/views/scripts/list/downtimes.phtml | 2 +- .../monitoring/application/views/scripts/list/hostgroups.phtml | 2 +- modules/monitoring/application/views/scripts/list/hosts.phtml | 2 +- .../application/views/scripts/list/notifications.phtml | 2 +- .../application/views/scripts/list/servicegroups.phtml | 2 +- .../monitoring/application/views/scripts/list/services.phtml | 2 +- .../application/views/scripts/partials/event-history.phtml | 2 +- .../application/views/scripts/partials/show-more.phtml | 2 +- modules/monitoring/library/Monitoring/DataView/DataView.php | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/library/Icinga/Web/Controller.php b/library/Icinga/Web/Controller.php index 7409dfa7e..dba085a58 100644 --- a/library/Icinga/Web/Controller.php +++ b/library/Icinga/Web/Controller.php @@ -235,7 +235,7 @@ class Controller extends ModuleActionController 'sort', // setupSortControl() 'dir', // setupSortControl() 'backend', // Framework - 'view', // Framework + 'showCompact', // Framework '_dev' // Framework ); diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 1e6ce6db1..251a45506 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -355,7 +355,7 @@ class ListController extends Controller $this->view->form = $form; $this->params - ->remove('view') + ->remove('showCompact') ->remove('format'); $orientation = $this->params->shift('vertical', 0) ? 'vertical' : 'horizontal'; /* diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index 1d65de919..6c6559210 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -35,7 +35,7 @@ class ServicesController extends Controller $serviceList = new ServiceList($this->backend); $this->applyRestriction('monitoring/filter/objects', $serviceList); $serviceList->addFilter(Filter::fromQueryString( - (string) $this->params->without(array('service_problem', 'service_handled', 'view')) + (string) $this->params->without(array('service_problem', 'service_handled', 'showCompact')) )); $this->serviceList = $serviceList; $this->serviceList->setColumns(array( diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml index 4941922a9..4ea24dfd3 100644 --- a/modules/monitoring/application/views/scripts/list/comments.phtml +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -43,7 +43,7 @@