dashboard_version.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // Queries
  51. //
  52. type GetDashboardVersionQuery struct {
  53. DashboardId int64
  54. OrgId int64
  55. Version int
  56. Result *DashboardVersion
  57. }
  58. type GetDashboardVersionsQuery struct {
  59. DashboardId int64
  60. OrgId int64
  61. Limit int
  62. Start int
  63. Result []*DashboardVersionDTO
  64. }
  65. //
  66. // Commands
  67. //
  68. // CompareDashboardVersionsCommand is used to compare two versions.
  69. type CompareDashboardVersionsCommand struct {
  70. OrgId int64
  71. DashboardId int64
  72. Original int
  73. New int
  74. DiffType DiffType
  75. Delta []byte `json:"delta"`
  76. }