2017-12-20 12:33:33 +01:00
|
|
|
import appEvents from 'app/core/app_events';
|
2017-12-07 19:32:38 +01:00
|
|
|
|
|
|
|
|
export class CreateFolderCtrl {
|
2017-12-20 12:33:33 +01:00
|
|
|
title = '';
|
2017-12-07 19:32:38 +01:00
|
|
|
navModel: any;
|
|
|
|
|
titleTouched = false;
|
2017-12-19 13:39:10 +01:00
|
|
|
hasValidationError: boolean;
|
|
|
|
|
validationError: any;
|
2017-12-07 19:32:38 +01:00
|
|
|
|
2017-12-15 16:36:31 +01:00
|
|
|
/** @ngInject **/
|
2017-12-21 08:39:31 +01:00
|
|
|
constructor(private backendSrv, private $location, private validationSrv, navModelSrv) {
|
2017-12-19 13:39:10 +01:00
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'manage-dashboards', 0);
|
2017-12-07 19:32:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create() {
|
2017-12-19 13:39:10 +01:00
|
|
|
if (this.hasValidationError) {
|
2017-12-07 19:32:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 13:39:10 +01:00
|
|
|
return this.backendSrv.createDashboardFolder(this.title).then(result => {
|
|
|
|
|
appEvents.emit('alert-success', ['Folder Created', 'OK']);
|
2017-12-07 19:32:38 +01:00
|
|
|
|
2017-12-31 12:24:21 +01:00
|
|
|
var folderUrl = `dashboards/folder/${result.dashboard.id}/${result.meta.slug}`;
|
2017-12-07 19:32:38 +01:00
|
|
|
this.$location.url(folderUrl);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
titleChanged() {
|
|
|
|
|
this.titleTouched = true;
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
this.validationSrv
|
|
|
|
|
.validateNewDashboardOrFolderName(this.title)
|
2017-12-19 13:39:10 +01:00
|
|
|
.then(() => {
|
|
|
|
|
this.hasValidationError = false;
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
this.hasValidationError = true;
|
|
|
|
|
this.validationError = err.message;
|
|
|
|
|
});
|
2017-12-07 19:32:38 +01:00
|
|
|
}
|
|
|
|
|
}
|