Fix regression from 5e8d57bec1

0 is a false value, so shortcutting no longer works.
Update other places in the code that assumed graph was the default.
This commit is contained in:
Brian Brazil 2014-12-26 16:40:06 +00:00
parent 48d6ba2505
commit ffa2e73803
4 changed files with 8 additions and 6 deletions

View file

@ -159,6 +159,6 @@ func TableLinkForExpression(expr string) string {
// GraphLinkForExpression creates an escaped relative link to the graph view of // GraphLinkForExpression creates an escaped relative link to the graph view of
// the provided expression. // the provided expression.
func GraphLinkForExpression(expr string) string { func GraphLinkForExpression(expr string) string {
urlData := url.QueryEscape(fmt.Sprintf(`[{"expr":%q}]`, expr)) urlData := url.QueryEscape(fmt.Sprintf(`[{"expr":%q,"tab":0}]`, expr))
return fmt.Sprintf("/graph#%s", strings.Replace(urlData, "+", "%20", -1)) return fmt.Sprintf("/graph#%s", strings.Replace(urlData, "+", "%20", -1))
} }

View file

@ -135,7 +135,7 @@ func TestTemplateExpansion(t *testing.T) {
{ {
// graphLink. // graphLink.
text: "{{ graphLink \"up\" }}", text: "{{ graphLink \"up\" }}",
output: "/graph#%5B%7B%22expr%22%3A%22up%22%7D%5D", output: "/graph#%5B%7B%22expr%22%3A%22up%22%2C%22tab%22%3A0%7D%5D",
}, },
{ {
// tableLink. // tableLink.

View file

@ -58,7 +58,9 @@ Prometheus.Graph.prototype.initialize = function() {
self.options["id"] = self.id; self.options["id"] = self.id;
self.options["range_input"] = self.options["range_input"] || "1h"; self.options["range_input"] = self.options["range_input"] || "1h";
self.options["stacked_checked"] = self.options["stacked"] ? "checked" : ""; self.options["stacked_checked"] = self.options["stacked"] ? "checked" : "";
self.options["tab"] = self.options["tab"] || 1; if (self.options["tab"] === undefined) {
self.options["tab"] = 1;
}
// Draw graph controls and container from Handlebars template. // Draw graph controls and container from Handlebars template.
@ -78,13 +80,13 @@ Prometheus.Graph.prototype.initialize = function() {
self.consoleTab = graphWrapper.find(".console"); self.consoleTab = graphWrapper.find(".console");
self.graphTab = graphWrapper.find(".graph_container"); self.graphTab = graphWrapper.find(".graph_container");
self.tabs = graphWrapper.find(".tabs"); self.tabs = graphWrapper.find(".tabs");
self.tab = $(self.tabs.find("> div")[self.options["tab"]]); // active tab self.tab = $(self.tabs.find("> div")[self.options["tab"]]); // active tab
self.tabs.tabs({ self.tabs.tabs({
active: self.options["tab"], active: self.options["tab"],
activate: function(e, ui) { activate: function(e, ui) {
storeGraphOptionsInUrl(); storeGraphOptionsInUrl();
self.tab = ui.newPanel self.tab = ui.newPanel;
if (self.tab.hasClass("reload")) { // reload if flagged with class "reload" if (self.tab.hasClass("reload")) { // reload if flagged with class "reload"
self.submitQuery(); self.submitQuery();
} }

View file

@ -577,7 +577,7 @@ PromConsole._chooseNameFunction = function(data) {
PromConsole._graphsToSlashGraphURL = function(exprs) { PromConsole._graphsToSlashGraphURL = function(exprs) {
var data = []; var data = [];
for (var i = 0; i < exprs.length; ++i) { for (var i = 0; i < exprs.length; ++i) {
data.push({'expr' : exprs[i]}); data.push({'expr': exprs[i], 'tab': 0});
} }
return '/graph#' + encodeURIComponent(JSON.stringify(data)); return '/graph#' + encodeURIComponent(JSON.stringify(data));