Commit 5c89c4b2 by Daniel Lee

WIP: dashlist in template for new folder

parent 533f2d3d
...@@ -185,7 +185,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response { ...@@ -185,7 +185,7 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
} }
c.TimeRequest(metrics.M_Api_Dashboard_Save) 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 { func canEditDashboard(role m.RoleType) bool {
......
...@@ -28,4 +28,27 @@ func TestDashboardModel(t *testing.T) { ...@@ -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)
})
})
} }
...@@ -211,12 +211,45 @@ export class BackendSrv { ...@@ -211,12 +211,45 @@ export class BackendSrv {
}); });
} }
saveDashboardFolder(name) { createDashboardFolder(name) {
const dash = { 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});
});
} }
} }
......
...@@ -19,7 +19,7 @@ export class FolderCtrl { ...@@ -19,7 +19,7 @@ export class FolderCtrl {
const title = this.title.trim(); 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('alert-success', ['Dashboard saved', 'Saved as ' + title]);
appEvents.emit('dashboard-saved', result); appEvents.emit('dashboard-saved', result);
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-6">Folder</span> <span class="gf-form-label width-6">Folder</span>
<folder-picker on-change="ctrl.onFolderChange" root-folder-name="All"></folder-picker> <folder-picker selected-folder="ctrl.panel.folderId" on-change="ctrl.onFolderChange" root-folder-name="All"></folder-picker>
</div> </div>
<div class="gf-form"> <div class="gf-form">
......
...@@ -12,7 +12,6 @@ class DashListCtrl extends PanelCtrl { ...@@ -12,7 +12,6 @@ class DashListCtrl extends PanelCtrl {
modes: any[]; modes: any[];
panelDefaults = { panelDefaults = {
folder: '',
query: '', query: '',
limit: 10, limit: 10,
tags: [], tags: [],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment