models.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. DashHitFolder HitType = "dash-folder"
  9. )
  10. type Hit struct {
  11. Id int64 `json:"id"`
  12. Uid string `json:"uid"`
  13. Title string `json:"title"`
  14. Uri string `json:"uri"`
  15. Url string `json:"url"`
  16. Type HitType `json:"type"`
  17. Tags []string `json:"tags"`
  18. IsStarred bool `json:"isStarred"`
  19. FolderId int64 `json:"folderId,omitempty"`
  20. FolderTitle string `json:"folderTitle,omitempty"`
  21. FolderSlug string `json:"folderSlug,omitempty"`
  22. }
  23. type HitList []*Hit
  24. func (s HitList) Len() int { return len(s) }
  25. func (s HitList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
  26. func (s HitList) Less(i, j int) bool {
  27. if s[i].Type == "dash-folder" && s[j].Type == "dash-db" {
  28. return true
  29. }
  30. if s[i].Type == "dash-db" && s[j].Type == "dash-folder" {
  31. return false
  32. }
  33. return strings.ToLower(s[i].Title) < strings.ToLower(s[j].Title)
  34. }
  35. type Query struct {
  36. Title string
  37. Tags []string
  38. OrgId int64
  39. SignedInUser *models.SignedInUser
  40. Limit int
  41. IsStarred bool
  42. Type string
  43. DashboardIds []int64
  44. FolderIds []int64
  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. FolderIds []int64
  55. Tags []string
  56. Limit int
  57. IsBrowse bool
  58. Result HitList
  59. }