models.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. Title string `json:"title"`
  13. Uri string `json:"uri"`
  14. Type HitType `json:"type"`
  15. Tags []string `json:"tags"`
  16. IsStarred bool `json:"isStarred"`
  17. FolderId int64 `json:"folderId,omitempty"`
  18. FolderTitle string `json:"folderTitle,omitempty"`
  19. FolderSlug string `json:"folderSlug,omitempty"`
  20. }
  21. type HitList []*Hit
  22. func (s HitList) Len() int { return len(s) }
  23. func (s HitList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
  24. func (s HitList) Less(i, j int) bool {
  25. if s[i].Type == "dash-folder" && s[j].Type == "dash-db" {
  26. return true
  27. }
  28. if s[i].Type == "dash-db" && s[j].Type == "dash-folder" {
  29. return false
  30. }
  31. return strings.ToLower(s[i].Title) < strings.ToLower(s[j].Title)
  32. }
  33. type Query struct {
  34. Title string
  35. Tags []string
  36. OrgId int64
  37. SignedInUser *models.SignedInUser
  38. Limit int
  39. IsStarred bool
  40. Type string
  41. DashboardIds []int64
  42. FolderIds []int64
  43. Result HitList
  44. }
  45. type FindPersistedDashboardsQuery struct {
  46. Title string
  47. OrgId int64
  48. SignedInUser *models.SignedInUser
  49. IsStarred bool
  50. DashboardIds []int64
  51. Type string
  52. FolderIds []int64
  53. Tags []string
  54. Limit int
  55. Result HitList
  56. }