MoveToFolderCtrl.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import coreModule from 'app/core/core_module';
  2. import appEvents from 'app/core/app_events';
  3. export class MoveToFolderCtrl {
  4. dashboards: any;
  5. folder: any;
  6. dismiss: any;
  7. afterSave: any;
  8. isValidFolderSelection = true;
  9. /** @ngInject */
  10. constructor(private backendSrv) {}
  11. onFolderChange(folder) {
  12. this.folder = folder;
  13. }
  14. save() {
  15. return this.backendSrv.moveDashboards(this.dashboards, this.folder).then(result => {
  16. if (result.successCount > 0) {
  17. const header = `Dashboard${result.successCount === 1 ? '' : 's'} Moved`;
  18. const msg = `${result.successCount} dashboard${result.successCount === 1 ? '' : 's'} moved to ${
  19. this.folder.title
  20. }`;
  21. appEvents.emit('alert-success', [header, msg]);
  22. }
  23. if (result.totalCount === result.alreadyInFolderCount) {
  24. appEvents.emit('alert-error', ['Error', `Dashboards already belongs to folder ${this.folder.title}`]);
  25. }
  26. this.dismiss();
  27. return this.afterSave();
  28. });
  29. }
  30. onEnterFolderCreation() {
  31. this.isValidFolderSelection = false;
  32. }
  33. onExitFolderCreation() {
  34. this.isValidFolderSelection = true;
  35. }
  36. }
  37. export function moveToFolderModal() {
  38. return {
  39. restrict: 'E',
  40. templateUrl: 'public/app/features/manage-dashboards/components/MoveToFolderModal/template.html',
  41. controller: MoveToFolderCtrl,
  42. bindToController: true,
  43. controllerAs: 'ctrl',
  44. scope: {
  45. dismiss: '&',
  46. dashboards: '=',
  47. afterSave: '&',
  48. },
  49. };
  50. }
  51. coreModule.directive('moveToFolderModal', moveToFolderModal);