diff --git a/public/app/features/dashboard/dashgrid/dashgrid.ts b/public/app/features/dashboard/dashgrid/dashgrid.ts index c596c916d43..ec2b51cf628 100644 --- a/public/app/features/dashboard/dashgrid/dashgrid.ts +++ b/public/app/features/dashboard/dashgrid/dashgrid.ts @@ -60,6 +60,10 @@ export class GridCtrl { bindItem(element) { this.gridstack.makeWidget(element); } + + removeItem(element) { + this.gridstack.removeWidget(element, false); + } } /** @ngInject **/ @@ -115,6 +119,13 @@ export function dashGridItem($timeout, $rootScope) { element.addClass('panel-fullscreen'); }, scope); + scope.$on('$destroy', () => { + gridCtrl.removeItem(element); + }); + + // scope.onItemRemoved({item: item}); + // ctrl.removeItem(element); + //var item = element.data('_gridstack_node'); //console.log('link item', item); diff --git a/public/app/features/dashboard/model.ts b/public/app/features/dashboard/model.ts index a999b5d0dcd..96faff0395d 100644 --- a/public/app/features/dashboard/model.ts +++ b/public/app/features/dashboard/model.ts @@ -302,6 +302,34 @@ export class DashboardModel { }); } + removePanel(panel, ask?) { + // 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"; + } + + 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(panel, false); + } + }); + return; + } + + var index = _.indexOf(this.panels, panel); + this.panels.splice(index, 1); + this.events.emit('panel-removed', panel); + } + isTimezoneUtc() { return this.getTimezone() === 'utc'; } diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index 61fe9c974e6..d27ae104237 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -217,7 +217,7 @@ export class PanelCtrl { } removePanel() { - this.row.removePanel(this.panel); + this.dashboard.removePanel(this.panel); } editPanelJson() { diff --git a/public/app/features/panel/panel_header.ts b/public/app/features/panel/panel_header.ts index 98944269412..12486cb7313 100644 --- a/public/app/features/panel/panel_header.ts +++ b/public/app/features/panel/panel_header.ts @@ -92,12 +92,6 @@ function panelHeader($compile) { elem.click(function(evt) { const targetClass = evt.target.className; - console.log(elem.closest('.ui-draggable-dragging')); - // ignore click if we are dragging - if (elem.closest('.ui-draggable-dragging').length > 0) { - return; - } - // remove existing scope if (menuScope) { menuScope.$destroy();