keybindings.js 2.8 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. 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+h', function() {
  36. var current = scope.dashboard.hideControls;
  37. scope.dashboard.hideControls = !current;
  38. }, { inputDisabled: true });
  39. keyboardManager.bind('ctrl+s', function(evt) {
  40. scope.appEvent('save-dashboard', evt);
  41. }, { inputDisabled: true });
  42. keyboardManager.bind('r', function() {
  43. scope.broadcastRefresh();
  44. }, { inputDisabled: true });
  45. keyboardManager.bind('ctrl+z', function(evt) {
  46. scope.appEvent('zoom-out', evt);
  47. }, { inputDisabled: true });
  48. keyboardManager.bind('left', function(evt) {
  49. scope.appEvent('shift-time-backward', evt);
  50. }, { inputDisabled: true });
  51. keyboardManager.bind('right', function(evt) {
  52. scope.appEvent('shift-time-forward', evt);
  53. }, { inputDisabled: true });
  54. keyboardManager.bind('ctrl+e', function(evt) {
  55. scope.appEvent('export-dashboard', 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. });