dashboard: import to folder

This commit is contained in:
Alexander Zobnin 2018-06-04 21:29:14 +03:00
parent d09749eaaa
commit 4063ae37a4
No known key found for this signature in database
GPG Key ID: E17E9ABACEFA59EB
6 changed files with 36 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -80,6 +80,18 @@
</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 gf-form--grow">
<span class="gf-form-label width-15">