CORD-582, CORD-734 Registering events listeners for keyboard shortcuts
and displaying them in the side panel
Change-Id: Ifbb227b3a425be5c33d1fe211abd473209414896
diff --git a/src/app/core/header/header.spec.ts b/src/app/core/header/header.spec.ts
index 0bd6877..c1d6062 100644
--- a/src/app/core/header/header.spec.ts
+++ b/src/app/core/header/header.spec.ts
@@ -42,6 +42,10 @@
}
};
+const MockXosKeyboardShortcut = {
+ registerKeyBinding: jasmine.createSpy('registerKeyBinding')
+};
+
describe('header component', () => {
beforeEach(() => {
angular
@@ -52,6 +56,7 @@
.value('toastrConfig', MockToastrConfig)
.value('AuthService', MockAuth)
.value('NavigationService', {})
+ .value('XosKeyboardShortcut', MockXosKeyboardShortcut)
.value('StyleConfig', {
logo: 'cord-logo.png',
})
@@ -77,6 +82,17 @@
expect(header.trim()).not.toBeNull();
});
+ it('should register a keyboard shortcut', () => {
+ expect(MockXosKeyboardShortcut.registerKeyBinding).toHaveBeenCalled();
+ // expect(MockXosKeyboardShortcut.registerKeyBinding).toHaveBeenCalledWith({
+ // key: 'f',
+ // description: 'Select search box',
+ // cb: () => {
+ // $('.navbar-form input').focus();
+ // },
+ // }, 'global');
+ });
+
it('should print user email', () => {
expect($('.profile-address', element).text()).toBe('test@xos.us');
});
diff --git a/src/app/core/header/header.ts b/src/app/core/header/header.ts
index 1f01bf8..8926080 100644
--- a/src/app/core/header/header.ts
+++ b/src/app/core/header/header.ts
@@ -7,13 +7,14 @@
import * as $ from 'jquery';
import {IXosStyleConfig} from '../../../index';
import {IXosSearchService, IXosSearchResult} from '../../datasources/helpers/search.service';
+import {IXosKeyboardShortcutService} from '../services/keyboard-shortcut';
export interface INotification extends IWSEvent {
viewed?: boolean;
}
class HeaderController {
- static $inject = ['$scope', '$rootScope', '$state', 'AuthService', 'SynchronizerStore', 'toastr', 'toastrConfig', 'NavigationService', 'StyleConfig', 'SearchService'];
+ static $inject = ['$scope', '$rootScope', '$state', 'AuthService', 'SynchronizerStore', 'toastr', 'toastrConfig', 'NavigationService', 'StyleConfig', 'SearchService', 'XosKeyboardShortcut'];
public notifications: INotification[] = [];
public newNotifications: INotification[] = [];
public version: string;
@@ -33,7 +34,8 @@
private toastrConfig: ng.toastr.IToastrConfig,
private NavigationService: IXosNavigationService,
private StyleConfig: IXosStyleConfig,
- private SearchService: IXosSearchService
+ private SearchService: IXosSearchService,
+ private XosKeyboardShortcut: IXosKeyboardShortcutService
) {
this.version = require('../../../../package.json').version;
angular.extend(this.toastrConfig, {
@@ -53,11 +55,13 @@
};
// listen for keypress
- $(document).on('keyup', (e) => {
- if (e.key === 'f') {
+ this.XosKeyboardShortcut.registerKeyBinding({
+ key: 'f',
+ description: 'Select search box',
+ cb: () => {
$('.navbar-form input').focus();
- }
- });
+ },
+ }, 'global');
// redirect to selected page
this.routeSelected = (item: IXosSearchResult) => {