models.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. Permission models.PermissionType
  47. Result HitList
  48. }
  49. type FindPersistedDashboardsQuery struct {
  50. Title string
  51. OrgId int64
  52. SignedInUser *models.SignedInUser
  53. IsStarred bool
  54. DashboardIds []int64
  55. Type string
  56. FolderIds []int64
  57. Tags []string
  58. Limit int
  59. Permission models.PermissionType
  60. Result HitList
  61. }