mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 10:17:05 +08:00
Dashboard search works better, tag cloud should be done soon
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user