Commit bcdbec61 by Torkel Ödegaard

Dashboard search works better, tag cloud should be done soon

parent 3f266a3e
......@@ -24,3 +24,13 @@ npm install
npm install -g grunt-cli
grunt
```
To rebuild on source change:
```
go get github.com/Unknwon/bra
bra run
```
Subproject commit a5c8bbfe1f04830507d981dff5a44248ffeab04c
Subproject commit d03949a735fd6ee486e278feb3b87f252be5ce96
package api
import (
"strings"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models"
......@@ -46,15 +48,32 @@ func DeleteDashboard(c *middleware.Context) {
func Search(c *middleware.Context) {
queryText := c.Query("q")
result := m.SearchResult{
Dashboards: []m.DashboardSearchHit{},
Tags: []m.DashboardTagCloudItem{},
}
if strings.HasPrefix(queryText, "tags!:") {
query := m.GetDashboardTagsQuery{}
err := bus.Dispatch(&query)
if err != nil {
c.JsonApiErr(500, "Failed to get tags from database", err)
return
}
result.Tags = query.Result
result.TagsOnly = true
} else {
queryText := strings.TrimPrefix(queryText, "title:")
query := m.SearchDashboardsQuery{Query: queryText, AccountId: c.GetAccountId()}
err := bus.Dispatch(&query)
if err != nil {
c.JsonApiErr(500, "Search failed", err)
return
}
result.Dashboards = query.Result
}
c.JSON(200, query.Result)
c.JSON(200, result)
}
func PostDashboard(c *middleware.Context) {
......
......@@ -27,16 +27,33 @@ type Dashboard struct {
}
type SearchResult struct {
Dashboards []DashboardSearchHit `json:"dashboards"`
Tags []DashboardTagCloudItem `json:"tags"`
TagsOnly bool `json:"tagsOnly"`
}
type DashboardSearchHit struct {
Id string `json:"id"`
Title string `json:"title"`
Slug string `json:"slug"`
Tags []string `json:"tags"`
}
type DashboardTagCloudItem struct {
Term string `json:"term"`
Count int `json:"count"`
}
type SearchDashboardsQuery struct {
Query string
AccountId int64
Result []*SearchResult
Result []DashboardSearchHit
}
type GetDashboardTagsQuery struct {
AccountId int64
Result []DashboardTagCloudItem
}
type SaveDashboardCommand struct {
......
......@@ -11,6 +11,7 @@ func init() {
bus.AddHandler("sql", GetDashboard)
bus.AddHandler("sql", DeleteDashboard)
bus.AddHandler("sql", SearchDashboards)
bus.AddHandler("sql", GetDashboardTags)
}
func SaveDashboard(cmd *m.SaveDashboardCommand) error {
......@@ -55,17 +56,25 @@ func GetDashboard(query *m.GetDashboardQuery) error {
}
func SearchDashboards(query *m.SearchDashboardsQuery) error {
titleMatch := "%" + query.Query + "%"
titleQuery := "%" + query.Query + "%"
sess := x.Limit(100, 0).Where("account_id=? AND title LIKE ?", query.AccountId, titleMatch)
sess := x.Limit(100, 0).Where("account_id=? AND title LIKE ?", query.AccountId, titleQuery)
sess.Table("Dashboard")
query.Result = make([]*m.SearchResult, 0)
query.Result = make([]m.DashboardSearchHit, 0)
err := sess.Find(&query.Result)
return err
}
func GetDashboardTags(query *m.GetDashboardTagsQuery) error {
query.Result = []m.DashboardTagCloudItem{
m.DashboardTagCloudItem{Term: "test", Count: 10},
m.DashboardTagCloudItem{Term: "prod", Count: 20},
}
return nil
}
func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
sess := x.NewSession()
defer sess.Close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment