models.go 1.7 KB

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