浏览代码

Worked on stars in search results

Torkel Ödegaard 11 年之前
父节点
当前提交
97758380e0
共有 6 个文件被更改,包括 28 次插入1 次删除
  1. 1 1
      grafana
  2. 1 0
      pkg/api/api.go
  3. 4 0
      pkg/api/dtos/models.go
  4. 20 0
      pkg/api/stars.go
  5. 1 0
      pkg/models/search.go
  6. 1 0
      pkg/services/sqlstore/dashboard.go

+ 1 - 1
grafana

@@ -1 +1 @@
-Subproject commit 1e3970c6e56af810047ab815acd7fd5e681b5139
+Subproject commit b67f4dc390b5241339b8f2799110faf3d454e4c5

+ 1 - 0
pkg/api/api.go

@@ -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)
 		})

+ 4 - 0
pkg/api/dtos/models.go

@@ -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 ""

+ 20 - 0
pkg/api/stars.go

@@ -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)
+}

+ 1 - 0
pkg/models/search.go

@@ -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"`

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

@@ -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{},