models.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "github.com/grafana/grafana/pkg/components/simplejson"
  7. m "github.com/grafana/grafana/pkg/models"
  8. "github.com/grafana/grafana/pkg/setting"
  9. )
  10. type AnyId struct {
  11. Id int64 `json:"id"`
  12. }
  13. type LoginCommand struct {
  14. User string `json:"user" binding:"Required"`
  15. Password string `json:"password" binding:"Required"`
  16. Remember bool `json:"remember"`
  17. }
  18. type CurrentUser struct {
  19. IsSignedIn bool `json:"isSignedIn"`
  20. Id int64 `json:"id"`
  21. Login string `json:"login"`
  22. Email string `json:"email"`
  23. Name string `json:"name"`
  24. LightTheme bool `json:"lightTheme"`
  25. OrgCount int `json:"orgCount"`
  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 DataSource struct {
  36. Id int64 `json:"id"`
  37. OrgId int64 `json:"orgId"`
  38. Name string `json:"name"`
  39. Type string `json:"type"`
  40. TypeLogoUrl string `json:"typeLogoUrl"`
  41. Access m.DsAccess `json:"access"`
  42. Url string `json:"url"`
  43. Password string `json:"password"`
  44. User string `json:"user"`
  45. Database string `json:"database"`
  46. BasicAuth bool `json:"basicAuth"`
  47. BasicAuthUser string `json:"basicAuthUser"`
  48. BasicAuthPassword string `json:"basicAuthPassword"`
  49. WithCredentials bool `json:"withCredentials"`
  50. IsDefault bool `json:"isDefault"`
  51. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  52. SecureJsonFields map[string]bool `json:"secureJsonFields"`
  53. }
  54. type DataSourceListItemDTO struct {
  55. Id int64 `json:"id"`
  56. OrgId int64 `json:"orgId"`
  57. Name string `json:"name"`
  58. Type string `json:"type"`
  59. TypeLogoUrl string `json:"typeLogoUrl"`
  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. IsDefault bool `json:"isDefault"`
  67. JsonData *simplejson.Json `json:"jsonData,omitempty"`
  68. }
  69. type DataSourceList []DataSourceListItemDTO
  70. func (slice DataSourceList) Len() int {
  71. return len(slice)
  72. }
  73. func (slice DataSourceList) Less(i, j int) bool {
  74. return strings.ToLower(slice[i].Name) < strings.ToLower(slice[j].Name)
  75. }
  76. func (slice DataSourceList) Swap(i, j int) {
  77. slice[i], slice[j] = slice[j], slice[i]
  78. }
  79. type MetricRequest struct {
  80. From string `json:"from"`
  81. To string `json:"to"`
  82. Queries []*simplejson.Json `json:"queries"`
  83. }
  84. type UserStars struct {
  85. DashboardIds map[string]bool `json:"dashboardIds"`
  86. }
  87. func GetGravatarUrl(text string) string {
  88. if text == "" {
  89. return ""
  90. }
  91. hasher := md5.New()
  92. hasher.Write([]byte(strings.ToLower(text)))
  93. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  94. }