Browse Source

Use and add keybard shortcut

Tobias Skarhed 7 years ago
parent
commit
1618b095c7

+ 15 - 1
public/app/core/services/keybindingSrv.ts

@@ -15,7 +15,14 @@ export class KeybindingSrv {
   timepickerOpen = false;
 
   /** @ngInject */
-  constructor(private $rootScope, private $location, private datasourceSrv, private timeSrv, private contextSrv) {
+  constructor(
+    private $rootScope,
+    private $location,
+    private datasourceSrv,
+    private timeSrv,
+    private contextSrv,
+    private $window
+  ) {
     // clear out all shortcuts on route change
     $rootScope.$on('$routeChangeSuccess', () => {
       Mousetrap.reset();
@@ -259,6 +266,13 @@ export class KeybindingSrv {
     this.bind('d v', () => {
       appEvents.emit('toggle-view-mode');
     });
+
+    //Autofit panels
+    this.bind('d a', () => {
+      this.$location.search('autofitpanels', this.$location.search().autofitpanels ? null : true);
+      //Force reload
+      this.$window.location.href = this.$location.absUrl();
+    });
   }
 }
 

+ 3 - 2
public/app/features/dashboard/dashboard_ctrl.ts

@@ -24,7 +24,8 @@ export class DashboardCtrl implements PanelContainer {
     private unsavedChangesSrv,
     private dashboardViewStateSrv,
     public playlistSrv,
-    private panelLoader
+    private panelLoader,
+    private $location
   ) {
     // temp hack due to way dashboards are loaded
     // can't use controllerAs on route yet
@@ -64,7 +65,7 @@ export class DashboardCtrl implements PanelContainer {
         this.dashboard = dashboard;
         this.dashboard.processRepeats();
 
-        if (window.location.search.search('autofitpanels') !== -1) {
+        if (this.$location.search().autofitpanels) {
           let maxRows = Math.max(
             ...this.dashboard.panels.map(panel => {
               return panel.gridPos.h + panel.gridPos.y;