dashboard_version.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. )
  7. type DiffType int
  8. const (
  9. DiffJSON DiffType = iota
  10. DiffBasic
  11. DiffDelta
  12. )
  13. var (
  14. ErrDashboardVersionNotFound = errors.New("Dashboard version not found")
  15. ErrNoVersionsForDashboardId = errors.New("No dashboard versions found for the given DashboardId")
  16. )
  17. // A DashboardVersion represents the comparable data in a dashboard, allowing
  18. // diffs of the dashboard to be performed.
  19. type DashboardVersion struct {
  20. Id int64 `json:"id"`
  21. DashboardId int64 `json:"dashboardId"`
  22. ParentVersion int `json:"parentVersion"`
  23. RestoredFrom int `json:"restoredFrom"`
  24. Version int `json:"version"`
  25. Created time.Time `json:"created"`
  26. CreatedBy int64 `json:"createdBy"`
  27. Message string `json:"message"`
  28. Data *simplejson.Json `json:"data"`
  29. }
  30. // DashboardVersionMeta extends the dashboard version model with the names
  31. // associated with the UserIds, overriding the field with the same name from
  32. // the DashboardVersion model.
  33. type DashboardVersionMeta struct {
  34. DashboardVersion
  35. CreatedBy string `json:"createdBy"`
  36. }
  37. // DashboardVersionDTO represents a dashboard version, without the dashboard
  38. // map.
  39. type DashboardVersionDTO struct {
  40. Id int64 `json:"id"`
  41. DashboardId int64 `json:"dashboardId"`
  42. ParentVersion int `json:"parentVersion"`
  43. RestoredFrom int `json:"restoredFrom"`
  44. Version int `json:"version"`
  45. Created time.Time `json:"created"`
  46. CreatedBy string `json:"createdBy"`
  47. Message string `json:"message"`
  48. }
  49. //
  50. // COMMANDS
  51. //
  52. // GetDashboardVersionCommand contains the data required to execute the
  53. // sqlstore.GetDashboardVersionCommand, which returns the DashboardVersion for
  54. // the given Version.
  55. type GetDashboardVersionCommand struct {
  56. DashboardId int64 `json:"dashboardId" binding:"Required"`
  57. Version int `json:"version" binding:"Required"`
  58. Result *DashboardVersion
  59. }
  60. // GetDashboardVersionsCommand contains the data required to execute the
  61. // sqlstore.GetDashboardVersionsCommand, which returns all dashboard versions.
  62. type GetDashboardVersionsCommand struct {
  63. DashboardId int64 `json:"dashboardId" binding:"Required"`
  64. OrderBy string `json:"orderBy"`
  65. Limit int `json:"limit"`
  66. Start int `json:"start"`
  67. Result []*DashboardVersion
  68. }
  69. // RestoreDashboardVersionCommand creates a new dashboard version.
  70. type RestoreDashboardVersionCommand struct {
  71. DashboardId int64 `json:"dashboardId"`
  72. Version int `json:"version" binding:"Required"`
  73. UserId int64 `json:"-"`
  74. Result *Dashboard
  75. }
  76. // CompareDashboardVersionsCommand is used to compare two versions.
  77. type CompareDashboardVersionsCommand struct {
  78. DashboardId int64 `json:"dashboardId"`
  79. Original int `json:"original" binding:"Required"`
  80. New int `json:"new" binding:"Required"`
  81. DiffType DiffType `json:"-"`
  82. Delta []byte `json:"delta"`
  83. }