JS: Introduce Icinga.History.getCurrentState()

Before, Icinga.History.pushCurrentState() had this functionality
enclosed. Now it is usable from other functions as well.
This commit is contained in:
Eric Lippmann 2020-01-15 09:55:39 +01:00
parent db69f23c20
commit 97006973d8
1 changed files with 32 additions and 14 deletions

View File

@ -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);
}
},