| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  | ///<reference path="../../headers/common.d.ts" />
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import $ from 'jquery'; | 
					
						
							| 
									
										
										
										
											2016-11-03 15:14:44 +01:00
										 |  |  | import _ from 'lodash'; | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | import coreModule from 'app/core/core_module'; | 
					
						
							|  |  |  | import appEvents from 'app/core/app_events'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import Mousetrap from 'mousetrap'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class KeybindingSrv { | 
					
						
							|  |  |  |   helpModal: boolean; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2016-11-03 15:14:44 +01:00
										 |  |  |   constructor( | 
					
						
							|  |  |  |     private $rootScope, | 
					
						
							|  |  |  |     private $modal, | 
					
						
							|  |  |  |     private $location, | 
					
						
							|  |  |  |     private contextSrv, | 
					
						
							|  |  |  |     private $timeout) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |     // clear out all shortcuts on route change
 | 
					
						
							|  |  |  |     $rootScope.$on('$routeChangeSuccess', () => { | 
					
						
							|  |  |  |       Mousetrap.reset(); | 
					
						
							|  |  |  |       // rebind global shortcuts
 | 
					
						
							|  |  |  |       this.setupGlobal(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.setupGlobal(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setupGlobal() { | 
					
						
							| 
									
										
										
										
											2016-11-03 15:14:44 +01:00
										 |  |  |     this.bind(['?', 'h'], this.showHelpModal); | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |     this.bind("g h", this.goToHome); | 
					
						
							| 
									
										
										
										
											2016-11-02 22:08:17 +01:00
										 |  |  |     this.bind("g a", this.openAlerting); | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |     this.bind("g p", this.goToProfile); | 
					
						
							|  |  |  |     this.bind("s s", this.openSearchStarred); | 
					
						
							| 
									
										
										
										
											2016-11-04 17:19:03 +01:00
										 |  |  |     this.bind('s o', this.openSearch); | 
					
						
							|  |  |  |     this.bind('s t', this.openSearchTags); | 
					
						
							| 
									
										
										
										
											2016-11-03 13:19:40 +01:00
										 |  |  |     this.bind('f', this.openSearch); | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   openSearchStarred() { | 
					
						
							|  |  |  |     this.$rootScope.appEvent('show-dash-search', {starred: true}); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 17:19:03 +01:00
										 |  |  |   openSearchTags() { | 
					
						
							|  |  |  |     this.$rootScope.appEvent('show-dash-search', {tagsMode: true}); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |   openSearch() { | 
					
						
							|  |  |  |     this.$rootScope.appEvent('show-dash-search'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 22:08:17 +01:00
										 |  |  |   openAlerting() { | 
					
						
							|  |  |  |     this.$location.url("/alerting"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |   goToHome() { | 
					
						
							| 
									
										
										
										
											2016-11-02 22:08:17 +01:00
										 |  |  |     this.$location.url("/"); | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   goToProfile() { | 
					
						
							| 
									
										
										
										
											2016-11-02 22:08:17 +01:00
										 |  |  |     this.$location.url("/profile"); | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   showHelpModal() { | 
					
						
							| 
									
										
										
										
											2016-11-03 22:14:29 +01:00
										 |  |  |     appEvents.emit('show-modal', {templateHtml: '<help-modal></help-modal>'}); | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bind(keyArg, fn) { | 
					
						
							|  |  |  |     Mousetrap.bind(keyArg, evt => { | 
					
						
							|  |  |  |       evt.preventDefault(); | 
					
						
							|  |  |  |       evt.stopPropagation(); | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |       evt.returnValue = false; | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |       return this.$rootScope.$apply(fn.bind(this)); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 15:14:44 +01:00
										 |  |  |   showDashEditView(view) { | 
					
						
							|  |  |  |     var search = _.extend(this.$location.search(), {editview: view}); | 
					
						
							|  |  |  |     this.$location.search(search); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |   setupDashboardBindings(scope, dashboard) { | 
					
						
							| 
									
										
										
										
											2016-11-03 15:50:11 +01:00
										 |  |  |     // this.bind('b', () => {
 | 
					
						
							|  |  |  |     //   dashboard.toggleEditMode();
 | 
					
						
							|  |  |  |     // });
 | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     this.bind('mod+o', () => { | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |       dashboard.sharedCrosshair = !dashboard.sharedCrosshair; | 
					
						
							|  |  |  |       scope.broadcastRefresh(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     this.bind('mod+h', () => { | 
					
						
							| 
									
										
										
										
											2016-11-03 22:39:59 +01:00
										 |  |  |       dashboard.hideControls = !dashboard.hideControls; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     this.bind('mod+s', e => { | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |       scope.appEvent('save-dashboard'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     this.bind('t z', () => { | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |       scope.appEvent('zoom-out'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     this.bind('t left', () => { | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |       scope.appEvent('shift-time-backward'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     this.bind('t right', () => { | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |       scope.appEvent('shift-time-forward'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     this.bind('mod+i', () => { | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |       scope.appEvent('quick-snapshot'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 13:19:40 +01:00
										 |  |  |     // edit panel
 | 
					
						
							| 
									
										
										
										
											2016-11-02 15:16:48 +01:00
										 |  |  |     this.bind('e', () => { | 
					
						
							|  |  |  |       if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) { | 
					
						
							|  |  |  |         this.$rootScope.appEvent('panel-change-view', { | 
					
						
							| 
									
										
										
										
											2016-11-02 21:45:46 +01:00
										 |  |  |           fullscreen: true, | 
					
						
							|  |  |  |           edit: true, | 
					
						
							|  |  |  |           panelId: dashboard.meta.focusPanelId, | 
					
						
							|  |  |  |           toggle: true | 
					
						
							| 
									
										
										
										
											2016-11-02 15:16:48 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 13:19:40 +01:00
										 |  |  |     // view panel
 | 
					
						
							| 
									
										
										
										
											2016-11-02 17:03:14 +01:00
										 |  |  |     this.bind('v', () => { | 
					
						
							|  |  |  |       if (dashboard.meta.focusPanelId) { | 
					
						
							|  |  |  |         this.$rootScope.appEvent('panel-change-view', { | 
					
						
							| 
									
										
										
										
											2016-11-02 21:45:46 +01:00
										 |  |  |           fullscreen: true, | 
					
						
							|  |  |  |           edit: null, | 
					
						
							|  |  |  |           panelId: dashboard.meta.focusPanelId, | 
					
						
							|  |  |  |           toggle: true, | 
					
						
							| 
									
										
										
										
											2016-11-02 17:03:14 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 13:19:40 +01:00
										 |  |  |     // delete panel
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     this.bind('p r', () => { | 
					
						
							| 
									
										
										
										
											2016-11-02 15:16:48 +01:00
										 |  |  |       if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) { | 
					
						
							|  |  |  |         var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId); | 
					
						
							|  |  |  |         panelInfo.row.removePanel(panelInfo.panel); | 
					
						
							|  |  |  |         dashboard.meta.focusPanelId = 0; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 17:19:03 +01:00
										 |  |  |     // share panel
 | 
					
						
							|  |  |  |     this.bind('p s', () => { | 
					
						
							|  |  |  |       if (dashboard.meta.focusPanelId) { | 
					
						
							|  |  |  |         var shareScope =  scope.$new(); | 
					
						
							|  |  |  |         var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId); | 
					
						
							|  |  |  |         shareScope.panel = panelInfo.panel; | 
					
						
							|  |  |  |         shareScope.dashboard = dashboard; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         appEvents.emit('show-modal', { | 
					
						
							|  |  |  |           src: 'public/app/features/dashboard/partials/shareModal.html', | 
					
						
							|  |  |  |           scope: shareScope | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-04 11:43:44 +01:00
										 |  |  |     // delete row
 | 
					
						
							|  |  |  |     this.bind('r r', () => { | 
					
						
							|  |  |  |       if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) { | 
					
						
							|  |  |  |         var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId); | 
					
						
							|  |  |  |         dashboard.removeRow(panelInfo.row); | 
					
						
							|  |  |  |         dashboard.meta.focusPanelId = 0; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // collapse row
 | 
					
						
							|  |  |  |     this.bind('r c', () => { | 
					
						
							|  |  |  |       if (dashboard.meta.focusPanelId) { | 
					
						
							|  |  |  |         var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId); | 
					
						
							|  |  |  |         panelInfo.row.toggleCollapse(); | 
					
						
							|  |  |  |         dashboard.meta.focusPanelId = 0; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-03 15:14:44 +01:00
										 |  |  |     this.bind('d r', () => { | 
					
						
							|  |  |  |       scope.broadcastRefresh(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.bind('d s', () => { | 
					
						
							|  |  |  |       this.showDashEditView('settings'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-02 12:55:58 +01:00
										 |  |  |     this.bind('esc', () => { | 
					
						
							|  |  |  |       var popups = $('.popover.in'); | 
					
						
							|  |  |  |       if (popups.length > 0) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       // close modals
 | 
					
						
							|  |  |  |       var modalData = $(".modal").data(); | 
					
						
							|  |  |  |       if (modalData && modalData.$scope && modalData.$scope.dismiss) { | 
					
						
							|  |  |  |         modalData.$scope.dismiss(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       scope.appEvent('hide-dash-editor'); | 
					
						
							|  |  |  |       scope.exitFullscreen(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | coreModule.service('keybindingSrv', KeybindingSrv); |