|
@@ -10,6 +10,26 @@ import (
|
|
|
"github.com/torkelo/grafana-pro/pkg/setting"
|
|
"github.com/torkelo/grafana-pro/pkg/setting"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+// TODO: this needs to be cached or improved somehow
|
|
|
|
|
+func setIsStarredFlagOnSearchResults(c *middleware.Context, hits []*m.DashboardSearchHit) error {
|
|
|
|
|
+ if !c.IsSignedIn {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ query := m.GetUserStarsQuery{UserId: c.UserId}
|
|
|
|
|
+ if err := bus.Dispatch(&query); err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, dash := range hits {
|
|
|
|
|
+ if _, exists := query.Result[dash.Id]; exists {
|
|
|
|
|
+ dash.IsStarred = true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func Search(c *middleware.Context) {
|
|
func Search(c *middleware.Context) {
|
|
|
queryText := c.Query("q")
|
|
queryText := c.Query("q")
|
|
|
starred := c.Query("starred")
|
|
starred := c.Query("starred")
|
|
@@ -20,6 +40,7 @@ func Search(c *middleware.Context) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if strings.HasPrefix(queryText, "tags!:") {
|
|
if strings.HasPrefix(queryText, "tags!:") {
|
|
|
|
|
+
|
|
|
query := m.GetDashboardTagsQuery{AccountId: c.AccountId}
|
|
query := m.GetDashboardTagsQuery{AccountId: c.AccountId}
|
|
|
err := bus.Dispatch(&query)
|
|
err := bus.Dispatch(&query)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -28,7 +49,9 @@ func Search(c *middleware.Context) {
|
|
|
}
|
|
}
|
|
|
result.Tags = query.Result
|
|
result.Tags = query.Result
|
|
|
result.TagsOnly = true
|
|
result.TagsOnly = true
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+
|
|
|
searchQueryRegEx, _ := regexp.Compile(`(tags:(\w*)\sAND\s)?(?:title:)?(.*)?`)
|
|
searchQueryRegEx, _ := regexp.Compile(`(tags:(\w*)\sAND\s)?(?:title:)?(.*)?`)
|
|
|
matches := searchQueryRegEx.FindStringSubmatch(queryText)
|
|
matches := searchQueryRegEx.FindStringSubmatch(queryText)
|
|
|
query := m.SearchDashboardsQuery{
|
|
query := m.SearchDashboardsQuery{
|
|
@@ -38,12 +61,18 @@ func Search(c *middleware.Context) {
|
|
|
IsStarred: starred == "1",
|
|
IsStarred: starred == "1",
|
|
|
AccountId: c.AccountId,
|
|
AccountId: c.AccountId,
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
err := bus.Dispatch(&query)
|
|
err := bus.Dispatch(&query)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
c.JsonApiErr(500, "Search failed", err)
|
|
c.JsonApiErr(500, "Search failed", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if err := setIsStarredFlagOnSearchResults(c, query.Result); err != nil {
|
|
|
|
|
+ c.JsonApiErr(500, "Failed to get user stars", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
result.Dashboards = query.Result
|
|
result.Dashboards = query.Result
|
|
|
for _, dash := range result.Dashboards {
|
|
for _, dash := range result.Dashboards {
|
|
|
dash.Url = setting.AbsUrlTo("dashboard/db/" + dash.Slug)
|
|
dash.Url = setting.AbsUrlTo("dashboard/db/" + dash.Slug)
|