mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Moved dashboard keybinding setup to own service.
The goal is to split up the situation between the dashboard controller and the current dashboard service. I want to be able to use the routing in order to select various dashboard controllers, so I can extend the current scripting mechanism by implementing new dashboard controllers. However, to do this in a non-insane way, I need to move as much functionality as possible into services, so the individual controllers just need to throw the right set of services together and add a bit of loading logic.
This commit is contained in:
parent
2c43fdc409
commit
4a362704fd
@ -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
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
4
src/app/services/dashboard/all.js
Normal file
4
src/app/services/dashboard/all.js
Normal file
@ -0,0 +1,4 @@
|
||||
define([
|
||||
'./dashboardKeyBindings',
|
||||
],
|
||||
function () {});
|
59
src/app/services/dashboard/dashboardKeyBindings.js
Normal file
59
src/app/services/dashboard/dashboardKeyBindings.js
Normal file
@ -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 });
|
||||
};
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user