save_as_modal.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import coreModule from 'app/core/core_module';
  2. const template = `
  3. <div class="modal-body">
  4. <div class="modal-header">
  5. <h2 class="modal-header-title">
  6. <i class="fa fa-copy"></i>
  7. <span class="p-l-1">Save As...</span>
  8. </h2>
  9. <a class="modal-header-close" ng-click="ctrl.dismiss();">
  10. <i class="fa fa-remove"></i>
  11. </a>
  12. </div>
  13. <form name="ctrl.saveForm" class="modal-content" novalidate>
  14. <div class="p-t-2">
  15. <div class="gf-form">
  16. <label class="gf-form-label width-7">New name</label>
  17. <input type="text" class="gf-form-input" ng-model="ctrl.clone.title" give-focus="true" required>
  18. </div>
  19. <div class="gf-form">
  20. <folder-picker initial-folder-id="ctrl.folderId"
  21. on-change="ctrl.onFolderChange($folder)"
  22. enable-create-new="true"
  23. label-class="width-7">
  24. </folder-picker>
  25. </div>
  26. </div>
  27. <div class="gf-form-button-row text-center">
  28. <button type="submit" class="btn btn-success" ng-click="ctrl.save()">Save</button>
  29. <a class="btn-text" ng-click="ctrl.dismiss();">Cancel</a>
  30. </div>
  31. </form>
  32. </div>
  33. `;
  34. export class SaveDashboardAsModalCtrl {
  35. clone: any;
  36. folderId: any;
  37. dismiss: () => void;
  38. /** @ngInject */
  39. constructor(private dashboardSrv) {
  40. var dashboard = this.dashboardSrv.getCurrent();
  41. this.clone = dashboard.getSaveModelClone();
  42. this.clone.id = null;
  43. this.clone.uid = '';
  44. this.clone.title += ' Copy';
  45. this.clone.editable = true;
  46. this.clone.hideControls = false;
  47. this.folderId = dashboard.meta.folderId;
  48. // remove alerts if source dashboard is already persisted
  49. // do not want to create alert dupes
  50. if (dashboard.id > 0) {
  51. this.clone.panels.forEach(panel => {
  52. if (panel.type === 'graph' && panel.alert) {
  53. delete panel.thresholds;
  54. }
  55. delete panel.alert;
  56. });
  57. }
  58. delete this.clone.autoUpdate;
  59. }
  60. save() {
  61. return this.dashboardSrv.save(this.clone, { folderId: this.folderId }).then(this.dismiss);
  62. }
  63. keyDown(evt) {
  64. if (evt.keyCode === 13) {
  65. this.save();
  66. }
  67. }
  68. onFolderChange(folder) {
  69. this.folderId = folder.id;
  70. }
  71. }
  72. export function saveDashboardAsDirective() {
  73. return {
  74. restrict: 'E',
  75. template: template,
  76. controller: SaveDashboardAsModalCtrl,
  77. bindToController: true,
  78. controllerAs: 'ctrl',
  79. scope: { dismiss: '&' },
  80. };
  81. }
  82. coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective);