mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 13:22:03 +08:00
Worked on stars in search results
This commit is contained in:
2
grafana
2
grafana
Submodule grafana updated: 1e3970c6e5...b67f4dc390
@ -45,6 +45,7 @@ func Register(r *macaron.Macaron) {
|
||||
r.Put("/", bind(m.UpdateUserCommand{}), UpdateUser)
|
||||
r.Post("/using/:id", SetUsingAccount)
|
||||
r.Get("/accounts", GetUserAccounts)
|
||||
r.Get("/stars/", GetUserStars)
|
||||
r.Post("/stars/dashboard/:id", StarDashboard)
|
||||
r.Delete("/stars/dashboard/:id", UnstarDashboard)
|
||||
})
|
||||
|
@ -57,6 +57,10 @@ type MetricQueryResultDataDto struct {
|
||||
DataPoints [][2]float64 `json:"datapoints"`
|
||||
}
|
||||
|
||||
type UserStars struct {
|
||||
DashboardIds map[string]bool `json:"dashboardIds"`
|
||||
}
|
||||
|
||||
func GetGravatarUrl(text string) string {
|
||||
if text == "" {
|
||||
return ""
|
||||
|
@ -1,6 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
@ -43,3 +46,20 @@ func UnstarDashboard(c *middleware.Context) {
|
||||
|
||||
c.JsonOK("Dashboard unstarred")
|
||||
}
|
||||
|
||||
func GetUserStars(c *middleware.Context) {
|
||||
query := m.GetUserStarsQuery{UserId: c.UserId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
c.JsonApiErr(500, "Failed to get user stars", err)
|
||||
return
|
||||
}
|
||||
|
||||
var result dtos.UserStars
|
||||
result.DashboardIds = make(map[string]bool)
|
||||
for _, star := range query.Result {
|
||||
result.DashboardIds[strconv.FormatInt(star.DashboardId, 10)] = true
|
||||
}
|
||||
|
||||
c.JSON(200, &result)
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ type SearchResult struct {
|
||||
}
|
||||
|
||||
type DashboardSearchHit struct {
|
||||
Id int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Slug string `json:"slug"`
|
||||
Tags []string `json:"tags"`
|
||||
|
@ -105,6 +105,7 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error {
|
||||
hit, exists := hits[item.Id]
|
||||
if !exists {
|
||||
hit = &m.DashboardSearchHit{
|
||||
Id: item.Id,
|
||||
Title: item.Title,
|
||||
Slug: item.Slug,
|
||||
Tags: []string{},
|
||||
|
Reference in New Issue
Block a user