瀏覽代碼

dashboard: import to folder

Alexander Zobnin 7 年之前
父節點
當前提交
4063ae37a4

+ 1 - 0
pkg/api/dtos/plugins.go

@@ -57,4 +57,5 @@ type ImportDashboardCommand struct {
 	Overwrite bool                           `json:"overwrite"`
 	Overwrite bool                           `json:"overwrite"`
 	Dashboard *simplejson.Json               `json:"dashboard"`
 	Dashboard *simplejson.Json               `json:"dashboard"`
 	Inputs    []plugins.ImportDashboardInput `json:"inputs"`
 	Inputs    []plugins.ImportDashboardInput `json:"inputs"`
+	FolderId  int64                          `json:"folderId"`
 }
 }

+ 1 - 0
pkg/api/plugins.go

@@ -174,6 +174,7 @@ func ImportDashboard(c *m.ReqContext, apiCmd dtos.ImportDashboardCommand) Respon
 		Path:      apiCmd.Path,
 		Path:      apiCmd.Path,
 		Inputs:    apiCmd.Inputs,
 		Inputs:    apiCmd.Inputs,
 		Overwrite: apiCmd.Overwrite,
 		Overwrite: apiCmd.Overwrite,
+		FolderId:  apiCmd.FolderId,
 		Dashboard: apiCmd.Dashboard,
 		Dashboard: apiCmd.Dashboard,
 	}
 	}
 
 

+ 3 - 1
pkg/plugins/dashboard_importer.go

@@ -16,6 +16,7 @@ type ImportDashboardCommand struct {
 	Path      string
 	Path      string
 	Inputs    []ImportDashboardInput
 	Inputs    []ImportDashboardInput
 	Overwrite bool
 	Overwrite bool
+	FolderId  int64
 
 
 	OrgId    int64
 	OrgId    int64
 	User     *m.SignedInUser
 	User     *m.SignedInUser
@@ -70,7 +71,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
 		UserId:    cmd.User.UserId,
 		UserId:    cmd.User.UserId,
 		Overwrite: cmd.Overwrite,
 		Overwrite: cmd.Overwrite,
 		PluginId:  cmd.PluginId,
 		PluginId:  cmd.PluginId,
-		FolderId:  dashboard.FolderId,
+		FolderId:  cmd.FolderId,
 	}
 	}
 
 
 	dto := &dashboards.SaveDashboardDTO{
 	dto := &dashboards.SaveDashboardDTO{
@@ -91,6 +92,7 @@ func ImportDashboard(cmd *ImportDashboardCommand) error {
 		Title:            savedDash.Title,
 		Title:            savedDash.Title,
 		Path:             cmd.Path,
 		Path:             cmd.Path,
 		Revision:         savedDash.Data.Get("revision").MustInt64(1),
 		Revision:         savedDash.Data.Get("revision").MustInt64(1),
+		FolderId:         savedDash.FolderId,
 		ImportedUri:      "db/" + savedDash.Slug,
 		ImportedUri:      "db/" + savedDash.Slug,
 		ImportedUrl:      savedDash.GetUrl(),
 		ImportedUrl:      savedDash.GetUrl(),
 		ImportedRevision: dashboard.Data.Get("revision").MustInt64(1),
 		ImportedRevision: dashboard.Data.Get("revision").MustInt64(1),

+ 1 - 0
pkg/plugins/dashboards.go

@@ -17,6 +17,7 @@ type PluginDashboardInfoDTO struct {
 	ImportedUrl      string `json:"importedUrl"`
 	ImportedUrl      string `json:"importedUrl"`
 	Slug             string `json:"slug"`
 	Slug             string `json:"slug"`
 	DashboardId      int64  `json:"dashboardId"`
 	DashboardId      int64  `json:"dashboardId"`
+	FolderId         int64  `json:"folderId"`
 	ImportedRevision int64  `json:"importedRevision"`
 	ImportedRevision int64  `json:"importedRevision"`
 	Revision         int64  `json:"revision"`
 	Revision         int64  `json:"revision"`
 	Description      string `json:"description"`
 	Description      string `json:"description"`

+ 18 - 1
public/app/features/dashboard/dashboard_import_ctrl.ts

@@ -21,6 +21,8 @@ export class DashboardImportCtrl {
   uidValidationError: any;
   uidValidationError: any;
   autoGenerateUid: boolean;
   autoGenerateUid: boolean;
   autoGenerateUidValue: string;
   autoGenerateUidValue: string;
+  folderId: number;
+  isValidFolderSelection: boolean;
 
 
   /** @ngInject */
   /** @ngInject */
   constructor(private backendSrv, private validationSrv, navModelSrv, private $location, $routeParams) {
   constructor(private backendSrv, private validationSrv, navModelSrv, private $location, $routeParams) {
@@ -31,6 +33,7 @@ export class DashboardImportCtrl {
     this.uidExists = false;
     this.uidExists = false;
     this.autoGenerateUid = true;
     this.autoGenerateUid = true;
     this.autoGenerateUidValue = 'auto-generated';
     this.autoGenerateUidValue = 'auto-generated';
+    this.folderId = 0;
 
 
     // check gnetId in url
     // check gnetId in url
     if ($routeParams.gnetId) {
     if ($routeParams.gnetId) {
@@ -102,7 +105,7 @@ export class DashboardImportCtrl {
     this.nameExists = false;
     this.nameExists = false;
 
 
     this.validationSrv
     this.validationSrv
-      .validateNewDashboardName(0, this.dash.title)
+      .validateNewDashboardName(this.folderId, this.dash.title)
       .then(() => {
       .then(() => {
         this.hasNameValidationError = false;
         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() {
   saveDashboard() {
     var inputs = this.inputs.map(input => {
     var inputs = this.inputs.map(input => {
       return {
       return {
@@ -153,6 +169,7 @@ export class DashboardImportCtrl {
         dashboard: this.dash,
         dashboard: this.dash,
         overwrite: true,
         overwrite: true,
         inputs: inputs,
         inputs: inputs,
+        folderId: this.folderId,
       })
       })
       .then(res => {
       .then(res => {
         this.$location.url(res.importedUrl);
         this.$location.url(res.importedUrl);

+ 12 - 0
public/app/features/dashboard/partials/dashboard_import.html

@@ -80,6 +80,18 @@
         </div>
         </div>
       </div>
       </div>
 
 
+      <div class="gf-form-inline">
+        <div class="gf-form gf-form--grow">
+          <folder-picker initial-folder-id="ctrl.folderId"
+            on-change="ctrl.onFolderChange($folder)"
+            enter-folder-creation="ctrl.onEnterFolderCreation()"
+            exit-folder-creation="ctrl.onExitFolderCreation()"
+            enable-create-new="true"
+            label-class="width-15">
+          </folder-picker>
+        </div>
+      </div>
+
       <div class="gf-form-inline">
       <div class="gf-form-inline">
         <div class="gf-form gf-form--grow">
         <div class="gf-form gf-form--grow">
           <span class="gf-form-label width-15">
           <span class="gf-form-label width-15">