dashfolders: Folder picker should set correct default values. Fixes #10135
This commit is contained in:
@@ -134,12 +134,12 @@ export class ManageDashboardsCtrl {
|
||||
const selectedDashboards = this.getDashboardsToMove();
|
||||
|
||||
const template = '<move-to-folder-modal dismiss="dismiss()" ' +
|
||||
'dashboards="model.dashboards" after-save="model.afterSave()">' +
|
||||
'dashboards="model.dashboards" from-folder-id="model.fromFolderId" after-save="model.afterSave()">' +
|
||||
'</move-to-folder-modal>`';
|
||||
appEvents.emit('show-modal', {
|
||||
templateHtml: template,
|
||||
modalClass: 'modal--narrow',
|
||||
model: { dashboards: selectedDashboards, afterSave: this.getDashboards.bind(this) }
|
||||
model: { dashboards: selectedDashboards, fromFolderId: this.folderId ? Number(this.folderId) : 0, afterSave: this.getDashboards.bind(this) }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@ import _ from 'lodash';
|
||||
|
||||
export class FolderPickerCtrl {
|
||||
initialTitle: string;
|
||||
initialFolderId: number;
|
||||
initialFolderId?: number;
|
||||
labelClass: string;
|
||||
onChange: any;
|
||||
onLoad: any;
|
||||
rootName = 'Root';
|
||||
folder: any;
|
||||
|
||||
@@ -17,12 +18,19 @@ export class FolderPickerCtrl {
|
||||
this.labelClass = "width-7";
|
||||
}
|
||||
|
||||
if (this.initialFolderId > 0) {
|
||||
if (this.initialFolderId && this.initialFolderId > 0) {
|
||||
this.getOptions('').then(result => {
|
||||
this.folder = _.find(result, {value: this.initialFolderId});
|
||||
this.onFolderLoad();
|
||||
});
|
||||
} else {
|
||||
this.folder = {text: this.initialTitle, value: null};
|
||||
if (this.initialTitle) {
|
||||
this.folder = {text: this.initialTitle, value: null};
|
||||
} else {
|
||||
this.folder = {text: this.rootName, value: 0};
|
||||
}
|
||||
|
||||
this.onFolderLoad();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +41,12 @@ export class FolderPickerCtrl {
|
||||
};
|
||||
|
||||
return this.backendSrv.search(params).then(result => {
|
||||
if (query === "") {
|
||||
result.unshift({title: this.rootName, value: 0});
|
||||
if (query === '' ||
|
||||
query.toLowerCase() === "r" ||
|
||||
query.toLowerCase() === "ro" ||
|
||||
query.toLowerCase() === "roo" ||
|
||||
query.toLowerCase() === "root") {
|
||||
result.unshift({title: this.rootName, id: 0});
|
||||
}
|
||||
|
||||
return _.map(result, item => {
|
||||
@@ -43,6 +55,12 @@ export class FolderPickerCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
onFolderLoad() {
|
||||
if (this.onLoad) {
|
||||
this.onLoad({$folder: {id: this.folder.value, title: this.folder.text}});
|
||||
}
|
||||
}
|
||||
|
||||
onFolderChange(option) {
|
||||
this.onChange({$folder: {id: option.value, title: option.text}});
|
||||
}
|
||||
@@ -69,11 +87,12 @@ export function folderPicker() {
|
||||
bindToController: true,
|
||||
controllerAs: 'ctrl',
|
||||
scope: {
|
||||
initialTitle: "<",
|
||||
initialTitle: '<',
|
||||
initialFolderId: '<',
|
||||
labelClass: '@',
|
||||
rootName: '@',
|
||||
onChange: '&'
|
||||
onChange: '&',
|
||||
onLoad: '&'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
|
||||
<div class="p-t-2">
|
||||
<div class="gf-form">
|
||||
<folder-picker initial-title="Choose"
|
||||
<folder-picker
|
||||
on-load="ctrl.onFolderChange($folder)"
|
||||
on-change="ctrl.onFolderChange($folder)"
|
||||
label-class="width-7">
|
||||
</folder-picker>
|
||||
|
||||
@@ -7,6 +7,7 @@ export class MoveToFolderCtrl {
|
||||
folder: any;
|
||||
dismiss: any;
|
||||
afterSave: any;
|
||||
fromFolderId: number;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(private backendSrv, private $q) {}
|
||||
@@ -16,10 +17,16 @@ export class MoveToFolderCtrl {
|
||||
}
|
||||
|
||||
save() {
|
||||
if (this.folder.id === this.fromFolderId) {
|
||||
appEvents.emit('alert-error', ['Dashboard(s) already belong to this folder']);
|
||||
return;
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
for (let dash of this.dashboards) {
|
||||
const promise = this.backendSrv.get('/api/dashboards/' + dash).then(fullDash => {
|
||||
const model = new DashboardModel(fullDash.dashboard, fullDash.meta);
|
||||
|
||||
model.folderId = this.folder.id;
|
||||
model.meta.folderId = this.folder.id;
|
||||
model.meta.folderTitle = this.folder.title;
|
||||
@@ -53,6 +60,7 @@ export function moveToFolderModal() {
|
||||
scope: {
|
||||
dismiss: "&",
|
||||
dashboards: "=",
|
||||
fromFolderId: '<',
|
||||
afterSave: "&"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,9 +37,8 @@
|
||||
<bootstrap-tagsinput ng-model="ctrl.dashboard.tags" tagclass="label label-tag" placeholder="add tags">
|
||||
</bootstrap-tagsinput>
|
||||
</div>
|
||||
|
||||
<folder-picker ng-if="!ctrl.dashboard.meta.isFolder"
|
||||
initial-title="ctrl.dashboard.meta.folderTitle"
|
||||
initial-folder-id="ctrl.dashboard.folderId"
|
||||
on-change="ctrl.onFolderChange($folder)"
|
||||
label-class="width-7">
|
||||
</folder-picker>
|
||||
|
||||
@@ -22,7 +22,7 @@ const template = `
|
||||
<input type="text" class="gf-form-input" ng-model="ctrl.clone.title" give-focus="true" required>
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<folder-picker initial-title="ctrl.folderTitle"
|
||||
<folder-picker initial-folder-id="ctrl.folderId"
|
||||
on-change="ctrl.onFolderChange($folder)"
|
||||
label-class="width-7">
|
||||
</folder-picker>
|
||||
@@ -39,7 +39,7 @@ const template = `
|
||||
|
||||
export class SaveDashboardAsModalCtrl {
|
||||
clone: any;
|
||||
folderTitle: any;
|
||||
folderId: any;
|
||||
dismiss: () => void;
|
||||
|
||||
/** @ngInject */
|
||||
@@ -50,7 +50,7 @@ export class SaveDashboardAsModalCtrl {
|
||||
this.clone.title += ' Copy';
|
||||
this.clone.editable = true;
|
||||
this.clone.hideControls = false;
|
||||
this.folderTitle = dashboard.meta.folderTitle || 'Root';
|
||||
this.folderId = dashboard.folderId;
|
||||
|
||||
// remove alerts if source dashboard is already persisted
|
||||
// do not want to create alert dupes
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
<div class="section gf-form-group">
|
||||
<h5 class="section-heading">Options</h5>
|
||||
<div class="gf-form">
|
||||
<folder-picker root-name="All"
|
||||
initial-folder-id="ctrl.panel.folderId"
|
||||
<folder-picker initial-folder-id="ctrl.panel.folderId"
|
||||
on-change="ctrl.onFolderChange($folder)"
|
||||
label-class="width-6">
|
||||
</folder-picker>
|
||||
|
||||
Reference in New Issue
Block a user