diff --git a/pkg/api/dtos/plugins.go b/pkg/api/dtos/plugins.go index f4281f877b3..78a611c5eeb 100644 --- a/pkg/api/dtos/plugins.go +++ b/pkg/api/dtos/plugins.go @@ -57,4 +57,5 @@ type ImportDashboardCommand struct { Overwrite bool `json:"overwrite"` Dashboard *simplejson.Json `json:"dashboard"` Inputs []plugins.ImportDashboardInput `json:"inputs"` + FolderId int64 `json:"folderId"` } diff --git a/pkg/api/plugins.go b/pkg/api/plugins.go index f757f2b9adc..4b44009ab8c 100644 --- a/pkg/api/plugins.go +++ b/pkg/api/plugins.go @@ -174,6 +174,7 @@ func ImportDashboard(c *m.ReqContext, apiCmd dtos.ImportDashboardCommand) Respon Path: apiCmd.Path, Inputs: apiCmd.Inputs, Overwrite: apiCmd.Overwrite, + FolderId: apiCmd.FolderId, Dashboard: apiCmd.Dashboard, } diff --git a/pkg/plugins/dashboard_importer.go b/pkg/plugins/dashboard_importer.go index 1364fded987..9b319358780 100644 --- a/pkg/plugins/dashboard_importer.go +++ b/pkg/plugins/dashboard_importer.go @@ -16,6 +16,7 @@ type ImportDashboardCommand struct { Path string Inputs []ImportDashboardInput Overwrite bool + FolderId int64 OrgId int64 User *m.SignedInUser @@ -70,7 +71,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error { UserId: cmd.User.UserId, Overwrite: cmd.Overwrite, PluginId: cmd.PluginId, - FolderId: dashboard.FolderId, + FolderId: cmd.FolderId, } dto := &dashboards.SaveDashboardDTO{ @@ -91,6 +92,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error { Title: savedDash.Title, Path: cmd.Path, Revision: savedDash.Data.Get("revision").MustInt64(1), + FolderId: savedDash.FolderId, ImportedUri: "db/" + savedDash.Slug, ImportedUrl: savedDash.GetUrl(), ImportedRevision: dashboard.Data.Get("revision").MustInt64(1), diff --git a/pkg/plugins/dashboards.go b/pkg/plugins/dashboards.go index d15bcdd6db5..500d97e38ca 100644 --- a/pkg/plugins/dashboards.go +++ b/pkg/plugins/dashboards.go @@ -17,6 +17,7 @@ type PluginDashboardInfoDTO struct { ImportedUrl string `json:"importedUrl"` Slug string `json:"slug"` DashboardId int64 `json:"dashboardId"` + FolderId int64 `json:"folderId"` ImportedRevision int64 `json:"importedRevision"` Revision int64 `json:"revision"` Description string `json:"description"` diff --git a/public/app/features/dashboard/dashboard_import_ctrl.ts b/public/app/features/dashboard/dashboard_import_ctrl.ts index fe61d3f7a55..7764bb4815f 100644 --- a/public/app/features/dashboard/dashboard_import_ctrl.ts +++ b/public/app/features/dashboard/dashboard_import_ctrl.ts @@ -21,6 +21,8 @@ export class DashboardImportCtrl { uidValidationError: any; autoGenerateUid: boolean; autoGenerateUidValue: string; + folderId: number; + isValidFolderSelection: boolean; /** @ngInject */ constructor(private backendSrv, private validationSrv, navModelSrv, private $location, $routeParams) { @@ -31,6 +33,7 @@ export class DashboardImportCtrl { this.uidExists = false; this.autoGenerateUid = true; this.autoGenerateUidValue = 'auto-generated'; + this.folderId = 0; // check gnetId in url if ($routeParams.gnetId) { @@ -102,7 +105,7 @@ export class DashboardImportCtrl { this.nameExists = false; this.validationSrv - .validateNewDashboardName(0, this.dash.title) + .validateNewDashboardName(this.folderId, this.dash.title) .then(() => { this.hasNameValidationError = false; }) @@ -138,6 +141,19 @@ export class DashboardImportCtrl { }); } + onFolderChange(folder) { + this.folderId = folder.id; + this.titleChanged(); + } + + onEnterFolderCreation() { + this.inputsValid = false; + } + + onExitFolderCreation() { + this.inputsValid = true; + } + saveDashboard() { var inputs = this.inputs.map(input => { return { @@ -153,6 +169,7 @@ export class DashboardImportCtrl { dashboard: this.dash, overwrite: true, inputs: inputs, + folderId: this.folderId, }) .then(res => { this.$location.url(res.importedUrl); diff --git a/public/app/features/dashboard/partials/dashboard_import.html b/public/app/features/dashboard/partials/dashboard_import.html index 51011ae2c3d..b0f3568148d 100644 --- a/public/app/features/dashboard/partials/dashboard_import.html +++ b/public/app/features/dashboard/partials/dashboard_import.html @@ -80,6 +80,18 @@ +
+
+ + +
+
+