mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
Use query parameters in the url
This commit is contained in:
parent
3da825fc76
commit
3e18d86d8a
|
@ -627,13 +627,40 @@ Prometheus.Graph.prototype.remove = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
function parseGraphOptionsFromURL() {
|
function parseGraphOptionsFromURL() {
|
||||||
var hashOptions = window.location.hash.slice(1);
|
var allGraphsOptions = [];
|
||||||
if (!hashOptions) {
|
var queryStringBeginning = window.location.href.indexOf('?')
|
||||||
return [];
|
if(queryStringBeginning == -1) {
|
||||||
|
return allGraphsOptions;
|
||||||
}
|
}
|
||||||
var optionsJSON = decodeURIComponent(window.location.hash.slice(1));
|
var paramTuples = window.location.href.slice(queryStringBeginning + 1).split('&');
|
||||||
options = JSON.parse(optionsJSON);
|
|
||||||
return options;
|
paramTuples.forEach(function(tuple){
|
||||||
|
var paramNameAndValue = tuple.split('=');
|
||||||
|
var paramName = paramNameAndValue[0]
|
||||||
|
var paramValue = decodeURIComponent(paramNameAndValue[1])
|
||||||
|
|
||||||
|
var indexAndName = paramName.split('.');
|
||||||
|
var optionName = indexAndName[1];
|
||||||
|
|
||||||
|
if(optionName == "end_input"){
|
||||||
|
paramValue = paramValue.replace("+", " ") // workaround jquery.param space plus
|
||||||
|
}
|
||||||
|
|
||||||
|
if(optionName == "tab"){
|
||||||
|
paramValue = parseInt(paramValue) // tab is int
|
||||||
|
}
|
||||||
|
|
||||||
|
var indexStr = indexAndName[0].substring(1);
|
||||||
|
if(isNaN(indexStr) == false) {
|
||||||
|
var index = parseInt(indexStr);
|
||||||
|
if(typeof allGraphsOptions[index] === 'undefined') {
|
||||||
|
allGraphsOptions[index] = {};
|
||||||
|
}
|
||||||
|
allGraphsOptions[index][optionName] = paramValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return allGraphsOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: This needs to be kept in sync with /util/strutil/strconv.go:GraphLinkForExpression
|
// NOTE: This needs to be kept in sync with /util/strutil/strconv.go:GraphLinkForExpression
|
||||||
|
@ -642,8 +669,19 @@ function storeGraphOptionsInURL() {
|
||||||
for (var i = 0; i < graphs.length; i++) {
|
for (var i = 0; i < graphs.length; i++) {
|
||||||
allGraphsOptions.push(graphs[i].getOptions());
|
allGraphsOptions.push(graphs[i].getOptions());
|
||||||
}
|
}
|
||||||
var optionsJSON = JSON.stringify(allGraphsOptions);
|
|
||||||
window.location.hash = encodeURIComponent(optionsJSON);
|
var queryString = generateQueryString(allGraphsOptions);
|
||||||
|
history.pushState({}, "", "graph?" + queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateQueryString(allGraphsOptions) {
|
||||||
|
return allGraphsOptions.map(function(graphsOptions, index){
|
||||||
|
var queryObject = {}
|
||||||
|
Object.keys(graphsOptions).map(function(key){
|
||||||
|
queryObject["g" + index + "." + key] = graphsOptions[key];
|
||||||
|
});
|
||||||
|
return $.param(queryObject)
|
||||||
|
}).join("&");
|
||||||
}
|
}
|
||||||
|
|
||||||
function addGraph(options) {
|
function addGraph(options) {
|
||||||
|
|
Loading…
Reference in a new issue