models.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 DataSourceListItemDTO struct {
  78. Id int64 `json:"id"`
  79. OrgId int64 `json:"orgId"`
  80. Name string `json:"name"`
  81. Type string `json:"type"`
  82. TypeLogoUrl string `json:"typeLogoUrl"`
  83. Access m.DsAccess `json:"access"`
  84. Url string `json:"url"`
  85. Password string `json:"password"`
  86. User string `json:"user"`
  87. Database string `json:"database"`
  88. BasicAuth bool `json:"basicAuth"`
  89. IsDefault bool `json:"isDefault"`
  90. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  91. }
  92. type DataSourceList []DataSourceListItemDTO
  93. func (slice DataSourceList) Len() int {
  94. return len(slice)
  95. }
  96. func (slice DataSourceList) Less(i, j int) bool {
  97. return strings.ToLower(slice[i].Name) < strings.ToLower(slice[j].Name)
  98. }
  99. func (slice DataSourceList) Swap(i, j int) {
  100. slice[i], slice[j] = slice[j], slice[i]
  101. }
  102. type MetricRequest struct {
  103. From string `json:"from"`
  104. To string `json:"to"`
  105. Queries []*simplejson.Json `json:"queries"`
  106. }
  107. type UserStars struct {
  108. DashboardIds map[string]bool `json:"dashboardIds"`
  109. }
  110. func GetGravatarUrl(text string) string {
  111. if text == "" {
  112. return ""
  113. }
  114. hasher := md5.New()
  115. hasher.Write([]byte(strings.ToLower(text)))
  116. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  117. }