瀏覽代碼

dashboards: fix keyboard shortcut for expand/collapse rows

Marcus Efraimsson 7 年之前
父節點
當前提交
34f1611d18
共有 2 個文件被更改,包括 30 次插入6 次删除
  1. 2 6
      public/app/core/services/keybindingSrv.ts
  2. 28 0
      public/app/features/dashboard/dashboard_model.ts

+ 2 - 6
public/app/core/services/keybindingSrv.ts

@@ -213,16 +213,12 @@ export class KeybindingSrv {
 
     // collapse all rows
     this.bind('d shift+c', () => {
-      for (let row of dashboard.rows) {
-        row.collapse = true;
-      }
+      dashboard.collapseRows();
     });
 
     // expand all rows
     this.bind('d shift+e', () => {
-      for (let row of dashboard.rows) {
-        row.collapse = false;
-      }
+      dashboard.expandRows();
     });
 
     this.bind('d n', e => {

+ 28 - 0
public/app/features/dashboard/dashboard_model.ts

@@ -524,6 +524,34 @@ export class DashboardModel {
     this.removePanel(row);
   }
 
+  expandRows() {
+    for (let i = 0; i < this.panels.length; i++) {
+      var panel = this.panels[i];
+
+      if (panel.type !== 'row') {
+        continue;
+      }
+
+      if (panel.collapsed) {
+        this.toggleRow(panel);
+      }
+    }
+  }
+
+  collapseRows() {
+    for (let i = 0; i < this.panels.length; i++) {
+      var panel = this.panels[i];
+
+      if (panel.type !== 'row') {
+        continue;
+      }
+
+      if (!panel.collapsed) {
+        this.toggleRow(panel);
+      }
+    }
+  }
+
   setPanelFocus(id) {
     this.meta.focusPanelId = id;
   }