import coreModule from 'app/core/core_module'; const template = `
`; export class SaveDashboardAsModalCtrl { clone: any; folderId: any; dismiss: () => void; isValidFolderSelection = true; /** @ngInject */ constructor(private dashboardSrv) { const dashboard = this.dashboardSrv.getCurrent(); this.clone = dashboard.getSaveModelClone(); this.clone.id = null; this.clone.uid = ''; this.clone.title += ' Copy'; this.clone.editable = true; this.clone.hideControls = false; this.folderId = dashboard.meta.folderId; // remove alerts if source dashboard is already persisted // do not want to create alert dupes if (dashboard.id > 0) { this.clone.panels.forEach(panel => { if (panel.type === 'graph' && panel.alert) { delete panel.thresholds; } delete panel.alert; }); } delete this.clone.autoUpdate; } save() { return this.dashboardSrv.save(this.clone, { folderId: this.folderId }).then(this.dismiss); } keyDown(evt) { if (evt.keyCode === 13) { this.save(); } } onFolderChange(folder) { this.folderId = folder.id; } onEnterFolderCreation() { this.isValidFolderSelection = false; } onExitFolderCreation() { this.isValidFolderSelection = true; } } export function saveDashboardAsDirective() { return { restrict: 'E', template: template, controller: SaveDashboardAsModalCtrl, bindToController: true, controllerAs: 'ctrl', scope: { dismiss: '&' }, }; } coreModule.directive('saveDashboardAsModal', saveDashboardAsDirective);