From 4a52a653e418f85fb585d1ed5e0122f941fed06a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 20 Jul 2023 16:04:07 +0200 Subject: [PATCH] js: Always load redirects to their designated target The server applies the redirection magic now, but only for compatibility reasons. resolves #4881 --- library/Icinga/Web/Response.php | 21 ++++++++++++++++++--- public/js/icinga/loader.js | 15 +++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/library/Icinga/Web/Response.php b/library/Icinga/Web/Response.php index df0b842d54..7772b3d6d9 100644 --- a/library/Icinga/Web/Response.php +++ b/library/Icinga/Web/Response.php @@ -315,14 +315,29 @@ public function json() */ protected function prepare() { + $request = $this->getRequest(); $redirectUrl = $this->getRedirectUrl(); - if ($this->getRequest()->isXmlHttpRequest()) { + if ($request->isXmlHttpRequest()) { if ($redirectUrl !== null) { - if ($this->getRequest()->isGet() && Icinga::app()->getViewRenderer()->view->compact) { + if ($request->isGet() && Icinga::app()->getViewRenderer()->view->compact) { $redirectUrl->getParams()->set('showCompact', true); } - $this->setHeader('X-Icinga-Redirect', rawurlencode($redirectUrl->getAbsoluteUrl()), true); + $encodedRedirectUrl = rawurlencode($redirectUrl->getAbsoluteUrl()); + + // TODO: Compatibility only. Remove once v2.14 is out. + $targetId = $request->getHeader('X-Icinga-Container'); + if ($request->isPost() && $targetId === 'col2' && $request->getHeader('X-Icinga-Col2-State')) { + $col1State = Url::fromPath($request->getHeader('X-Icinga-Col1-State')); + $col2State = Url::fromPath($request->getHeader('X-Icinga-Col2-State')); + if ($col2State->getPath() !== $redirectUrl->getPath() + && $col1State->getPath() === $redirectUrl->getPath() + ) { + $encodedRedirectUrl = '__CLOSE__'; + } + } + + $this->setHeader('X-Icinga-Redirect', $encodedRedirectUrl, true); if ($this->getRerenderLayout()) { $this->setHeader('X-Icinga-Rerender-Layout', 'yes', true); } diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index c86736df29..018bc5dc4a 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -294,6 +294,11 @@ headers['X-Icinga-Autorefresh'] = '1'; } + if ($target.is('#col2')) { + headers['X-Icinga-Col1-State'] = this.icinga.history.getCol1State(); + headers['X-Icinga-Col2-State'] = this.icinga.history.getCol2State().replace(/^#!/, ''); + } + // Ask for a new window id in case we don't already have one if (this.icinga.ui.hasWindowId()) { var windowId = this.icinga.ui.getWindowId(); @@ -677,16 +682,6 @@ this.loadUrl(parts.shift(), $('#col1')); this.loadUrl(parts.shift(), $('#col2')); } else { - if ($target.attr('id') === 'col2') { // TODO: multicol - if (($target.data('icingaUrl') || '').split('?')[0] === url.split('?')[0]) { - // Don't do anything in this case - } else if ($('#col1').data('icingaUrl').split('?')[0] === url.split('?')[0]) { - icinga.ui.layout1col(); - $target = $('#col1'); - delete(this.requests['col2']); - } - } - var req = this.loadUrl(url, $target); req.forceFocus = url === origin ? forceFocus : null; req.autoRefreshInterval = autoRefreshInterval;