|
|
@@ -1,8 +1,6 @@
|
|
|
-///<reference path="../../../headers/common.d.ts" />
|
|
|
-
|
|
|
-import _ from 'lodash';
|
|
|
-import coreModule from 'app/core/core_module';
|
|
|
-import appEvents from 'app/core/app_events';
|
|
|
+import _ from "lodash";
|
|
|
+import coreModule from "app/core/core_module";
|
|
|
+import appEvents from "app/core/app_events";
|
|
|
|
|
|
export class FolderPickerCtrl {
|
|
|
initialTitle: string;
|
|
|
@@ -14,7 +12,7 @@ export class FolderPickerCtrl {
|
|
|
enterFolderCreation: any;
|
|
|
exitFolderCreation: any;
|
|
|
enableCreateNew: boolean;
|
|
|
- rootName = 'Root';
|
|
|
+ rootName = "Root";
|
|
|
folder: any;
|
|
|
createNewFolder: boolean;
|
|
|
newFolderName: string;
|
|
|
@@ -34,24 +32,26 @@ export class FolderPickerCtrl {
|
|
|
getOptions(query) {
|
|
|
var params = {
|
|
|
query: query,
|
|
|
- type: 'dash-folder',
|
|
|
+ type: "dash-folder"
|
|
|
};
|
|
|
|
|
|
return this.backendSrv.search(params).then(result => {
|
|
|
- if (query === '' ||
|
|
|
- query.toLowerCase() === "r" ||
|
|
|
- query.toLowerCase() === "ro" ||
|
|
|
- query.toLowerCase() === "roo" ||
|
|
|
- query.toLowerCase() === "root") {
|
|
|
- result.unshift({title: this.rootName, id: 0});
|
|
|
+ if (
|
|
|
+ query === "" ||
|
|
|
+ query.toLowerCase() === "r" ||
|
|
|
+ query.toLowerCase() === "ro" ||
|
|
|
+ query.toLowerCase() === "roo" ||
|
|
|
+ query.toLowerCase() === "root"
|
|
|
+ ) {
|
|
|
+ result.unshift({ title: this.rootName, id: 0 });
|
|
|
}
|
|
|
|
|
|
- if (this.enableCreateNew && query === '') {
|
|
|
- result.unshift({title: '-- New Folder --', id: -1});
|
|
|
+ if (this.enableCreateNew && query === "") {
|
|
|
+ result.unshift({ title: "-- New Folder --", id: -1 });
|
|
|
}
|
|
|
|
|
|
return _.map(result, item => {
|
|
|
- return {text: item.title, value: item.id};
|
|
|
+ return { text: item.title, value: item.id };
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
@@ -62,13 +62,14 @@ export class FolderPickerCtrl {
|
|
|
this.enterFolderCreation();
|
|
|
return;
|
|
|
}
|
|
|
- this.onChange({$folder: {id: option.value, title: option.text}});
|
|
|
+ this.onChange({ $folder: { id: option.value, title: option.text } });
|
|
|
}
|
|
|
|
|
|
newFolderNameChanged() {
|
|
|
this.newFolderNameTouched = true;
|
|
|
|
|
|
- this.validationSrv.validateNewDashboardOrFolderName(this.newFolderName)
|
|
|
+ this.validationSrv
|
|
|
+ .validateNewDashboardOrFolderName(this.newFolderName)
|
|
|
.then(() => {
|
|
|
this.hasValidationError = false;
|
|
|
})
|
|
|
@@ -84,13 +85,18 @@ export class FolderPickerCtrl {
|
|
|
evt.preventDefault();
|
|
|
}
|
|
|
|
|
|
- return this.backendSrv.createDashboardFolder(this.newFolderName).then(result => {
|
|
|
- appEvents.emit('alert-success', ['Folder Created', 'OK']);
|
|
|
-
|
|
|
- this.closeCreateFolder();
|
|
|
- this.folder = {text: result.dashboard.title, value: result.dashboard.id};
|
|
|
- this.onFolderChange(this.folder);
|
|
|
- });
|
|
|
+ return this.backendSrv
|
|
|
+ .createDashboardFolder(this.newFolderName)
|
|
|
+ .then(result => {
|
|
|
+ appEvents.emit("alert-success", ["Folder Created", "OK"]);
|
|
|
+
|
|
|
+ this.closeCreateFolder();
|
|
|
+ this.folder = {
|
|
|
+ text: result.dashboard.title,
|
|
|
+ value: result.dashboard.id
|
|
|
+ };
|
|
|
+ this.onFolderChange(this.folder);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
cancelCreateFolder(evt) {
|
|
|
@@ -108,21 +114,21 @@ export class FolderPickerCtrl {
|
|
|
this.createNewFolder = false;
|
|
|
this.hasValidationError = false;
|
|
|
this.validationError = null;
|
|
|
- this.newFolderName = '';
|
|
|
+ this.newFolderName = "";
|
|
|
this.newFolderNameTouched = false;
|
|
|
}
|
|
|
|
|
|
private loadInitialValue() {
|
|
|
if (this.initialFolderId && this.initialFolderId > 0) {
|
|
|
- this.getOptions('').then(result => {
|
|
|
- this.folder = _.find(result, {value: this.initialFolderId});
|
|
|
+ this.getOptions("").then(result => {
|
|
|
+ this.folder = _.find(result, { value: this.initialFolderId });
|
|
|
this.onFolderLoad();
|
|
|
});
|
|
|
} else {
|
|
|
if (this.initialTitle) {
|
|
|
- this.folder = {text: this.initialTitle, value: null};
|
|
|
+ this.folder = { text: this.initialTitle, value: null };
|
|
|
} else {
|
|
|
- this.folder = {text: this.rootName, value: 0};
|
|
|
+ this.folder = { text: this.rootName, value: 0 };
|
|
|
}
|
|
|
|
|
|
this.onFolderLoad();
|
|
|
@@ -131,31 +137,34 @@ export class FolderPickerCtrl {
|
|
|
|
|
|
private onFolderLoad() {
|
|
|
if (this.onLoad) {
|
|
|
- this.onLoad({$folder: {id: this.folder.value, title: this.folder.text}});
|
|
|
+ this.onLoad({
|
|
|
+ $folder: { id: this.folder.value, title: this.folder.text }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function folderPicker() {
|
|
|
return {
|
|
|
- restrict: 'E',
|
|
|
- templateUrl: 'public/app/features/dashboard/folder_picker/folder_picker.html',
|
|
|
+ restrict: "E",
|
|
|
+ templateUrl:
|
|
|
+ "public/app/features/dashboard/folder_picker/folder_picker.html",
|
|
|
controller: FolderPickerCtrl,
|
|
|
bindToController: true,
|
|
|
- controllerAs: 'ctrl',
|
|
|
+ controllerAs: "ctrl",
|
|
|
scope: {
|
|
|
- initialTitle: '<',
|
|
|
- initialFolderId: '<',
|
|
|
- labelClass: '@',
|
|
|
- rootName: '@',
|
|
|
- onChange: '&',
|
|
|
- onLoad: '&',
|
|
|
- onCreateFolder: '&',
|
|
|
- enterFolderCreation: '&',
|
|
|
- exitFolderCreation: '&',
|
|
|
- enableCreateNew: '@'
|
|
|
+ initialTitle: "<",
|
|
|
+ initialFolderId: "<",
|
|
|
+ labelClass: "@",
|
|
|
+ rootName: "@",
|
|
|
+ onChange: "&",
|
|
|
+ onLoad: "&",
|
|
|
+ onCreateFolder: "&",
|
|
|
+ enterFolderCreation: "&",
|
|
|
+ exitFolderCreation: "&",
|
|
|
+ enableCreateNew: "@"
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-coreModule.directive('folderPicker', folderPicker);
|
|
|
+coreModule.directive("folderPicker", folderPicker);
|