mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-27 06:29:42 -08:00
Add backward compatibility to old query format
This commit is contained in:
parent
5ac89fbc1f
commit
44377dc458
|
@ -777,10 +777,47 @@ function init() {
|
|||
url: PATH_PREFIX + "/static/js/graph_template.handlebar",
|
||||
success: function(data) {
|
||||
graphTemplate = Handlebars.compile(data);
|
||||
var Page = new Prometheus.Page();
|
||||
Page.init();
|
||||
if (isDeprecatedGraphURL()) {
|
||||
redirectToMigratedURL();
|
||||
} else {
|
||||
var Page = new Prometheus.Page();
|
||||
Page.init();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// These two methods (isDeprecatedGraphURL and redirectToMigratedURL)
|
||||
// are added only for backward compatibility to old query format.
|
||||
function isDeprecatedGraphURL() {
|
||||
if (window.location.hash.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var decodedFragment = decodeURIComponent(window.location.hash);
|
||||
try {
|
||||
JSON.parse(decodedFragment.substr(1)); // drop the hash #
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function redirectToMigratedURL() {
|
||||
var decodedFragment = decodeURIComponent(window.location.hash);
|
||||
var graphOptions = JSON.parse(decodedFragment.substr(1)); // drop the hash #
|
||||
var queryObject = {};
|
||||
|
||||
graphOptions.map(function(options, index){
|
||||
var prefix = "g" + index + ".";
|
||||
Object.keys(options).forEach(function(key) {
|
||||
queryObject[prefix + key] = options[key];
|
||||
});
|
||||
});
|
||||
var query = $.param(queryObject);
|
||||
window.location = "/graph?" + query;
|
||||
}
|
||||
|
||||
$(init);
|
||||
|
|
Loading…
Reference in a new issue