| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- ///<reference path="../../headers/common.d.ts" />
- import $ from 'jquery';
- import _ from 'lodash';
- import coreModule from 'app/core/core_module';
- import appEvents from 'app/core/app_events';
- import Mousetrap from 'mousetrap';
- export class KeybindingSrv {
- helpModal: boolean;
- /** @ngInject */
- constructor(
- private $rootScope,
- private $modal,
- private $location,
- private contextSrv,
- private $timeout) {
- // clear out all shortcuts on route change
- $rootScope.$on('$routeChangeSuccess', () => {
- Mousetrap.reset();
- // rebind global shortcuts
- this.setupGlobal();
- });
- this.setupGlobal();
- }
- setupGlobal() {
- this.bind(['?', 'h'], this.showHelpModal);
- this.bind("g h", this.goToHome);
- this.bind("g a", this.openAlerting);
- this.bind("g p", this.goToProfile);
- this.bind("s s", this.openSearchStarred);
- this.bind('s o', this.openSearch);
- this.bind('s t', this.openSearchTags);
- this.bind('f', this.openSearch);
- }
- openSearchStarred() {
- this.$rootScope.appEvent('show-dash-search', {starred: true});
- }
- openSearchTags() {
- this.$rootScope.appEvent('show-dash-search', {tagsMode: true});
- }
- openSearch() {
- this.$rootScope.appEvent('show-dash-search');
- }
- openAlerting() {
- this.$location.url("/alerting");
- }
- goToHome() {
- this.$location.url("/");
- }
- goToProfile() {
- this.$location.url("/profile");
- }
- showHelpModal() {
- appEvents.emit('show-modal', {templateHtml: '<help-modal></help-modal>'});
- }
- bind(keyArg, fn) {
- Mousetrap.bind(keyArg, evt => {
- evt.preventDefault();
- evt.stopPropagation();
- evt.returnValue = false;
- return this.$rootScope.$apply(fn.bind(this));
- });
- }
- showDashEditView(view) {
- var search = _.extend(this.$location.search(), {editview: view});
- this.$location.search(search);
- }
- setupDashboardBindings(scope, dashboard) {
- // this.bind('b', () => {
- // dashboard.toggleEditMode();
- // });
- this.bind('mod+o', () => {
- dashboard.graphTooltip = (dashboard.graphTooltip + 1) % 3;
- appEvents.emit('graph-hover-clear');
- scope.broadcastRefresh();
- });
- this.bind('mod+h', () => {
- dashboard.hideControls = !dashboard.hideControls;
- });
- this.bind('mod+s', e => {
- scope.appEvent('save-dashboard');
- });
- this.bind('t z', () => {
- scope.appEvent('zoom-out', 2);
- });
- this.bind('ctrl+z', () => {
- scope.appEvent('zoom-out', 2);
- });
- this.bind('t left', () => {
- scope.appEvent('shift-time-backward');
- });
- this.bind('t right', () => {
- scope.appEvent('shift-time-forward');
- });
- this.bind('mod+i', () => {
- scope.appEvent('quick-snapshot');
- });
- // edit panel
- this.bind('e', () => {
- if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
- this.$rootScope.appEvent('panel-change-view', {
- fullscreen: true,
- edit: true,
- panelId: dashboard.meta.focusPanelId,
- toggle: true
- });
- }
- });
- // view panel
- this.bind('v', () => {
- if (dashboard.meta.focusPanelId) {
- this.$rootScope.appEvent('panel-change-view', {
- fullscreen: true,
- edit: null,
- panelId: dashboard.meta.focusPanelId,
- toggle: true,
- });
- }
- });
- // delete panel
- this.bind('p r', () => {
- if (dashboard.meta.focusPanelId && dashboard.meta.canEdit) {
- var panelInfo = dashboard.getPanelInfoById(dashboard.meta.focusPanelId);
- panelInfo.row.removePanel(panelInfo.panel);
- dashboard.meta.focusPanelId = 0;
- }
- });
- // 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
- });
- }
- });
- // 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;
- }
- });
- this.bind('d r', () => {
- scope.broadcastRefresh();
- });
- this.bind('d s', () => {
- this.showDashEditView('settings');
- });
- this.bind('d k', () => {
- appEvents.emit('toggle-kiosk-mode');
- });
- this.bind('d v', () => {
- appEvents.emit('toggle-view-mode');
- });
- 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);
|