diff --git a/src/app/app.js b/src/app/app.js index c3c46dbdde0..1508f16e013 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -98,7 +98,7 @@ function (angular, $, _, appLevelRequire) { 'pasvaz.bindonce' ]; - _.each('controllers directives factories services filters'.split(' '), + _.each('controllers directives factories services services.dashboard filters'.split(' '), function (type) { var module_name = 'kibana.'+type; // create the module diff --git a/src/app/controllers/dash.js b/src/app/controllers/dash.js index 98f5df2983e..1038378b1b3 100644 --- a/src/app/controllers/dash.js +++ b/src/app/controllers/dash.js @@ -22,7 +22,8 @@ define([ 'jquery', 'config', 'underscore', - 'services/all' + 'services/all', + 'services/dashboard/all' ], function (angular, $, config, _) { "use strict"; @@ -30,7 +31,7 @@ function (angular, $, config, _) { var module = angular.module('kibana.controllers'); module.controller('DashCtrl', function( - $scope, $rootScope, ejsResource, dashboard, + $scope, $rootScope, ejsResource, dashboard, dashboardKeybindings, alertSrv, panelMove, keyboardManager, grafanaVersion) { $scope.requiredElasticSearchVersion = ">=0.90.3"; @@ -66,68 +67,7 @@ function (angular, $, config, _) { $scope.bindKeyboardShortcuts(); }; - $scope.bindKeyboardShortcuts = function() { - $rootScope.$on('panel-fullscreen-enter', function() { - $rootScope.fullscreen = true; - }); - - $rootScope.$on('panel-fullscreen-exit', function() { - $rootScope.fullscreen = false; - }); - - $rootScope.$on('dashboard-saved', function() { - if ($rootScope.fullscreen) { - $rootScope.$emit('panel-fullscreen-exit'); - } - }); - - keyboardManager.bind('ctrl+f', function(evt) { - $rootScope.$emit('open-search', evt); - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+h', function() { - var current = dashboard.current.hideControls; - dashboard.current.hideControls = !current; - dashboard.current.panel_hints = current; - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+s', function(evt) { - $rootScope.$emit('save-dashboard', evt); - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+r', function() { - dashboard.refresh(); - }, { inputDisabled: true }); - - keyboardManager.bind('ctrl+z', function(evt) { - $rootScope.$emit('zoom-out', evt); - }, { inputDisabled: true }); - - keyboardManager.bind('esc', function() { - var popups = $('.popover.in'); - if (popups.length > 0) { - return; - } - $rootScope.$emit('panel-fullscreen-exit'); - }, { inputDisabled: true }); - }; - - $scope.countWatchers = function (scopeStart) { - var q = [scopeStart || $rootScope], watchers = 0, scope; - while (q.length > 0) { - scope = q.pop(); - if (scope.$$watchers) { - watchers += scope.$$watchers.length; - } - if (scope.$$childHead) { - q.push(scope.$$childHead); - } - if (scope.$$nextSibling) { - q.push(scope.$$nextSibling); - } - } - window.console.log(watchers); - }; + $scope.bindKeyboardShortcuts = dashboardKeybindings.shortcuts $scope.isPanel = function(obj) { if(!_.isNull(obj) && !_.isUndefined(obj) && !_.isUndefined(obj.type)) { @@ -196,4 +136,4 @@ function (angular, $, config, _) { $scope.init(); }); -}); \ No newline at end of file +}); diff --git a/src/app/services/dashboard/all.js b/src/app/services/dashboard/all.js new file mode 100644 index 00000000000..f861edb5a8d --- /dev/null +++ b/src/app/services/dashboard/all.js @@ -0,0 +1,4 @@ +define([ + './dashboardKeyBindings', +], +function () {}); diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js new file mode 100644 index 00000000000..d3127a10420 --- /dev/null +++ b/src/app/services/dashboard/dashboardKeyBindings.js @@ -0,0 +1,59 @@ +define([ + 'angular', + 'jquery', + 'underscore', + 'services/all' +], +function( angular, $, _ ) { + "use strict"; + + var module = angular.module('kibana.services.dashboard'); + + module.service( 'dashboardKeybindings', function($rootScope, keyboardManager, dashboard) { + this.shortcuts = function() { + $rootScope.$on('panel-fullscreen-enter', function() { + $rootScope.fullscreen = true; + }); + + $rootScope.$on('panel-fullscreen-exit', function() { + $rootScope.fullscreen = false; + }); + + $rootScope.$on('dashboard-saved', function() { + if ($rootScope.fullscreen) { + $rootScope.$emit('panel-fullscreen-exit'); + } + }); + + keyboardManager.bind('ctrl+f', function(evt) { + $rootScope.$emit('open-search', evt); + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+h', function() { + var current = dashboard.current.hideControls; + dashboard.current.hideControls = !current; + dashboard.current.panel_hints = current; + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+s', function(evt) { + $rootScope.$emit('save-dashboard', evt); + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+r', function() { + dashboard.refresh(); + }, { inputDisabled: true }); + + keyboardManager.bind('ctrl+z', function(evt) { + $rootScope.$emit('zoom-out', evt); + }, { inputDisabled: true }); + + keyboardManager.bind('esc', function() { + var popups = $('.popover.in'); + if (popups.length > 0) { + return; + } + $rootScope.$emit('panel-fullscreen-exit'); + }, { inputDisabled: true }); + }; + }); +});