save_as_modal.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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" ng-submit="ctrl.save()" 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. label-class="width-7">
  23. </folder-picker>
  24. </div>
  25. </div>
  26. <div class="gf-form-button-row text-center">
  27. <button type="submit" class="btn btn-success" ng-disabled="ctrl.saveForm.$invalid">Save</button>
  28. <a class="btn-text" ng-click="ctrl.dismiss();">Cancel</a>
  29. </div>
  30. </form>
  31. </div>
  32. `;
  33. export class SaveDashboardAsModalCtrl {
  34. clone: any;
  35. folderId: any;
  36. dismiss: () => void;
  37. /** @ngInject */
  38. constructor(private dashboardSrv) {
  39. var dashboard = this.dashboardSrv.getCurrent();
  40. this.clone = dashboard.getSaveModelClone();
  41. this.clone.id = null;
  42. this.clone.title += ' Copy';
  43. this.clone.editable = true;
  44. this.clone.hideControls = false;
  45. this.folderId = dashboard.folderId;
  46. // remove alerts if source dashboard is already persisted
  47. // do not want to create alert dupes
  48. if (dashboard.id > 0) {
  49. this.clone.panels.forEach(panel => {
  50. if (panel.type === "graph" && panel.alert) {
  51. delete panel.thresholds;
  52. }
  53. delete panel.alert;
  54. });
  55. }
  56. delete this.clone.autoUpdate;
  57. }
  58. save() {
  59. return this.dashboardSrv.save(this.clone).then(this.dismiss);
  60. }
  61. keyDown(evt) {
  62. if (evt.keyCode === 13) {
  63. this.save();
  64. }
  65. }
  66. onFolderChange(folder) {
  67. this.clone.folderId = folder.id;
  68. }
  69. }
  70. export function saveDashboardAsDirective() {
  71. return {
  72. restrict: 'E',
  73. template: template,
  74. controller: SaveDashboardAsModalCtrl,
  75. bindToController: true,
  76. controllerAs: 'ctrl',
  77. scope: {dismiss: "&"}
  78. };
  79. }
  80. coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective);