MoveToFolderCtrl.ts 1.6 KB

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