create_folder_ctrl.ts 995 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import appEvents from 'app/core/app_events';
  2. export class CreateFolderCtrl {
  3. title = '';
  4. navModel: any;
  5. nameExists = false;
  6. titleTouched = false;
  7. constructor(private backendSrv, private $location, navModelSrv) {
  8. this.navModel = navModelSrv.getNav('dashboards', 'manage-dashboards', 0);
  9. }
  10. create() {
  11. if (!this.title || this.title.trim().length === 0) {
  12. return;
  13. }
  14. const title = this.title.trim();
  15. return this.backendSrv.createDashboardFolder(title).then(result => {
  16. appEvents.emit('alert-success', ['Folder Created', 'OK']);
  17. var folderUrl = `/dashboards/folder/${result.id}/db/${result.slug}`;
  18. this.$location.url(folderUrl);
  19. });
  20. }
  21. titleChanged() {
  22. this.titleTouched = true;
  23. this.backendSrv.search({query: this.title}).then(res => {
  24. this.nameExists = false;
  25. for (let hit of res) {
  26. if (this.title === hit.title) {
  27. this.nameExists = true;
  28. break;
  29. }
  30. }
  31. });
  32. }
  33. }