Browse Source

WIP: dashlist in template for new folder

Daniel Lee 8 years ago
parent
commit
5c89c4b2bd

+ 1 - 1
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 {

+ 23 - 0
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)
+		})
+	})
 }

+ 36 - 3
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});
+    });
   }
 }
 

+ 1 - 1
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);

+ 1 - 1
public/app/plugins/panel/dashlist/editor.html

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

+ 0 - 1
public/app/plugins/panel/dashlist/module.ts

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