Lots of work on search and dashboard loading, trying to generalize concepts and code, #960

This commit is contained in:
Torkel Ödegaard
2015-05-12 14:11:30 +02:00
parent a40299b4dc
commit b3be51f17f
15 changed files with 120 additions and 176 deletions
+20 -11
View File
@@ -17,11 +17,10 @@ type JsonDashIndex struct {
}
type JsonDashIndexItem struct {
Title string
TitleLower string
Tags []string
TagsCsv string
FilePath string
Path string
Dashboard *m.Dashboard
}
func NewJsonDashIndex(path string, orgIds string) *JsonDashIndex {
@@ -40,9 +39,9 @@ func (index *JsonDashIndex) Search(query *Query) ([]*m.DashboardSearchHit, error
for _, item := range index.items {
if strings.Contains(item.TitleLower, query.Title) {
results = append(results, &m.DashboardSearchHit{
Title: item.Title,
Tags: item.Tags,
Slug: item.FilePath,
Title: item.Dashboard.Title,
Tags: item.Dashboard.GetTags(),
Uri: "file/" + item.Path,
})
}
}
@@ -50,6 +49,16 @@ func (index *JsonDashIndex) Search(query *Query) ([]*m.DashboardSearchHit, error
return results, nil
}
func (index *JsonDashIndex) GetDashboard(path string) *m.Dashboard {
for _, item := range index.items {
if item.Path == path {
return item.Dashboard
}
}
return nil
}
func (index *JsonDashIndex) updateIndex() error {
log.Info("Updating JSON dashboard index, path: %v", index.path)
@@ -102,13 +111,13 @@ func loadDashboardFromFile(filename string) (*JsonDashIndexItem, error) {
return nil, err
}
dash := m.NewDashboardFromJson(data)
stat, _ := os.Stat(filename)
item := &JsonDashIndexItem{}
item.Title = dash.Title
item.TitleLower = strings.ToLower(item.Title)
item.Tags = dash.GetTags()
item.TagsCsv = strings.Join(item.Tags, ",")
item.Dashboard = m.NewDashboardFromJson(data)
item.TitleLower = strings.ToLower(item.Dashboard.Title)
item.TagsCsv = strings.Join(item.Dashboard.GetTags(), ",")
item.Path = stat.Name()
return item, nil
}
+7
View File
@@ -87,3 +87,10 @@ func setIsStarredFlagOnSearchResults(userId int64, hits []*m.DashboardSearchHit)
return nil
}
func GetDashboardFromJsonIndex(filename string) *m.Dashboard {
if jsonDashIndex == nil {
return nil
}
return jsonDashIndex.GetDashboard(filename)
}
+1 -1
View File
@@ -175,7 +175,7 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error {
hit = &m.DashboardSearchHit{
Id: item.Id,
Title: item.Title,
Slug: item.Slug,
Uri: "db/" + item.Slug,
Tags: []string{},
}
query.Result = append(query.Result, hit)