models.go 1.5 KB

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