|
|
|
|
@ -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") |
|
|
|
|
result := m.SearchResult{ |
|
|
|
|
Dashboards: []m.DashboardSearchHit{}, |
|
|
|
|
Tags: []m.DashboardTagCloudItem{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
query := m.SearchDashboardsQuery{Query: queryText, AccountId: c.GetAccountId()} |
|
|
|
|
err := bus.Dispatch(&query) |
|
|
|
|
if err != nil { |
|
|
|
|
c.JsonApiErr(500, "Search failed", err) |
|
|
|
|
return |
|
|
|
|
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) { |
|
|
|
|
|