mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard search works better, tag cloud should be done soon
This commit is contained in:
parent
3f266a3e1b
commit
bcdbec61d7
10
README.md
10
README.md
@ -24,3 +24,13 @@ npm install
|
|||||||
npm install -g grunt-cli
|
npm install -g grunt-cli
|
||||||
grunt
|
grunt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To rebuild on source change:
|
||||||
|
```
|
||||||
|
go get github.com/Unknwon/bra
|
||||||
|
|
||||||
|
bra run
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
2
grafana
2
grafana
@ -1 +1 @@
|
|||||||
Subproject commit a5c8bbfe1f04830507d981dff5a44248ffeab04c
|
Subproject commit d03949a735fd6ee486e278feb3b87f252be5ce96
|
@ -1,6 +1,8 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||||
@ -46,15 +48,32 @@ func DeleteDashboard(c *middleware.Context) {
|
|||||||
|
|
||||||
func Search(c *middleware.Context) {
|
func Search(c *middleware.Context) {
|
||||||
queryText := c.Query("q")
|
queryText := c.Query("q")
|
||||||
|
result := m.SearchResult{
|
||||||
query := m.SearchDashboardsQuery{Query: queryText, AccountId: c.GetAccountId()}
|
Dashboards: []m.DashboardSearchHit{},
|
||||||
err := bus.Dispatch(&query)
|
Tags: []m.DashboardTagCloudItem{},
|
||||||
if err != nil {
|
|
||||||
c.JsonApiErr(500, "Search failed", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, query.Result)
|
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, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostDashboard(c *middleware.Context) {
|
func PostDashboard(c *middleware.Context) {
|
||||||
|
@ -27,16 +27,33 @@ type Dashboard struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SearchResult struct {
|
type SearchResult struct {
|
||||||
Id string `json:"id"`
|
Dashboards []DashboardSearchHit `json:"dashboards"`
|
||||||
Title string `json:"title"`
|
Tags []DashboardTagCloudItem `json:"tags"`
|
||||||
Slug string `json:"slug"`
|
TagsOnly bool `json:"tagsOnly"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DashboardSearchHit struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DashboardTagCloudItem struct {
|
||||||
|
Term string `json:"term"`
|
||||||
|
Count int `json:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SearchDashboardsQuery struct {
|
type SearchDashboardsQuery struct {
|
||||||
Query string
|
Query string
|
||||||
AccountId int64
|
AccountId int64
|
||||||
|
|
||||||
Result []*SearchResult
|
Result []DashboardSearchHit
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDashboardTagsQuery struct {
|
||||||
|
AccountId int64
|
||||||
|
Result []DashboardTagCloudItem
|
||||||
}
|
}
|
||||||
|
|
||||||
type SaveDashboardCommand struct {
|
type SaveDashboardCommand struct {
|
||||||
|
@ -11,6 +11,7 @@ func init() {
|
|||||||
bus.AddHandler("sql", GetDashboard)
|
bus.AddHandler("sql", GetDashboard)
|
||||||
bus.AddHandler("sql", DeleteDashboard)
|
bus.AddHandler("sql", DeleteDashboard)
|
||||||
bus.AddHandler("sql", SearchDashboards)
|
bus.AddHandler("sql", SearchDashboards)
|
||||||
|
bus.AddHandler("sql", GetDashboardTags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SaveDashboard(cmd *m.SaveDashboardCommand) error {
|
func SaveDashboard(cmd *m.SaveDashboardCommand) error {
|
||||||
@ -55,17 +56,25 @@ func GetDashboard(query *m.GetDashboardQuery) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SearchDashboards(query *m.SearchDashboardsQuery) error {
|
func SearchDashboards(query *m.SearchDashboardsQuery) error {
|
||||||
titleMatch := "%" + query.Query + "%"
|
titleQuery := "%" + query.Query + "%"
|
||||||
|
|
||||||
sess := x.Limit(100, 0).Where("account_id=? AND title LIKE ?", query.AccountId, titleMatch)
|
sess := x.Limit(100, 0).Where("account_id=? AND title LIKE ?", query.AccountId, titleQuery)
|
||||||
sess.Table("Dashboard")
|
sess.Table("Dashboard")
|
||||||
|
|
||||||
query.Result = make([]*m.SearchResult, 0)
|
query.Result = make([]m.DashboardSearchHit, 0)
|
||||||
err := sess.Find(&query.Result)
|
err := sess.Find(&query.Result)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDashboardTags(query *m.GetDashboardTagsQuery) error {
|
||||||
|
query.Result = []m.DashboardTagCloudItem{
|
||||||
|
m.DashboardTagCloudItem{Term: "test", Count: 10},
|
||||||
|
m.DashboardTagCloudItem{Term: "prod", Count: 20},
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
|
func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sess.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user