2014-05-15 08:04:23 -05:00
|
|
|
define([
|
2014-05-27 11:18:05 -05:00
|
|
|
'angular',
|
|
|
|
'jquery',
|
2014-05-15 08:04:23 -05:00
|
|
|
],
|
2014-05-27 11:18:05 -05:00
|
|
|
function(angular, $) {
|
|
|
|
"use strict";
|
|
|
|
|
2014-07-28 11:11:52 -05:00
|
|
|
var module = angular.module('grafana.services');
|
2014-05-27 11:18:05 -05:00
|
|
|
|
2014-10-19 11:30:41 -05:00
|
|
|
module.service('dashboardKeybindings', function($rootScope, keyboardManager, $modal, $q) {
|
2014-06-08 07:40:44 -05:00
|
|
|
|
2014-06-12 06:37:40 -05:00
|
|
|
this.shortcuts = function(scope) {
|
2014-06-08 07:40:44 -05:00
|
|
|
|
2014-06-12 06:37:40 -05:00
|
|
|
scope.$on('$destroy', function() {
|
2015-02-21 14:19:51 -06:00
|
|
|
keyboardManager.unbindAll();
|
2014-06-12 06:37:40 -05:00
|
|
|
});
|
|
|
|
|
2014-10-19 11:30:41 -05:00
|
|
|
var helpModalScope = null;
|
2014-10-20 10:33:07 -05:00
|
|
|
keyboardManager.bind('shift+?', function() {
|
2014-10-19 11:30:41 -05:00
|
|
|
if (helpModalScope) { return; }
|
|
|
|
|
|
|
|
helpModalScope = $rootScope.$new();
|
|
|
|
var helpModal = $modal({
|
|
|
|
template: './app/partials/help_modal.html',
|
|
|
|
persist: false,
|
|
|
|
show: false,
|
|
|
|
scope: helpModalScope,
|
|
|
|
keyboard: false
|
|
|
|
});
|
|
|
|
|
|
|
|
helpModalScope.$on('$destroy', function() { helpModalScope = null; });
|
|
|
|
$q.when(helpModal).then(function(modalEl) { modalEl.modal('show'); });
|
|
|
|
|
|
|
|
}, { inputDisabled: true });
|
|
|
|
|
2014-08-26 09:42:15 -05:00
|
|
|
keyboardManager.bind('ctrl+f', function() {
|
2015-02-17 11:20:47 -06:00
|
|
|
scope.appEvent('show-dash-search');
|
2014-06-06 23:38:33 -05:00
|
|
|
}, { inputDisabled: true });
|
|
|
|
|
2014-09-29 23:24:56 -05:00
|
|
|
keyboardManager.bind('ctrl+o', function() {
|
|
|
|
var current = scope.dashboard.sharedCrosshair;
|
|
|
|
scope.dashboard.sharedCrosshair = !current;
|
2015-02-22 01:09:58 -06:00
|
|
|
scope.broadcastRefresh();
|
2014-09-29 23:24:56 -05:00
|
|
|
}, { inputDisabled: true });
|
|
|
|
|
2014-06-06 23:38:33 -05:00
|
|
|
keyboardManager.bind('ctrl+h', function() {
|
2014-06-12 06:37:40 -05:00
|
|
|
var current = scope.dashboard.hideControls;
|
|
|
|
scope.dashboard.hideControls = !current;
|
2014-06-06 23:38:33 -05:00
|
|
|
}, { inputDisabled: true });
|
|
|
|
|
|
|
|
keyboardManager.bind('ctrl+s', function(evt) {
|
2014-09-24 09:26:39 -05:00
|
|
|
scope.appEvent('save-dashboard', evt);
|
2014-06-06 23:38:33 -05:00
|
|
|
}, { inputDisabled: true });
|
|
|
|
|
|
|
|
keyboardManager.bind('ctrl+r', function() {
|
2015-02-22 01:09:58 -06:00
|
|
|
scope.broadcastRefresh();
|
2014-06-06 23:38:33 -05:00
|
|
|
}, { inputDisabled: true });
|
|
|
|
|
|
|
|
keyboardManager.bind('ctrl+z', function(evt) {
|
2014-09-24 09:26:39 -05:00
|
|
|
scope.appEvent('zoom-out', evt);
|
2014-06-06 23:38:33 -05:00
|
|
|
}, { inputDisabled: true });
|
|
|
|
|
|
|
|
keyboardManager.bind('esc', function() {
|
|
|
|
var popups = $('.popover.in');
|
|
|
|
if (popups.length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-07 02:00:52 -05:00
|
|
|
// close modals
|
|
|
|
var modalData = $(".modal").data();
|
|
|
|
if (modalData && modalData.$scope && modalData.$scope.dismiss) {
|
|
|
|
modalData.$scope.dismiss();
|
|
|
|
}
|
|
|
|
|
2014-09-24 09:26:39 -05:00
|
|
|
scope.appEvent('hide-dash-editor');
|
2014-08-26 09:42:15 -05:00
|
|
|
|
2014-08-13 08:02:57 -05:00
|
|
|
scope.exitFullscreen();
|
2014-06-06 23:38:33 -05:00
|
|
|
}, { inputDisabled: true });
|
2014-05-27 11:18:05 -05:00
|
|
|
};
|
|
|
|
});
|
2014-05-15 08:04:23 -05:00
|
|
|
});
|