From efcd14ce0a461b9947ad6dfc2fbb4c15665163b0 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 25 Apr 2022 11:53:49 +0200 Subject: [PATCH] [WIP] Allow modules to register *framework* params I'm not yet convinced about this solution. The name *framework parameter* isn't always correct. (i.e. page) Then there's also an alternative available by using the `rel` attribute of anchors with a custom value. If it's set our JS preserves (or doesn't) the `_dashlet` param. It cannot do that for every url that's loaded into the same container. (e.g. stat badges in the footer of lists) --- library/Icinga/Application/Modules/Module.php | 29 +++++++++++++++++++ library/Icinga/Application/Web.php | 27 +++++++++++++++++ library/Icinga/Web/Controller.php | 10 ++++--- .../controllers/ListController.php | 1 - modules/monitoring/configuration.php | 2 ++ 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index f243e47c0..a4f5aec97 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -207,6 +207,9 @@ class Module */ protected $routes = array(); + /** @var string[] Framework parameters of this module */ + protected $frameworkParams = []; + /** * A set of menu elements * @@ -283,6 +286,18 @@ class Module $this->translationDomain = $name; } + /** + * Get this module's framework parameters + * + * @return string[] + */ + public function getFrameworkParams(): array + { + $this->launchConfigScript(); + + return $this->frameworkParams; + } + /** * Provide a search URL * @@ -1461,4 +1476,18 @@ class Module $this->routes[$name] = $route; return $this; } + + /** + * Register URL parameters which should be ignored by various URL handlers + * + * @param string ...$params + * + * @return $this + */ + protected function addFrameworkParams(string ...$params): self + { + $this->frameworkParams = array_merge($this->frameworkParams, $params); + + return $this; + } } diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 3cf6faeac..49bfc9f53 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -133,6 +133,33 @@ class Web extends EmbeddedWeb return array_combine($themes, $themes); } + /** + * Get default framework parameters and those of the current module + * + * @return string[] + */ + public function getFrameworkParams(): array + { + $defaultParams = [ + 'isIframe', + 'showFullscreen', + 'showCompact', + 'renderLayout', + '_disableLayout', + '_dashlet', + '_dev', + // TODO: is this really a "framework" param? or should the all be called differently, widgetyUrlFlags perhaps? + 'page' + ]; + + $moduleParams = []; + if (($moduleName = $this->getRequest()->getModuleName()) !== 'default') { + $moduleParams = $this->getModuleManager()->getModule($moduleName)->getFrameworkParams(); + } + + return array_merge($defaultParams, $moduleParams); + } + /** * Prepare routing * diff --git a/library/Icinga/Web/Controller.php b/library/Icinga/Web/Controller.php index a2730d5fc..90cff36b5 100644 --- a/library/Icinga/Web/Controller.php +++ b/library/Icinga/Web/Controller.php @@ -3,6 +3,7 @@ namespace Icinga\Web; +use Icinga\Application\Icinga; use Icinga\Data\Filterable; use Icinga\Data\Sortable; use Icinga\Data\QueryInterface; @@ -234,16 +235,17 @@ class Controller extends ModuleActionController 'limit', // setupPaginationControl() 'sort', // setupSortControl() 'dir', // setupSortControl() - 'backend', // Framework - 'showCompact', // Framework - '_dev' // Framework ); $editor = Widget::create('filterEditor'); /** @var \Icinga\Web\Widget\FilterEditor $editor */ call_user_func_array( array($editor, 'preserveParams'), - array_merge($defaultPreservedParams, $preserveParams ?: array()) + array_merge( + Icinga::app()->getFrameworkParams(), + $defaultPreservedParams, + $preserveParams ?: array() + ) ); $editor diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 397b68325..d44a61da8 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -729,7 +729,6 @@ class ListController extends Controller protected function filterQuery(DataView $dataView) { $this->setupFilterControl($dataView, null, null, array( - 'format', // handleFormatRequest() 'stateType', // hostsAction() and servicesAction() 'addColumns', // addColumns() 'problems', // servicegridAction() diff --git a/modules/monitoring/configuration.php b/modules/monitoring/configuration.php index 8415f889c..90df4febf 100644 --- a/modules/monitoring/configuration.php +++ b/modules/monitoring/configuration.php @@ -120,6 +120,8 @@ $this->provideSearchUrl($this->translate('Services'), 'monitoring/list/services? $this->provideSearchUrl($this->translate('Hostgroups'), 'monitoring/list/hostgroups?limit=10', 97); $this->provideSearchUrl($this->translate('Servicegroups'), 'monitoring/list/servicegroups?limit=10', 96); +$this->addFrameworkParams('backend', 'format'); + /* * Available navigation items */