Merge branch 'bugfix/url-anchors-not-working-9844'

fixes #9844
This commit is contained in:
Matthias Jentsch 2015-09-10 17:06:25 +02:00
commit c379b76cea
3 changed files with 77 additions and 9 deletions

View File

@ -261,10 +261,10 @@
*/ */
refresh: function() { refresh: function() {
this.clear(); this.clear();
var hash = this.icinga.utils.parseUrl(window.location.href).hash; var hash = icinga.history.getCol2State().replace(/^#!/, '');
if (this.hasMultiselection()) { if (this.hasMultiselection()) {
var query = parseSelectionQuery(hash); var query = parseSelectionQuery(hash);
if (query.length > 1 && this.getMultiselectionUrl() === this.icinga.utils.parseUrl(hash.substr(1)).path) { if (query.length > 1 && this.getMultiselectionUrl() === this.icinga.utils.parseUrl(hash).path) {
// select all rows with matching filters // select all rows with matching filters
var self = this; var self = this;
$.each(query, function(i, selection) { $.each(query, function(i, selection) {
@ -275,7 +275,7 @@
return; return;
} }
} }
this.selectUrl(hash.substr(1)); this.selectUrl(hash);
} }
}; };
@ -348,13 +348,12 @@
} }
// update history // update history
var url = self.icinga.utils.parseUrl(window.location.href.split('#')[0]); var state = icinga.history.getCol1State();
var count = table.selections().length; var count = table.selections().length;
var state = url.path + url.query;
if (count > 0) { if (count > 0) {
var query = table.toQuery(); var query = table.toQuery();
self.icinga.loader.loadUrl(query, self.icinga.events.getLinkTargetFor($tr)); self.icinga.loader.loadUrl(query, self.icinga.events.getLinkTargetFor($tr));
state += '#!' + query; state += '#!' + query;
} else { } else {
if (self.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') { if (self.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') {
self.icinga.ui.layout1col(); self.icinga.ui.layout1col();

View File

@ -94,6 +94,11 @@
} }
}, },
/**
* Push the given url as the new history state, unless the history is disabled
*
* @param {string} url The full url path, including anchor
*/
pushUrl: function (url) { pushUrl: function (url) {
// No history API, no action // No history API, no action
if (!this.enabled) { if (!this.enabled) {
@ -102,6 +107,13 @@
this.push(url); this.push(url);
}, },
/**
* Execute the history state, preserving the current state of behaviors
*
* Used internally by the history and should not be called externally, instead use {@link pushUrl}.
*
* @param {string} url
*/
push: function (url) { push: function (url) {
url = url.replace(/[\?&]?_(render|reload)=[a-z0-9]+/g, ''); url = url.replace(/[\?&]?_(render|reload)=[a-z0-9]+/g, '');
if (this.lastPushUrl === url) { if (this.lastPushUrl === url) {
@ -169,6 +181,14 @@
}); });
}, },
/**
* Update the application containers to match the current url
*
* Read the pane url from the current URL and load the corresponding panes into containers to
* match the current history state.
*
* @param {Boolean|Null} onload Set to true when the main pane should not be updated, defaults to false
*/
applyLocationBar: function (onload) { applyLocationBar: function (onload) {
var icinga = this.icinga, var icinga = this.icinga,
main, main,
@ -187,9 +207,13 @@
).addToHistory = false; ).addToHistory = false;
} }
if (document.location.hash && document.location.hash.match(/^#!/)) { if (this.getPaneAnchor(0)) {
$('#col1').data('icingaUrl', $('#col1').data('icingaUrl') + '#' + this.getPaneAnchor(0));
}
parts = document.location.hash.split(/#!/); var hash = this.getCol2State();
if (hash && hash.match(/^#!/)) {
parts = hash.split(/#!/);
if ($('#layout > #login').length) { if ($('#layout > #login').length) {
// We are on the login page // We are on the login page
@ -215,6 +239,51 @@
} }
}, },
/**
* Get the state of the selected pane
*
* @param col {int} The column index 0 or 1
*
* @returns {String} The string representing the state
*/
getPaneAnchor: function (col) {
if (col !== 1 && col !== 0) {
throw 'Trying to get anchor for non-existing column: ' + col;
}
var panes = document.location.toString().split('#!')[col];
return panes && panes.split('#')[1] || '';
},
/**
* Get the side pane state after (and including) the #!
*
* @returns {string} The pane url
*/
getCol2State: function () {
var hash = document.location.hash;
if (hash) {
if (hash.match(/^#[^!]/)) {
var hashs = hash.split('#');
hashs.shift();
hashs.shift();
hash = '#' + hashs.join('#');
}
}
return hash || '';
},
/**
* Return the main pane state fragment
*
* @returns {string} The main url including anchors, without #!
*/
getCol1State: function () {
var anchor = this.getPaneAnchor(0);
var hash = window.location.pathname + window.location.search +
(anchor.length ? ('#' + anchor) : '');
return hash || '';
},
/** /**
* Cleanup * Cleanup
*/ */

View File

@ -100,7 +100,7 @@
}, },
/** /**
* Return the numeric identifier fot a given log level * Return the numeric identifier for a given log level
*/ */
numericLevel: function (level) { numericLevel: function (level) {
var ret = this.logLevels[level]; var ret = this.logLevels[level];