keybindings.js 2.7 KB

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