diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go index a3db71afb04..23ad22e53c1 100644 --- a/pkg/services/sqlstore/dashboard.go +++ b/pkg/services/sqlstore/dashboard.go @@ -25,7 +25,7 @@ func init() { func SaveDashboard(cmd *m.SaveDashboardCommand) error { return inTransaction(func(sess *DBSession) error { dash := cmd.GetDashboardModel() - + fmt.Printf("ParentId: %v", dash.ParentId) // try get existing dashboard var existing, sameTitle m.Dashboard @@ -81,7 +81,7 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error { } else { dash.Version += 1 dash.Data.Set("version", dash.Version) - affectedRows, err = sess.Id(dash.Id).Update(dash) + affectedRows, err = sess.MustCols("parent_id").Id(dash.Id).Update(dash) } if err != nil { diff --git a/pkg/services/sqlstore/dashboard_test.go b/pkg/services/sqlstore/dashboard_test.go index b537762ab92..98dfc9eac40 100644 --- a/pkg/services/sqlstore/dashboard_test.go +++ b/pkg/services/sqlstore/dashboard_test.go @@ -191,6 +191,46 @@ func TestDashboardDataAccess(t *testing.T) { So(err, ShouldNotBeNil) }) + Convey("Should be able to update dashboard and remove parentId", func() { + cmd := m.SaveDashboardCommand{ + OrgId: 1, + Dashboard: simplejson.NewFromAny(map[string]interface{}{ + "id": 1, + "title": "parentId", + "tags": []interface{}{}, + }), + Overwrite: true, + ParentId: 2, + } + + err := SaveDashboard(&cmd) + So(err, ShouldBeNil) + So(cmd.Result.ParentId, ShouldEqual, 2) + + cmd = m.SaveDashboardCommand{ + OrgId: 1, + Dashboard: simplejson.NewFromAny(map[string]interface{}{ + "id": 1, + "title": "parentId", + "tags": []interface{}{}, + }), + ParentId: 0, + Overwrite: true, + } + + err = SaveDashboard(&cmd) + So(err, ShouldBeNil) + + query := m.GetDashboardQuery{ + Slug: cmd.Result.Slug, + OrgId: 1, + } + + err = GetDashboard(&query) + So(err, ShouldBeNil) + So(query.Result.ParentId, ShouldEqual, 0) + }) + Convey("Should be able to get dashboard tags", func() { query := m.GetDashboardTagsQuery{OrgId: 1} diff --git a/public/app/features/dashboard/folder_picker/picker.ts b/public/app/features/dashboard/folder_picker/picker.ts index 8140743f78a..6d718d75011 100644 --- a/public/app/features/dashboard/folder_picker/picker.ts +++ b/public/app/features/dashboard/folder_picker/picker.ts @@ -6,13 +6,14 @@ import _ from 'lodash'; export class FolderPickerCtrl { dashboard: any; - folders: any[]; + folders: Folder[]; selectedFolder: number; /** @ngInject */ constructor(private backendSrv, private $scope, $sce) { this.get(this.dashboard.id); this.selectedFolder = this.dashboard.meta.parentId; + this.folders = [{id: 0, title: 'Root', type: 'dash-folder'}]; } get(dashboardId: number) { @@ -21,17 +22,26 @@ export class FolderPickerCtrl { }; return this.backendSrv.search(params).then(result => { - this.folders = result; + this.folders.push(...result); }); } folderChanged() { - if (this.selectedFolder > 0) { - this.dashboard.parentId = this.selectedFolder; - } + this.dashboard.parentId = this.selectedFolder; } } +export interface Folder { + id: number; + title: string; + uri?: string; + type: string; + tags?: string[]; + isStarred?: boolean; + parentId?: number; + dashboards?: any; +} + export function folderPicker() { return { restrict: 'E', diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index b451139fd8b..d3df6095e3f 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -45,7 +45,7 @@ - +