save_as_modal.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.title += ' Copy';
  44. this.clone.editable = true;
  45. this.clone.hideControls = false;
  46. this.folderId = dashboard.meta.folderId;
  47. // remove alerts if source dashboard is already persisted
  48. // do not want to create alert dupes
  49. if (dashboard.id > 0) {
  50. this.clone.panels.forEach(panel => {
  51. if (panel.type === 'graph' && panel.alert) {
  52. delete panel.thresholds;
  53. }
  54. delete panel.alert;
  55. });
  56. }
  57. delete this.clone.autoUpdate;
  58. }
  59. save() {
  60. return this.dashboardSrv.save(this.clone, { folderId: this.folderId }).then(this.dismiss);
  61. }
  62. keyDown(evt) {
  63. if (evt.keyCode === 13) {
  64. this.save();
  65. }
  66. }
  67. onFolderChange(folder) {
  68. this.folderId = folder.id;
  69. }
  70. }
  71. export function saveDashboardAsDirective() {
  72. return {
  73. restrict: 'E',
  74. template: template,
  75. controller: SaveDashboardAsModalCtrl,
  76. bindToController: true,
  77. controllerAs: 'ctrl',
  78. scope: { dismiss: '&' },
  79. };
  80. }
  81. coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective);