models.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 DashboardSlug struct {
  53. Slug string `json:"slug"`
  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. Access m.DsAccess `json:"access"`
  61. Url string `json:"url"`
  62. Password string `json:"password"`
  63. User string `json:"user"`
  64. Database string `json:"database"`
  65. BasicAuth bool `json:"basicAuth"`
  66. BasicAuthUser string `json:"basicAuthUser"`
  67. BasicAuthPassword string `json:"basicAuthPassword"`
  68. WithCredentials bool `json:"withCredentials"`
  69. IsDefault bool `json:"isDefault"`
  70. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  71. }
  72. type MetricQueryResultDto struct {
  73. Data []MetricQueryResultDataDto `json:"data"`
  74. }
  75. type MetricQueryResultDataDto struct {
  76. Target string `json:"target"`
  77. DataPoints [][2]float64 `json:"datapoints"`
  78. }
  79. type UserStars struct {
  80. DashboardIds map[string]bool `json:"dashboardIds"`
  81. }
  82. func GetGravatarUrl(text string) string {
  83. if text == "" {
  84. return ""
  85. }
  86. hasher := md5.New()
  87. hasher.Write([]byte(strings.ToLower(text)))
  88. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  89. }