Skip to content

Commit

Permalink
js: Always load redirects to their designated target
Browse files Browse the repository at this point in the history
The server applies the redirection magic now, but only
for compatibility reasons.

resolves #4881
  • Loading branch information
nilmerg committed Aug 11, 2023
1 parent 243192b commit 4a52a65
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
21 changes: 18 additions & 3 deletions library/Icinga/Web/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 5 additions & 10 deletions public/js/icinga/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4a52a65

Please sign in to comment.