Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js: Don't refresh twice upon __BACK__ #5125

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions public/js/icinga/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@
var originUrl = req.$target.data('icingaUrl');

$(window).on('popstate.__back__', { self: this }, function (event) {
var _this = event.data.self;
var $refreshTarget = $('#col2');
var refreshUrl;
const _this = event.data.self;
let $refreshTarget = $('#col2');
let refreshUrl;

var hash = icinga.history.getCol2State();
const hash = icinga.history.getCol2State();
if (hash && hash.match(/^#!/)) {
// TODO: These three lines are copied from history.js, I don't like this
var parts = hash.split(/#!/);
Expand All @@ -546,22 +546,10 @@
$refreshTarget = $('#col1');
}

// loadUrl won't run this request, as due to the history handling it's already running.
// The important bit though is that it returns this (already running) request. This way
// it's possible to set `scripted = true` on the request. (`addToHistory = true` should
// already be the case, though it's added again just in case it's not already `true`..)
var req = _this.loadUrl(refreshUrl, $refreshTarget);
req.addToHistory = false;
req.scripted = true;

setTimeout(function () {
// TODO: Find a better solution than a hardcoded one
// This is still the *cheat* to get live results
// (in case there's a delay and a change is not instantly effective)
var req = _this.loadUrl(refreshUrl, $refreshTarget);
req.addToHistory = false;
req.scripted = true;
}, 1000);
const refreshReq = _this.loadUrl(refreshUrl, $refreshTarget);
refreshReq.autoRefreshInterval = req.getResponseHeader('X-Icinga-Refresh');
refreshReq.autorefresh = true;
refreshReq.scripted = true;

$(window).off('popstate.__back__');
});
Expand Down