Browse Source

WIP: dashboard search by type (folder or dash)

Daniel Lee 8 năm trước cách đây
mục cha
commit
68b9342de3

+ 2 - 0
pkg/api/search.go

@@ -14,6 +14,7 @@ func Search(c *middleware.Context) {
 	tags := c.QueryStrings("tag")
 	starred := c.Query("starred")
 	limit := c.QueryInt("limit")
+	dashboardType := c.Query("type")
 
 	if limit == 0 {
 		limit = 1000
@@ -35,6 +36,7 @@ func Search(c *middleware.Context) {
 		IsStarred:    starred == "true",
 		OrgId:        c.OrgId,
 		DashboardIds: dbids,
+		Type:         dashboardType,
 	}
 
 	err := bus.Dispatch(&searchQuery)

+ 1 - 0
pkg/services/search/handlers.go

@@ -45,6 +45,7 @@ func searchHandler(query *Query) error {
 		IsStarred:    query.IsStarred,
 		OrgId:        query.OrgId,
 		DashboardIds: query.DashboardIds,
+		Type:         query.Type,
 	}
 
 	if err := bus.Dispatch(&dashQuery); err != nil {

+ 2 - 0
pkg/services/search/models.go

@@ -46,6 +46,7 @@ type Query struct {
 	UserId       int64
 	Limit        int
 	IsStarred    bool
+	Type         string
 	DashboardIds []int
 
 	Result HitList
@@ -57,6 +58,7 @@ type FindPersistedDashboardsQuery struct {
 	UserId       int64
 	IsStarred    bool
 	DashboardIds []int
+	Type         string
 
 	Result HitList
 }

+ 8 - 0
pkg/services/sqlstore/dashboard.go

@@ -201,6 +201,14 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
 		params = append(params, "%"+query.Title+"%")
 	}
 
+	if len(query.Type) > 0 && query.Type == "dash-folder" {
+		sql.WriteString(" AND dashboard.is_folder = 1")
+	}
+
+	if len(query.Type) > 0 && query.Type == "dash-db" {
+		sql.WriteString(" AND dashboard.is_folder = 0")
+	}
+
 	sql.WriteString(fmt.Sprintf(" ORDER BY dashboard.title ASC LIMIT 1000"))
 
 	var res []DashboardSearchProjection