diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 1809c6ca486..daab2ec9074 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -185,7 +185,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response { } c.TimeRequest(metrics.M_Api_Dashboard_Save) - return Json(200, util.DynMap{"status": "success", "slug": cmd.Result.Slug, "version": cmd.Result.Version}) + return Json(200, util.DynMap{"status": "success", "slug": cmd.Result.Slug, "version": cmd.Result.Version, "id": cmd.Result.Id}) } func canEditDashboard(role m.RoleType) bool { diff --git a/pkg/models/dashboards_test.go b/pkg/models/dashboards_test.go index ee16508dc8a..a527e5b3891 100644 --- a/pkg/models/dashboards_test.go +++ b/pkg/models/dashboards_test.go @@ -28,4 +28,27 @@ func TestDashboardModel(t *testing.T) { }) }) + Convey("Given a new dashboard folder", t, func() { + json := simplejson.New() + json.Set("title", "test dash") + + cmd := &SaveDashboardCommand{Dashboard: json, IsFolder: true} + dash := cmd.GetDashboardModel() + + Convey("Should set IsFolder to true", func() { + So(dash.IsFolder, ShouldBeTrue) + }) + }) + + Convey("Given a child dashboard", t, func() { + json := simplejson.New() + json.Set("title", "test dash") + + cmd := &SaveDashboardCommand{Dashboard: json, ParentId: 1} + dash := cmd.GetDashboardModel() + + Convey("Should set ParentId", func() { + So(dash.ParentId, ShouldEqual, 1) + }) + }) } diff --git a/public/app/core/services/backend_srv.ts b/public/app/core/services/backend_srv.ts index b590a5d947a..ff1de594949 100644 --- a/public/app/core/services/backend_srv.ts +++ b/public/app/core/services/backend_srv.ts @@ -211,12 +211,45 @@ export class BackendSrv { }); } - saveDashboardFolder(name) { + createDashboardFolder(name) { const dash = { - title: name + title: name, + editable: false, + hideControls: true, + rows: [ + { + panels: [ + { + folderId: 0, + headings: false, + id: 1, + limit: 1000, + links: [], + query: '', + recent: false, + search: true, + span: 12, + starred: false, + tags: [], + title: 'Dashboards', + type: 'dashlist' + } + ], + showTitle: false, + title: 'Dashboard List', + titleSize: 'h6' + } + ] }; - return this.post('/api/dashboards/db/', {dashboard: dash, isFolder: true, overwrite: false}); + return this.post('/api/dashboards/db/', {dashboard: dash, isFolder: true, overwrite: false}) + .then(res => { + return this.getDashboard('db', res.slug); + }) + .then(res => { + res.dashboard.rows[0].panels[0].folderId = res.dashboard.id; + return this.saveDashboard(res.dashboard, {overwrite: false}); + }); } } diff --git a/public/app/features/dashboard/folder_modal/folder.ts b/public/app/features/dashboard/folder_modal/folder.ts index 5573cff61fc..81d3cc92566 100644 --- a/public/app/features/dashboard/folder_modal/folder.ts +++ b/public/app/features/dashboard/folder_modal/folder.ts @@ -19,7 +19,7 @@ export class FolderCtrl { const title = this.title.trim(); - return this.backendSrv.saveDashboardFolder(title).then((result) => { + return this.backendSrv.createDashboardFolder(title).then((result) => { appEvents.emit('alert-success', ['Dashboard saved', 'Saved as ' + title]); appEvents.emit('dashboard-saved', result); diff --git a/public/app/plugins/panel/dashlist/editor.html b/public/app/plugins/panel/dashlist/editor.html index 2dc35808e99..c789fffeb93 100644 --- a/public/app/plugins/panel/dashlist/editor.html +++ b/public/app/plugins/panel/dashlist/editor.html @@ -24,7 +24,7 @@