diff --git a/README.md b/README.md index 79c912a3b57..45ed8274f43 100644 --- a/README.md +++ b/README.md @@ -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 +``` + + + diff --git a/grafana b/grafana index a5c8bbfe1f0..d03949a735f 160000 --- a/grafana +++ b/grafana @@ -1 +1 @@ -Subproject commit a5c8bbfe1f04830507d981dff5a44248ffeab04c +Subproject commit d03949a735fd6ee486e278feb3b87f252be5ce96 diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 45f3fb3e951..329779e1867 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -1,6 +1,8 @@ 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") - - query := m.SearchDashboardsQuery{Query: queryText, AccountId: c.GetAccountId()} - err := bus.Dispatch(&query) - if err != nil { - c.JsonApiErr(500, "Search failed", err) - return + result := m.SearchResult{ + Dashboards: []m.DashboardSearchHit{}, + Tags: []m.DashboardTagCloudItem{}, } - c.JSON(200, query.Result) + 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, result) } func PostDashboard(c *middleware.Context) { diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index f03a300f0dc..ab7ffb50e5d 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -27,16 +27,33 @@ type Dashboard struct { } type SearchResult struct { - Id string `json:"id"` - Title string `json:"title"` - Slug string `json:"slug"` + 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 { diff --git a/pkg/stores/sqlstore/dashboards.go b/pkg/stores/sqlstore/dashboards.go index 281690e8474..f3c64c56f01 100644 --- a/pkg/stores/sqlstore/dashboards.go +++ b/pkg/stores/sqlstore/dashboards.go @@ -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()