From 609f3c1c9d30662cd8fddfbcce2d43b23cb30080 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Thu, 22 Feb 2018 18:02:29 +0100 Subject: [PATCH] dashboards: fix keyboard shortcut for remove panel --- public/app/core/services/keybindingSrv.ts | 5 ++- .../app/features/dashboard/dashboard_ctrl.ts | 39 +++++++++++++++++++ public/app/features/panel/panel_ctrl.ts | 29 ++------------ 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index 6f7a48f61d5..d0e74698e3f 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -171,8 +171,9 @@ export class KeybindingSrv { // delete panel this.bind('p r', () => { if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) { - var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId); - panelInfo.row.removePanel(panelInfo.panel); + this.$rootScope.appEvent('panel-remove', { + panelId: dashboard.meta.focusPanelId, + }); dashboard.meta.focusPanelId = 0; } }); diff --git a/public/app/features/dashboard/dashboard_ctrl.ts b/public/app/features/dashboard/dashboard_ctrl.ts index 8b1c69ef7fe..94d0b18f157 100644 --- a/public/app/features/dashboard/dashboard_ctrl.ts +++ b/public/app/features/dashboard/dashboard_ctrl.ts @@ -3,6 +3,7 @@ import config from 'app/core/config'; import coreModule from 'app/core/core_module'; import { PanelContainer } from './dashgrid/PanelContainer'; import { DashboardModel } from './dashboard_model'; +import { PanelModel } from './panel_model'; export class DashboardCtrl implements PanelContainer { dashboard: DashboardModel; @@ -130,9 +131,47 @@ export class DashboardCtrl implements PanelContainer { return this; } + onRemovingPanel(evt, options) { + options = options || {}; + if (!options.panelId) { + return; + } + + var panelInfo = this.dashboard.getPanelInfoById(options.panelId); + this.removePanel(panelInfo.panel, true); + } + + removePanel(panel: PanelModel, ask: boolean) { + // confirm deletion + if (ask !== false) { + var text2, confirmText; + + if (panel.alert) { + text2 = 'Panel includes an alert rule, removing panel will also remove alert rule'; + confirmText = 'YES'; + } + + this.$scope.appEvent('confirm-modal', { + title: 'Remove Panel', + text: 'Are you sure you want to remove this panel?', + text2: text2, + icon: 'fa-trash', + confirmText: confirmText, + yesText: 'Remove', + onConfirm: () => { + this.removePanel(panel, false); + }, + }); + return; + } + + this.dashboard.removePanel(panel); + } + init(dashboard) { this.$scope.onAppEvent('show-json-editor', this.showJsonEditor.bind(this)); this.$scope.onAppEvent('template-variable-value-updated', this.templateVariableUpdated.bind(this)); + this.$scope.onAppEvent('panel-remove', this.onRemovingPanel.bind(this)); this.setupDashboard(dashboard); } } diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index d8757f49be6..429408ed803 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -241,31 +241,10 @@ export class PanelCtrl { }); } - removePanel(ask: boolean) { - // confirm deletion - if (ask !== false) { - var text2, confirmText; - - if (this.panel.alert) { - text2 = 'Panel includes an alert rule, removing panel will also remove alert rule'; - confirmText = 'YES'; - } - - appEvents.emit('confirm-modal', { - title: 'Remove Panel', - text: 'Are you sure you want to remove this panel?', - text2: text2, - icon: 'fa-trash', - confirmText: confirmText, - yesText: 'Remove', - onConfirm: () => { - this.removePanel(false); - }, - }); - return; - } - - this.dashboard.removePanel(this.panel); + removePanel() { + this.publishAppEvent('panel-remove', { + panelId: this.panel.id, + }); } editPanelJson() {