Lots of work on search and dashboard loading, trying to generalize concepts and code, #960
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user