2017-12-19 09:06:54 -06:00
|
|
|
import appEvents from "app/core/app_events";
|
2017-12-07 12:32:38 -06:00
|
|
|
|
|
|
|
export class CreateFolderCtrl {
|
2017-12-19 09:06:54 -06:00
|
|
|
title = "";
|
2017-12-07 12:32:38 -06:00
|
|
|
navModel: any;
|
|
|
|
nameExists = false;
|
|
|
|
titleTouched = false;
|
|
|
|
|
2017-12-15 09:36:31 -06:00
|
|
|
/** @ngInject **/
|
2017-12-07 12:32:38 -06:00
|
|
|
constructor(private backendSrv, private $location, navModelSrv) {
|
2017-12-19 09:06:54 -06:00
|
|
|
this.navModel = navModelSrv.getNav("dashboards", "manage-dashboards", 0);
|
2017-12-07 12:32:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
create() {
|
|
|
|
if (!this.title || this.title.trim().length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const title = this.title.trim();
|
|
|
|
|
|
|
|
return this.backendSrv.createDashboardFolder(title).then(result => {
|
2017-12-19 09:06:54 -06:00
|
|
|
appEvents.emit("alert-success", ["Folder Created", "OK"]);
|
2017-12-07 12:32:38 -06:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
var folderUrl = `/dashboards/folder/${result.dashboard.id}/${
|
|
|
|
result.meta.slug
|
|
|
|
}`;
|
2017-12-07 12:32:38 -06:00
|
|
|
this.$location.url(folderUrl);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
titleChanged() {
|
|
|
|
this.titleTouched = true;
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
this.backendSrv.search({ query: this.title }).then(res => {
|
2017-12-07 12:32:38 -06:00
|
|
|
this.nameExists = false;
|
|
|
|
for (let hit of res) {
|
|
|
|
if (this.title === hit.title) {
|
|
|
|
this.nameExists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|