From cf82a7487892a8f7e817f1386e6e93b40bb21d87 Mon Sep 17 00:00:00 2001
From: Sebastian Harl
Date: Thu, 14 May 2015 18:56:40 +0200
Subject: [PATCH] graphs: Determine GroupBy attributes automatically and use
check boxes.
---
server/query.go | 27 +++++++++++++++++++++++----
templates/graphs.tmpl | 14 +++++++++-----
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/server/query.go b/server/query.go
index 22385bf..ad645bd 100644
--- a/server/query.go
+++ b/server/query.go
@@ -133,16 +133,35 @@ func graphs(req request, s *Server) (*page, error) {
p := struct {
Query, Metrics string
QueryOptions string
- GroupBy string
+ GroupBy []string
+ Attributes map[string]bool
}{
Query: req.r.PostForm.Get("metrics-query"),
- GroupBy: req.r.PostForm.Get("group-by"),
+ GroupBy: req.r.PostForm["group-by"],
}
if req.r.Method == "POST" {
p.Metrics = p.Query
- if p.GroupBy != "" {
- p.QueryOptions += "/g=" + strings.Join(strings.Fields(p.GroupBy), ",")
+ if len(p.GroupBy) > 0 {
+ p.QueryOptions += "/g=" + strings.Join(p.GroupBy, ",")
+ }
+
+ metrics, err := s.queryMetrics(p.Query)
+ if err != nil {
+ return nil, err
+ }
+ p.Attributes = make(map[string]bool)
+ for _, m := range metrics {
+ for a := range m.Attributes {
+ var checked bool
+ for _, g := range p.GroupBy {
+ if a == g {
+ checked = true
+ break
+ }
+ }
+ p.Attributes[a] = checked
+ }
}
}
return tmpl(s.results["graphs"], &p)
diff --git a/templates/graphs.tmpl b/templates/graphs.tmpl
index 10cd238..5c8b490 100644
--- a/templates/graphs.tmpl
+++ b/templates/graphs.tmpl
@@ -1,12 +1,16 @@
+{{if .Attributes}}
+ Group by:
+ {{range $a, $v := .Attributes}}
+ {{$a}}
+ {{end}}
+
+{{end}}
{{if .Metrics}}
--
2.30.2