provisioning: improve UX when saving provisioned dashboards

This commit is contained in:
bergquist
2018-03-26 15:08:46 +02:00
parent a20f3d196c
commit d6faa3d06f
11 changed files with 152 additions and 4 deletions
+7
View File
@@ -102,6 +102,13 @@ func GetDashboard(c *m.ReqContext) Response {
meta.FolderUrl = query.Result.GetUrl()
}
dpQuery := &m.GetProvisionedDashboardByDashboardId{DashboardId: dash.Id}
err = bus.Dispatch(dpQuery)
if dpQuery.Result != nil {
meta.CanEdit = true
meta.Provisioned = true
}
// make sure db version is in sync with json model version
dash.Data.Set("version", dash.Version)
+1
View File
@@ -28,6 +28,7 @@ type DashboardMeta struct {
FolderId int64 `json:"folderId"`
FolderTitle string `json:"folderTitle"`
FolderUrl string `json:"folderUrl"`
Provisioned bool `json:"provisioned"`
}
type DashboardFullWithMeta struct {
+6
View File
@@ -317,6 +317,12 @@ type GetDashboardSlugByIdQuery struct {
Result string
}
type GetProvisionedDashboardByDashboardId struct {
DashboardId int64
Result *DashboardProvisioning
}
type GetProvisionedDashboardDataQuery struct {
Name string
@@ -55,9 +55,6 @@ func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *Das
dash.OrgId = cfg.OrgId
dash.Dashboard.OrgId = cfg.OrgId
dash.Dashboard.FolderId = folderId
if !cfg.Editable {
dash.Dashboard.Data.Set("editable", cfg.Editable)
}
if dash.Dashboard.Title == "" {
return nil, models.ErrDashboardTitleEmpty
@@ -8,6 +8,7 @@ import (
func init() {
bus.AddHandler("sql", GetProvisionedDashboardDataQuery)
bus.AddHandler("sql", SaveProvisionedDashboard)
bus.AddHandler("sql", GetProvisionedDataByDashboardId)
}
type DashboardExtras struct {
@@ -17,6 +18,18 @@ type DashboardExtras struct {
Value string
}
func GetProvisionedDataByDashboardId(cmd *models.GetProvisionedDashboardByDashboardId) error {
result := &models.DashboardProvisioning{}
_, err := x.Where("dashboard_id = ?", cmd.DashboardId).Get(result)
if err != nil {
return err
}
cmd.Result = result
return nil
}
func SaveProvisionedDashboard(cmd *models.SaveProvisionedDashboardCommand) error {
return inTransaction(func(sess *DBSession) error {
err := saveDashboard(sess, cmd.DashboardCmd)
@@ -50,6 +50,16 @@ func TestDashboardProvisioningTest(t *testing.T) {
So(query.Result[0].DashboardId, ShouldEqual, dashId)
So(query.Result[0].Updated, ShouldEqual, now.Unix())
})
Convey("Can query for one provisioned dashboard", func() {
query := &models.GetProvisionedDashboardByDashboardId{DashboardId: cmd.Result.Id}
err := GetProvisionedDataByDashboardId(query)
So(err, ShouldBeNil)
So(query.Result.DashboardId, ShouldEqual, cmd.Result.Id)
So(query.Result.Updated, ShouldEqual, now.Unix())
})
})
})
}