diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index 672ae29740b..0930a16d797 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/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(); + }); } } diff --git a/public/app/features/dashboard/dashboard_ctrl.ts b/public/app/features/dashboard/dashboard_ctrl.ts index ef68a76da30..ccb5686b23a 100644 --- a/public/app/features/dashboard/dashboard_ctrl.ts +++ b/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;