keybindings.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. define([
  2. 'angular',
  3. 'jquery',
  4. ],
  5. function(angular, $) {
  6. "use strict";
  7. var module = angular.module('grafana.services');
  8. module.service('dashboardKeybindings', function($rootScope, keyboardManager, $modal, $q) {
  9. this.shortcuts = function(scope) {
  10. scope.$on('$destroy', function() {
  11. keyboardManager.unbindAll();
  12. });
  13. var helpModalScope = null;
  14. keyboardManager.bind('shift+?', function() {
  15. if (helpModalScope) { return; }
  16. helpModalScope = $rootScope.$new();
  17. var helpModal = $modal({
  18. template: 'public/app/partials/help_modal.html',
  19. persist: false,
  20. show: false,
  21. scope: helpModalScope,
  22. keyboard: false
  23. });
  24. helpModalScope.$on('$destroy', function() { helpModalScope = null; });
  25. $q.when(helpModal).then(function(modalEl) { modalEl.modal('show'); });
  26. }, { inputDisabled: true });
  27. keyboardManager.bind('f', function() {
  28. scope.appEvent('show-dash-search');
  29. }, { inputDisabled: true });
  30. keyboardManager.bind('ctrl+o', function() {
  31. var current = scope.dashboard.sharedCrosshair;
  32. scope.dashboard.sharedCrosshair = !current;
  33. scope.broadcastRefresh();
  34. }, { inputDisabled: true });
  35. keyboardManager.bind('ctrl+b', function() {
  36. scope.dashboard.toggleEditMode();
  37. }, { inputDisabled: true });
  38. keyboardManager.bind('ctrl+s', function(evt) {
  39. scope.appEvent('save-dashboard', evt);
  40. }, { inputDisabled: true });
  41. keyboardManager.bind('r', function() {
  42. scope.broadcastRefresh();
  43. }, { inputDisabled: true });
  44. keyboardManager.bind('ctrl+z', function(evt) {
  45. scope.appEvent('zoom-out', evt);
  46. }, { inputDisabled: true });
  47. keyboardManager.bind('left', function(evt) {
  48. scope.appEvent('shift-time-backward', evt);
  49. }, { inputDisabled: true });
  50. keyboardManager.bind('right', function(evt) {
  51. scope.appEvent('shift-time-forward', evt);
  52. }, { inputDisabled: true });
  53. keyboardManager.bind('ctrl+i', function(evt) {
  54. scope.appEvent('quick-snapshot', evt);
  55. }, { inputDisabled: true });
  56. keyboardManager.bind('esc', function() {
  57. var popups = $('.popover.in');
  58. if (popups.length > 0) {
  59. return;
  60. }
  61. // close modals
  62. var modalData = $(".modal").data();
  63. if (modalData && modalData.$scope && modalData.$scope.dismiss) {
  64. modalData.$scope.dismiss();
  65. }
  66. scope.appEvent('hide-dash-editor');
  67. scope.exitFullscreen();
  68. }, { inputDisabled: true });
  69. };
  70. });
  71. });