Dashboard search works better, tag cloud should be done soon

This commit is contained in:
Torkel Ödegaard
2015-01-06 18:39:26 +01:00
parent 3f266a3e1b
commit bcdbec61d7
5 changed files with 70 additions and 15 deletions

View File

@ -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) {