From: Sebastian Harl Date: Thu, 14 May 2015 16:56:40 +0000 (+0200) Subject: graphs: Determine GroupBy attributes automatically and use check boxes. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=cf82a7487892a8f7e817f1386e6e93b40bb21d87;p=sysdb%2Fwebui.git graphs: Determine GroupBy attributes automatically and use check boxes. --- 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 @@

Graphs

- - -
- +

+{{if .Attributes}} +

Group by: + {{range $a, $v := .Attributes}} + {{$a}} + {{end}} +

+{{end}}

{{if .Metrics}}