From 97006973d8cf3c0bef00bfb0c343bc9d0828d854 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 15 Jan 2020 09:55:39 +0100 Subject: [PATCH] JS: Introduce Icinga.History.getCurrentState() Before, Icinga.History.pushCurrentState() had this functionality enclosed. Now it is usable from other functions as well. --- public/js/icinga/history.js | 46 ++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/public/js/icinga/history.js b/public/js/icinga/history.js index 7d2173f57..0e17c46a3 100644 --- a/public/js/icinga/history.js +++ b/public/js/icinga/history.js @@ -52,18 +52,17 @@ }, /** - * Detect active URLs and push combined URL to history + * Get the current state (url and title) as object * - * TODO: How should we handle POST requests? e.g. search VS login + * @returns {object} */ - pushCurrentState: function () { - // No history API, no action + getCurrentState: function () { if (! this.enabled) { - return; + return null; } - var url = ''; - var title = ''; + var title = null; + var url = null; // We only store URLs of containers sitting directly under #main: $('#main > .container').each(function (idx, container) { @@ -74,7 +73,7 @@ // TODO: I'd prefer to have the rightmost URL first if ('undefined' !== typeof cUrl) { // TODO: solve this on server side cUrl = icinga.utils.removeUrlParams(cUrl, blacklist); - if (url === '') { + if (! url) { url = cUrl; } else { url = url + '#!' + cUrl; @@ -86,13 +85,32 @@ } }); - // Did we find any URL? Then push it! - if (url !== '') { - this.icinga.logger.debug('Pushing current state to history'); - this.push(url); + return { + title: title, + url: url, + }; + }, + + /** + * Detect active URLs and push combined URL to history + * + * TODO: How should we handle POST requests? e.g. search VS login + */ + pushCurrentState: function () { + // No history API, no action + if (! this.enabled) { + return; } - if (title !== '') { - this.icinga.ui.setTitle(title); + + var state = this.getCurrentState(); + + // Did we find any URL? Then push it! + if (state.url) { + this.icinga.logger.debug('Pushing current state to history'); + this.push(state.url); + } + if (state.title) { + this.icinga.ui.setTitle(state.title); } },