keybindings.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.editMode = !scope.dashboard.editMode;
  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+e', function(evt) {
  54. scope.appEvent('export-dashboard', evt);
  55. }, { inputDisabled: true });
  56. keyboardManager.bind('ctrl+i', function(evt) {
  57. scope.appEvent('quick-snapshot', evt);
  58. }, { inputDisabled: true });
  59. keyboardManager.bind('esc', function() {
  60. var popups = $('.popover.in');
  61. if (popups.length > 0) {
  62. return;
  63. }
  64. // close modals
  65. var modalData = $(".modal").data();
  66. if (modalData && modalData.$scope && modalData.$scope.dismiss) {
  67. modalData.$scope.dismiss();
  68. }
  69. scope.appEvent('hide-dash-editor');
  70. scope.exitFullscreen();
  71. }, { inputDisabled: true });
  72. };
  73. });
  74. });