2016-11-02 06:55:58 -05:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import $ from 'jquery';
|
2016-11-03 09:14:44 -05:00
|
|
|
import _ from 'lodash';
|
2016-11-02 06:55:58 -05: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 09:14:44 -05:00
|
|
|
constructor(
|
|
|
|
private $rootScope,
|
|
|
|
private $modal,
|
|
|
|
private $location,
|
|
|
|
private contextSrv,
|
|
|
|
private $timeout) {
|
|
|
|
|
2016-11-02 06:55:58 -05:00
|
|
|
// clear out all shortcuts on route change
|
|
|
|
$rootScope.$on('$routeChangeSuccess', () => {
|
|
|
|
Mousetrap.reset();
|
|
|
|
// rebind global shortcuts
|
|
|
|
this.setupGlobal();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setupGlobal();
|
|
|
|
}
|
|
|
|
|
|
|
|
setupGlobal() {
|
2016-11-03 09:14:44 -05:00
|
|
|
this.bind(['?', 'h'], this.showHelpModal);
|
2016-11-02 06:55:58 -05:00
|
|
|
this.bind("g h", this.goToHome);
|
2016-11-02 16:08:17 -05:00
|
|
|
this.bind("g a", this.openAlerting);
|
2016-11-02 06:55:58 -05:00
|
|
|
this.bind("g p", this.goToProfile);
|
|
|
|
this.bind("s s", this.openSearchStarred);
|
2016-11-03 07:19:40 -05:00
|
|
|
this.bind('f', this.openSearch);
|
2016-11-02 06:55:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
openSearchStarred() {
|
|
|
|
this.$rootScope.appEvent('show-dash-search', {starred: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
openSearch() {
|
|
|
|
this.$rootScope.appEvent('show-dash-search');
|
|
|
|
}
|
|
|
|
|
2016-11-02 16:08:17 -05:00
|
|
|
openAlerting() {
|
|
|
|
this.$location.url("/alerting");
|
|
|
|
}
|
|
|
|
|
2016-11-02 06:55:58 -05:00
|
|
|
goToHome() {
|
2016-11-02 16:08:17 -05:00
|
|
|
this.$location.url("/");
|
2016-11-02 06:55:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
goToProfile() {
|
2016-11-02 16:08:17 -05:00
|
|
|
this.$location.url("/profile");
|
2016-11-02 06:55:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
showHelpModal() {
|
2016-11-03 14:32:36 -05:00
|
|
|
appEvents.emit('show-modal', {templateHtml: '<help-modal></help-modal>'});
|
2016-11-02 06:55:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bind(keyArg, fn) {
|
|
|
|
Mousetrap.bind(keyArg, evt => {
|
|
|
|
evt.preventDefault();
|
|
|
|
evt.stopPropagation();
|
|
|
|
return this.$rootScope.$apply(fn.bind(this));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-11-03 09:14:44 -05:00
|
|
|
showDashEditView(view) {
|
|
|
|
var search = _.extend(this.$location.search(), {editview: view});
|
|
|
|
this.$location.search(search);
|
|
|
|
}
|
|
|
|
|
2016-11-02 06:55:58 -05:00
|
|
|
setupDashboardBindings(scope, dashboard) {
|
2016-11-03 09:50:11 -05:00
|
|
|
// this.bind('b', () => {
|
|
|
|
// dashboard.toggleEditMode();
|
|
|
|
// });
|
2016-11-02 06:55:58 -05:00
|
|
|
|
|
|
|
this.bind('ctrl+o', () => {
|
|
|
|
dashboard.sharedCrosshair = !dashboard.sharedCrosshair;
|
|
|
|
scope.broadcastRefresh();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.bind(['ctrl+s', 'command+s'], () => {
|
|
|
|
scope.appEvent('save-dashboard');
|
|
|
|
});
|
|
|
|
this.bind('ctrl+z', () => {
|
|
|
|
scope.appEvent('zoom-out');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.bind('left', () => {
|
|
|
|
scope.appEvent('shift-time-backward');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.bind('right', () => {
|
|
|
|
scope.appEvent('shift-time-forward');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.bind('ctrl+i', () => {
|
|
|
|
scope.appEvent('quick-snapshot');
|
|
|
|
});
|
|
|
|
|
2016-11-03 07:19:40 -05:00
|
|
|
// edit panel
|
2016-11-02 09:16:48 -05:00
|
|
|
this.bind('e', () => {
|
|
|
|
if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
|
|
|
|
this.$rootScope.appEvent('panel-change-view', {
|
2016-11-02 15:45:46 -05:00
|
|
|
fullscreen: true,
|
|
|
|
edit: true,
|
|
|
|
panelId: dashboard.meta.focusPanelId,
|
|
|
|
toggle: true
|
2016-11-02 09:16:48 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-03 07:19:40 -05:00
|
|
|
// view panel
|
2016-11-02 11:03:14 -05:00
|
|
|
this.bind('v', () => {
|
|
|
|
if (dashboard.meta.focusPanelId) {
|
|
|
|
this.$rootScope.appEvent('panel-change-view', {
|
2016-11-02 15:45:46 -05:00
|
|
|
fullscreen: true,
|
|
|
|
edit: null,
|
|
|
|
panelId: dashboard.meta.focusPanelId,
|
|
|
|
toggle: true,
|
2016-11-02 11:03:14 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-03 07:19:40 -05:00
|
|
|
// delete panel
|
2016-11-03 09:14:44 -05:00
|
|
|
this.bind('r', () => {
|
2016-11-02 09:16:48 -05: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-03 09:14:44 -05:00
|
|
|
// delete panel
|
|
|
|
this.bind('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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.bind('d r', () => {
|
|
|
|
scope.broadcastRefresh();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.bind('d s', () => {
|
|
|
|
this.showDashEditView('settings');
|
|
|
|
});
|
|
|
|
|
2016-11-02 06:55:58 -05: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);
|