Refactor search (#23550)

Co-Authored-By: Arve Knudsen <arve.knudsen@grafana.com>
Co-Authored-By: Leonard Gram <leonard.gram@grafana.com>
This commit is contained in:
Emil Tullstedt
2020-04-20 16:20:45 +02:00
committed by GitHub
parent e5dd7efdee
commit 55c306eb6d
13 changed files with 778 additions and 16 deletions

View File

@@ -1,6 +1,8 @@
package api
import (
"github.com/grafana/grafana/pkg/util"
"net/http"
"strconv"
"github.com/grafana/grafana/pkg/bus"
@@ -16,6 +18,7 @@ func Search(c *models.ReqContext) Response {
limit := c.QueryInt64("limit")
page := c.QueryInt64("page")
dashboardType := c.Query("type")
sort := c.Query("sort")
permission := models.PERMISSION_VIEW
if limit > 5000 {
@@ -54,6 +57,7 @@ func Search(c *models.ReqContext) Response {
Type: dashboardType,
FolderIds: folderIDs,
Permission: permission,
Sort: sort,
}
err := bus.Dispatch(&searchQuery)
@@ -64,3 +68,20 @@ func Search(c *models.ReqContext) Response {
c.TimeRequest(metrics.MApiDashboardSearch)
return JSON(200, searchQuery.Result)
}
func (hs *HTTPServer) ListSortOptions(c *models.ReqContext) Response {
opts := hs.SearchService.SortOptions()
res := []util.DynMap{}
for _, o := range opts {
res = append(res, util.DynMap{
"name": o.Name,
"displayName": o.DisplayName,
"description": o.Description,
})
}
return JSON(http.StatusOK, util.DynMap{
"sortOptions": res,
})
}