models.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/grafana/grafana/pkg/components/simplejson"
  8. m "github.com/grafana/grafana/pkg/models"
  9. "github.com/grafana/grafana/pkg/setting"
  10. )
  11. type AnyId struct {
  12. Id int64 `json:"id"`
  13. }
  14. type LoginCommand struct {
  15. User string `json:"user" binding:"Required"`
  16. Password string `json:"password" binding:"Required"`
  17. Remember bool `json:"remember"`
  18. }
  19. type CurrentUser struct {
  20. IsSignedIn bool `json:"isSignedIn"`
  21. Id int64 `json:"id"`
  22. Login string `json:"login"`
  23. Email string `json:"email"`
  24. Name string `json:"name"`
  25. LightTheme bool `json:"lightTheme"`
  26. OrgId int64 `json:"orgId"`
  27. OrgName string `json:"orgName"`
  28. OrgRole m.RoleType `json:"orgRole"`
  29. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  30. GravatarUrl string `json:"gravatarUrl"`
  31. }
  32. type DashboardMeta struct {
  33. IsStarred bool `json:"isStarred,omitempty"`
  34. IsHome bool `json:"isHome,omitempty"`
  35. IsSnapshot bool `json:"isSnapshot,omitempty"`
  36. Type string `json:"type,omitempty"`
  37. CanSave bool `json:"canSave"`
  38. CanEdit bool `json:"canEdit"`
  39. CanStar bool `json:"canStar"`
  40. Slug string `json:"slug"`
  41. Expires time.Time `json:"expires"`
  42. Created time.Time `json:"created"`
  43. Updated time.Time `json:"updated"`
  44. UpdatedBy string `json:"updatedBy"`
  45. CreatedBy string `json:"createdBy"`
  46. Version int `json:"version"`
  47. }
  48. type DashboardFullWithMeta struct {
  49. Meta DashboardMeta `json:"meta"`
  50. Dashboard *simplejson.Json `json:"dashboard"`
  51. }
  52. type DashboardRedirect struct {
  53. RedirectUri string `json:"redirectUri"`
  54. }
  55. type DataSource struct {
  56. Id int64 `json:"id"`
  57. OrgId int64 `json:"orgId"`
  58. Name string `json:"name"`
  59. Type string `json:"type"`
  60. TypeLogoUrl string `json:"typeLogoUrl"`
  61. Access m.DsAccess `json:"access"`
  62. Url string `json:"url"`
  63. Password string `json:"password"`
  64. User string `json:"user"`
  65. Database string `json:"database"`
  66. BasicAuth bool `json:"basicAuth"`
  67. BasicAuthUser string `json:"basicAuthUser"`
  68. BasicAuthPassword string `json:"basicAuthPassword"`
  69. WithCredentials bool `json:"withCredentials"`
  70. IsDefault bool `json:"isDefault"`
  71. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  72. }
  73. type DataSourceList []DataSource
  74. func (slice DataSourceList) Len() int {
  75. return len(slice)
  76. }
  77. func (slice DataSourceList) Less(i, j int) bool {
  78. return slice[i].Name < slice[j].Name
  79. }
  80. func (slice DataSourceList) Swap(i, j int) {
  81. slice[i], slice[j] = slice[j], slice[i]
  82. }
  83. type MetricQueryResultDto struct {
  84. Data []MetricQueryResultDataDto `json:"data"`
  85. }
  86. type MetricQueryResultDataDto struct {
  87. Target string `json:"target"`
  88. DataPoints [][2]float64 `json:"datapoints"`
  89. }
  90. type UserStars struct {
  91. DashboardIds map[string]bool `json:"dashboardIds"`
  92. }
  93. func GetGravatarUrl(text string) string {
  94. if text == "" {
  95. return ""
  96. }
  97. hasher := md5.New()
  98. hasher.Write([]byte(strings.ToLower(text)))
  99. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  100. }