Ver Fonte

grid: remove panel works

Torkel Ödegaard há 8 anos atrás
pai
commit
23666c0f78

+ 11 - 0
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);

+ 28 - 0
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';
   }

+ 1 - 1
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() {

+ 0 - 6
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();