Commit 1a9f6307 by Torkel Ödegaard

Began work on adding json files to search, #960

parent 48ddd721
......@@ -212,3 +212,11 @@ max_days = 7
enabled = false
rabbitmq_url = amqp://localhost/
exchange = grafana_events
#################################### Dashboard JSON files ##########################
[dashboards.json]
enabled = false
path = dashboards
orgs = *
......@@ -15,6 +15,7 @@ import (
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social"
......@@ -51,6 +52,7 @@ func main() {
initRuntime()
writePIDFile()
search.Init()
social.NewOAuthService()
eventpublisher.Init()
plugins.Init()
......
......@@ -4,28 +4,9 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
)
// 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) {
query := c.Query("query")
tag := c.Query("tag")
......@@ -54,7 +35,7 @@ func Search(c *middleware.Context) {
result.TagsOnly = true
} else {
query := m.SearchDashboardsQuery{
query := search.Query{
Title: query,
Tag: tag,
UserId: c.UserId,
......@@ -69,11 +50,6 @@ func Search(c *middleware.Context) {
return
}
if err := setIsStarredFlagOnSearchResults(c, query.Result); err != nil {
c.JsonApiErr(500, "Failed to get user stars", err)
return
}
result.Dashboards = query.Result
}
......
package search
var (
// settings
DashboardsJsonEnabled bool
DashboardsJsonPath string
DashboardJsonOrgs string
)
func initJsonFileIndex() {
}
package search
import (
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
type Query struct {
Title string
Tag string
OrgId int64
UserId int64
Limit int
IsStarred bool
Result []*m.DashboardSearchHit
}
func Init() {
bus.AddHandler("search", searchHandler)
initJsonFileIndex()
}
func searchHandler(query *Query) error {
dashQuery := m.SearchDashboardsQuery{
Title: query.Title,
Tag: query.Tag,
UserId: query.UserId,
Limit: query.Limit,
IsStarred: query.IsStarred,
OrgId: query.OrgId,
}
if err := bus.Dispatch(&dashQuery); err != nil {
return err
}
if err := setIsStarredFlagOnSearchResults(query.UserId, query.Result); err != nil {
return err
}
query.Result = dashQuery.Result
return nil
}
func setIsStarredFlagOnSearchResults(userId int64, hits []*m.DashboardSearchHit) error {
query := m.GetUserStarsQuery{UserId: 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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment