models.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. Timezone string `json:"timezone"`
  32. Locale string `json:"locale"`
  33. HelpFlags1 m.HelpFlags1 `json:"helpFlags1"`
  34. }
  35. type DashboardMeta struct {
  36. IsStarred bool `json:"isStarred,omitempty"`
  37. IsHome bool `json:"isHome,omitempty"`
  38. IsSnapshot bool `json:"isSnapshot,omitempty"`
  39. Type string `json:"type,omitempty"`
  40. CanSave bool `json:"canSave"`
  41. CanEdit bool `json:"canEdit"`
  42. CanStar bool `json:"canStar"`
  43. Slug string `json:"slug"`
  44. Expires time.Time `json:"expires"`
  45. Created time.Time `json:"created"`
  46. Updated time.Time `json:"updated"`
  47. UpdatedBy string `json:"updatedBy"`
  48. CreatedBy string `json:"createdBy"`
  49. Version int `json:"version"`
  50. }
  51. type DashboardFullWithMeta struct {
  52. Meta DashboardMeta `json:"meta"`
  53. Dashboard *simplejson.Json `json:"dashboard"`
  54. }
  55. type DashboardRedirect struct {
  56. RedirectUri string `json:"redirectUri"`
  57. }
  58. type DataSource struct {
  59. Id int64 `json:"id"`
  60. OrgId int64 `json:"orgId"`
  61. Name string `json:"name"`
  62. Type string `json:"type"`
  63. TypeLogoUrl string `json:"typeLogoUrl"`
  64. Access m.DsAccess `json:"access"`
  65. Url string `json:"url"`
  66. Password string `json:"password"`
  67. User string `json:"user"`
  68. Database string `json:"database"`
  69. BasicAuth bool `json:"basicAuth"`
  70. BasicAuthUser string `json:"basicAuthUser"`
  71. BasicAuthPassword string `json:"basicAuthPassword"`
  72. WithCredentials bool `json:"withCredentials"`
  73. IsDefault bool `json:"isDefault"`
  74. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  75. SecureJsonFields map[string]bool `json:"secureJsonFields"`
  76. }
  77. type DataSourceList []DataSource
  78. func (slice DataSourceList) Len() int {
  79. return len(slice)
  80. }
  81. func (slice DataSourceList) Less(i, j int) bool {
  82. return slice[i].Name < slice[j].Name
  83. }
  84. func (slice DataSourceList) Swap(i, j int) {
  85. slice[i], slice[j] = slice[j], slice[i]
  86. }
  87. type MetricRequest struct {
  88. From string `json:"from"`
  89. To string `json:"to"`
  90. Queries []*simplejson.Json `json:"queries"`
  91. }
  92. type UserStars struct {
  93. DashboardIds map[string]bool `json:"dashboardIds"`
  94. }
  95. func GetGravatarUrl(text string) string {
  96. if text == "" {
  97. return ""
  98. }
  99. hasher := md5.New()
  100. hasher.Write([]byte(strings.ToLower(text)))
  101. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  102. }