WIP: dashlist in template for new folder

This commit is contained in:
Daniel Lee 2017-06-02 11:49:27 +02:00
parent 533f2d3d72
commit 5c89c4b2bd
6 changed files with 62 additions and 7 deletions

View File

@ -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 {

View File

@ -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)
})
})
}

View File

@ -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});
});
}
}

View File

@ -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);

View File

@ -24,7 +24,7 @@
<div class="gf-form">
<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 class="gf-form">

View File

@ -12,7 +12,6 @@ class DashListCtrl extends PanelCtrl {
modes: any[];
panelDefaults = {
folder: '',
query: '',
limit: 10,
tags: [],