|
|
|
|
@@ -13,17 +13,22 @@ import (
|
|
|
|
|
|
|
|
|
|
// Typed errors
|
|
|
|
|
var (
|
|
|
|
|
ErrDashboardNotFound = errors.New("Dashboard not found")
|
|
|
|
|
ErrDashboardSnapshotNotFound = errors.New("Dashboard snapshot not found")
|
|
|
|
|
ErrDashboardWithSameUIDExists = errors.New("A dashboard with the same uid already exists")
|
|
|
|
|
ErrDashboardWithSameNameInFolderExists = errors.New("A dashboard with the same name in the folder already exists")
|
|
|
|
|
ErrDashboardVersionMismatch = errors.New("The dashboard has been changed by someone else")
|
|
|
|
|
ErrDashboardTitleEmpty = errors.New("Dashboard title cannot be empty")
|
|
|
|
|
ErrDashboardFolderCannotHaveParent = errors.New("A Dashboard Folder cannot be added to another folder")
|
|
|
|
|
ErrDashboardContainsInvalidAlertData = errors.New("Invalid alert data. Cannot save dashboard")
|
|
|
|
|
ErrDashboardFailedToUpdateAlertData = errors.New("Failed to save alert data")
|
|
|
|
|
ErrDashboardsWithSameSlugExists = errors.New("Multiple dashboards with the same slug exists")
|
|
|
|
|
ErrDashboardFailedGenerateUniqueUid = errors.New("Failed to generate unique dashboard id")
|
|
|
|
|
ErrDashboardNotFound = errors.New("Dashboard not found")
|
|
|
|
|
ErrDashboardSnapshotNotFound = errors.New("Dashboard snapshot not found")
|
|
|
|
|
ErrDashboardWithSameUIDExists = errors.New("A dashboard with the same uid already exists")
|
|
|
|
|
ErrDashboardWithSameNameInFolderExists = errors.New("A dashboard with the same name in the folder already exists")
|
|
|
|
|
ErrDashboardVersionMismatch = errors.New("The dashboard has been changed by someone else")
|
|
|
|
|
ErrDashboardTitleEmpty = errors.New("Dashboard title cannot be empty")
|
|
|
|
|
ErrDashboardFolderCannotHaveParent = errors.New("A Dashboard Folder cannot be added to another folder")
|
|
|
|
|
ErrDashboardContainsInvalidAlertData = errors.New("Invalid alert data. Cannot save dashboard")
|
|
|
|
|
ErrDashboardFailedToUpdateAlertData = errors.New("Failed to save alert data")
|
|
|
|
|
ErrDashboardsWithSameSlugExists = errors.New("Multiple dashboards with the same slug exists")
|
|
|
|
|
ErrDashboardFailedGenerateUniqueUid = errors.New("Failed to generate unique dashboard id")
|
|
|
|
|
ErrDashboardExistingCannotChangeToDashboard = errors.New("An existing folder cannot be changed to a dashboard")
|
|
|
|
|
ErrDashboardTypeMismatch = errors.New("Dashboard cannot be changed to a folder")
|
|
|
|
|
ErrDashboardFolderWithSameNameAsDashboard = errors.New("Folder name cannot be the same as one of its dashboards")
|
|
|
|
|
ErrDashboardWithSameNameAsFolder = errors.New("Dashboard name cannot be the same as folder")
|
|
|
|
|
RootFolderName = "General"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UpdatePluginDashboardError struct {
|
|
|
|
|
@@ -64,6 +69,11 @@ type Dashboard struct {
|
|
|
|
|
Data *simplejson.Json
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *Dashboard) SetId(id int64) {
|
|
|
|
|
d.Id = id
|
|
|
|
|
d.Data.Set("id", id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewDashboard creates a new dashboard
|
|
|
|
|
func NewDashboard(title string) *Dashboard {
|
|
|
|
|
dash := &Dashboard{}
|
|
|
|
|
@@ -95,14 +105,21 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard {
|
|
|
|
|
dash.Data = data
|
|
|
|
|
dash.Title = dash.Data.Get("title").MustString()
|
|
|
|
|
dash.UpdateSlug()
|
|
|
|
|
update := false
|
|
|
|
|
|
|
|
|
|
if id, err := dash.Data.Get("id").Float64(); err == nil {
|
|
|
|
|
dash.Id = int64(id)
|
|
|
|
|
update = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if version, err := dash.Data.Get("version").Float64(); err == nil {
|
|
|
|
|
dash.Version = int(version)
|
|
|
|
|
dash.Updated = time.Now()
|
|
|
|
|
}
|
|
|
|
|
if uid, err := dash.Data.Get("uid").String(); err == nil {
|
|
|
|
|
dash.Uid = uid
|
|
|
|
|
update = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if version, err := dash.Data.Get("version").Float64(); err == nil && update {
|
|
|
|
|
dash.Version = int(version)
|
|
|
|
|
dash.Updated = time.Now()
|
|
|
|
|
} else {
|
|
|
|
|
dash.Data.Set("version", 0)
|
|
|
|
|
dash.Created = time.Now()
|
|
|
|
|
@@ -113,10 +130,6 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard {
|
|
|
|
|
dash.GnetId = int64(gnetId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if uid, err := dash.Data.Get("uid").String(); err == nil {
|
|
|
|
|
dash.Uid = uid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dash
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -211,6 +224,21 @@ type SaveDashboardCommand struct {
|
|
|
|
|
Result *Dashboard
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DashboardProvisioning struct {
|
|
|
|
|
Id int64
|
|
|
|
|
DashboardId int64
|
|
|
|
|
Name string
|
|
|
|
|
ExternalId string
|
|
|
|
|
Updated time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SaveProvisionedDashboardCommand struct {
|
|
|
|
|
DashboardCmd *SaveDashboardCommand
|
|
|
|
|
DashboardProvisioning *DashboardProvisioning
|
|
|
|
|
|
|
|
|
|
Result *Dashboard
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DeleteDashboardCommand struct {
|
|
|
|
|
Id int64
|
|
|
|
|
OrgId int64
|
|
|
|
|
@@ -263,6 +291,12 @@ type GetDashboardSlugByIdQuery struct {
|
|
|
|
|
Result string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetProvisionedDashboardDataQuery struct {
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
|
|
Result []*DashboardProvisioning
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetDashboardsBySlugQuery struct {
|
|
|
|
|
OrgId int64
|
|
|
|
|
Slug string
|
|
|
|
|
@@ -281,7 +315,7 @@ type DashboardRef struct {
|
|
|
|
|
Slug string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetDashboardUIDByIdQuery struct {
|
|
|
|
|
type GetDashboardRefByIdQuery struct {
|
|
|
|
|
Id int64
|
|
|
|
|
Result *DashboardRef
|
|
|
|
|
}
|
|
|
|
|
|