mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-14 07:17:52 -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",
|
url: PATH_PREFIX + "/static/js/graph_template.handlebar",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
graphTemplate = Handlebars.compile(data);
|
graphTemplate = Handlebars.compile(data);
|
||||||
|
if (isDeprecatedGraphURL()) {
|
||||||
|
redirectToMigratedURL();
|
||||||
|
} else {
|
||||||
var Page = new Prometheus.Page();
|
var Page = new Prometheus.Page();
|
||||||
Page.init();
|
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);
|
$(init);
|
||||||
|
|
Loading…
Reference in a new issue