models.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. FolderUid string `json:"folderUid,omitempty"`
  21. FolderTitle string `json:"folderTitle,omitempty"`
  22. FolderUrl string `json:"folderUrl,omitempty"`
  23. }
  24. type HitList []*Hit
  25. func (s HitList) Len() int { return len(s) }
  26. func (s HitList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
  27. func (s HitList) Less(i, j int) bool {
  28. if s[i].Type == "dash-folder" && s[j].Type == "dash-db" {
  29. return true
  30. }
  31. if s[i].Type == "dash-db" && s[j].Type == "dash-folder" {
  32. return false
  33. }
  34. return strings.ToLower(s[i].Title) < strings.ToLower(s[j].Title)
  35. }
  36. type Query struct {
  37. Title string
  38. Tags []string
  39. OrgId int64
  40. SignedInUser *models.SignedInUser
  41. Limit int
  42. IsStarred bool
  43. Type string
  44. DashboardIds []int64
  45. FolderIds []int64
  46. Result HitList
  47. }
  48. type FindPersistedDashboardsQuery struct {
  49. Title string
  50. OrgId int64
  51. SignedInUser *models.SignedInUser
  52. IsStarred bool
  53. DashboardIds []int64
  54. Type string
  55. FolderIds []int64
  56. Tags []string
  57. Limit int
  58. IsBrowse bool
  59. Result HitList
  60. }