models.go 3.3 KB

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