Skip to content

Commit

Permalink
Merge branch 'bugfix/url-anchors-not-working-9844'
Browse files Browse the repository at this point in the history
fixes #9844
  • Loading branch information
majentsch committed Sep 10, 2015
2 parents a4fec6f + a93481c commit c379b76
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
11 changes: 5 additions & 6 deletions public/js/icinga/behavior/actiontable.js
Expand Up @@ -261,10 +261,10 @@
*/
refresh: function() {
this.clear();
var hash = this.icinga.utils.parseUrl(window.location.href).hash;
var hash = icinga.history.getCol2State().replace(/^#!/, '');
if (this.hasMultiselection()) {
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
var self = this;
$.each(query, function(i, selection) {
Expand All @@ -275,7 +275,7 @@
return;
}
}
this.selectUrl(hash.substr(1));
this.selectUrl(hash);
}
};

Expand Down Expand Up @@ -348,13 +348,12 @@
}

// update history
var url = self.icinga.utils.parseUrl(window.location.href.split('#')[0]);
var state = icinga.history.getCol1State();
var count = table.selections().length;
var state = url.path + url.query;
if (count > 0) {
var query = table.toQuery();
self.icinga.loader.loadUrl(query, self.icinga.events.getLinkTargetFor($tr));
state += '#!' + query;
state += '#!' + query;
} else {
if (self.icinga.events.getLinkTargetFor($tr).attr('id') === 'col2') {
self.icinga.ui.layout1col();
Expand Down
73 changes: 71 additions & 2 deletions public/js/icinga/history.js
Expand Up @@ -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) {
// No history API, no action
if (!this.enabled) {
Expand All @@ -102,6 +107,13 @@
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) {
url = url.replace(/[\?&]?_(render|reload)=[a-z0-9]+/g, '');
if (this.lastPushUrl === url) {
Expand Down Expand Up @@ -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) {
var icinga = this.icinga,
main,
Expand All @@ -187,9 +207,13 @@
).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) {
// We are on the login page
Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion public/js/icinga/logger.js
Expand Up @@ -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) {
var ret = this.logLevels[level];
Expand Down

0 comments on commit c379b76

Please sign in to comment.