models.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package search
  2. import "strings"
  3. import "github.com/grafana/grafana/pkg/models"
  4. type HitType string
  5. const (
  6. DashHitDB HitType = "dash-db"
  7. DashHitHome HitType = "dash-home"
  8. DashHitJson HitType = "dash-json"
  9. DashHitScripted HitType = "dash-scripted"
  10. DashHitFolder HitType = "dash-folder"
  11. )
  12. type Hit struct {
  13. Id int64 `json:"id"`
  14. Title string `json:"title"`
  15. Uri string `json:"uri"`
  16. Type HitType `json:"type"`
  17. Tags []string `json:"tags"`
  18. IsStarred bool `json:"isStarred"`
  19. ParentId int64 `json:"parentId"`
  20. Dashboards []Hit `json:"dashboards"`
  21. }
  22. type HitList []*Hit
  23. func (s HitList) Len() int { return len(s) }
  24. func (s HitList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
  25. func (s HitList) Less(i, j int) bool {
  26. if s[i].Type == "dash-folder" && s[j].Type == "dash-db" {
  27. return true
  28. }
  29. if s[i].Type == "dash-db" && s[j].Type == "dash-folder" {
  30. return false
  31. }
  32. return strings.ToLower(s[i].Title) < strings.ToLower(s[j].Title)
  33. }
  34. type Query struct {
  35. Title string
  36. Tags []string
  37. OrgId int64
  38. SignedInUser *models.SignedInUser
  39. Limit int
  40. IsStarred bool
  41. Type string
  42. DashboardIds []int64
  43. FolderId int64
  44. Mode string
  45. Result HitList
  46. }
  47. type FindPersistedDashboardsQuery struct {
  48. Title string
  49. OrgId int64
  50. SignedInUser *models.SignedInUser
  51. IsStarred bool
  52. DashboardIds []int64
  53. Type string
  54. ParentId int64
  55. Mode string
  56. Result HitList
  57. }