Creating ohif:hotkeys package
This commit is contained in:
parent
f43e0d45c7
commit
5e7edd91ee
@ -8,6 +8,7 @@
|
|||||||
ohif:polyfill
|
ohif:polyfill
|
||||||
ohif:design
|
ohif:design
|
||||||
ohif:core
|
ohif:core
|
||||||
|
ohif:hotkeys
|
||||||
ohif:header
|
ohif:header
|
||||||
ohif:cornerstone
|
ohif:cornerstone
|
||||||
ohif:viewerbase
|
ohif:viewerbase
|
||||||
|
|||||||
@ -72,15 +72,16 @@ mongo-id@1.0.6
|
|||||||
natestrauser:select2@4.0.3
|
natestrauser:select2@4.0.3
|
||||||
npm-mongo@2.2.11_2
|
npm-mongo@2.2.11_2
|
||||||
observe-sequence@1.0.14
|
observe-sequence@1.0.14
|
||||||
ohif:polyfill@0.0.1
|
|
||||||
ohif:core@0.0.1
|
ohif:core@0.0.1
|
||||||
ohif:cornerstone@0.0.1
|
ohif:cornerstone@0.0.1
|
||||||
ohif:design@0.0.1
|
ohif:design@0.0.1
|
||||||
ohif:dicom-services@0.0.1
|
ohif:dicom-services@0.0.1
|
||||||
ohif:hanging-protocols@0.0.1
|
ohif:hanging-protocols@0.0.1
|
||||||
ohif:header@0.0.1
|
ohif:header@0.0.1
|
||||||
|
ohif:hotkeys@0.0.1
|
||||||
ohif:log@0.0.1
|
ohif:log@0.0.1
|
||||||
ohif:metadata@0.0.1
|
ohif:metadata@0.0.1
|
||||||
|
ohif:polyfill@0.0.1
|
||||||
ohif:study-list@0.0.1
|
ohif:study-list@0.0.1
|
||||||
ohif:themes@0.0.1
|
ohif:themes@0.0.1
|
||||||
ohif:themes-common@0.0.1
|
ohif:themes-common@0.0.1
|
||||||
|
|||||||
45
Packages/ohif-hotkeys/client/HotkeysContext.js
Normal file
45
Packages/ohif-hotkeys/client/HotkeysContext.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { OHIF } from 'meteor/ohif:core';
|
||||||
|
|
||||||
|
export class HotkeysContext {
|
||||||
|
constructor(name, definitions, enabled) {
|
||||||
|
this.name = name;
|
||||||
|
this.definitions = definitions;
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
extend(definitions={}) {
|
||||||
|
if (typeof definitions !== 'object') return;
|
||||||
|
this.destroy();
|
||||||
|
Object.assign(this.definitions, definitions);
|
||||||
|
this.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
initialize() {
|
||||||
|
Object.keys(this.definitions).forEach(definitionKey => {
|
||||||
|
const { hotkey, action, disabled } = this.definitions[definitionKey];
|
||||||
|
let message;
|
||||||
|
if (!hotkey) {
|
||||||
|
message = `No hotkey was defined for "${definitionKey}"`;
|
||||||
|
} else if (!action) {
|
||||||
|
message = `No action was defined for "${definitionKey}" using "${hotkey}" hotkey`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
return OHIF.log.warn(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).bind(`keydown.hotkey.${this.name}`, hotkey, event => {
|
||||||
|
if (!this.enabled.get()) return;
|
||||||
|
if (typeof disabled !== undefined) {
|
||||||
|
if ((typeof disabled === 'function' && disabled()) || disabled) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
action(event);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
$(document).unbind(`keydown.hotkey.${this.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
Packages/ohif-hotkeys/client/HotkeysManager.js
Normal file
59
Packages/ohif-hotkeys/client/HotkeysManager.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { ReactiveVar } from 'meteor/reactive-var';
|
||||||
|
import { HotkeysContext } from 'meteor/ohif:hotkeys/client/HotkeysContext';
|
||||||
|
|
||||||
|
export class HotkeysManager {
|
||||||
|
constructor() {
|
||||||
|
this.contexts = {};
|
||||||
|
this.currentContextName = null;
|
||||||
|
this.enabled = new ReactiveVar(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
disable() {
|
||||||
|
this.enabled.set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
enable() {
|
||||||
|
this.enabled.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
getContext(contextName) {
|
||||||
|
return this.contexts[contextName];
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentContext() {
|
||||||
|
return this.getContext(this.currentContextName);
|
||||||
|
}
|
||||||
|
|
||||||
|
setContext(contextName, contextDefinitions) {
|
||||||
|
const enabled = this.enabled;
|
||||||
|
const context = new HotkeysContext(contextName, contextDefinitions, enabled);
|
||||||
|
const currentContext = this.getCurrentContext();
|
||||||
|
if (currentContext && currentContext.name === contextName) {
|
||||||
|
currentContext.destroy();
|
||||||
|
context.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.contexts[contextName] = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsetContext(contextName) {
|
||||||
|
if (contextName === this.currentContextName) {
|
||||||
|
this.getCurrentContext().destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete this.contexts[contextName];
|
||||||
|
}
|
||||||
|
|
||||||
|
switchToContext(contextName) {
|
||||||
|
const currentContext = this.getCurrentContext();
|
||||||
|
if (currentContext) {
|
||||||
|
currentContext.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
const newContext = this.contexts[contextName];
|
||||||
|
if (!newContext) return;
|
||||||
|
|
||||||
|
this.currentContextName = contextName;
|
||||||
|
newContext.initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Packages/ohif-hotkeys/main.js
Normal file
18
Packages/ohif-hotkeys/main.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { OHIF } from 'meteor/ohif:core';
|
||||||
|
import { HotkeysManager } from 'meteor/ohif:hotkeys/client/HotkeysManager';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create hotkeys namespace using a HotkeysManager class instance
|
||||||
|
*/
|
||||||
|
const hotkeys = new HotkeysManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append hotkeys namespace to OHIF namespace
|
||||||
|
*/
|
||||||
|
|
||||||
|
OHIF.hotkeys = hotkeys;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export relevant objects
|
||||||
|
*/
|
||||||
|
export { hotkeys };
|
||||||
16
Packages/ohif-hotkeys/package.js
Normal file
16
Packages/ohif-hotkeys/package.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
Package.describe({
|
||||||
|
name: 'ohif:hotkeys',
|
||||||
|
summary: 'OHIF hotkeys management',
|
||||||
|
version: '0.0.1'
|
||||||
|
});
|
||||||
|
|
||||||
|
Package.onUse(function(api) {
|
||||||
|
api.versionsFrom('1.4');
|
||||||
|
|
||||||
|
// Meteor packages
|
||||||
|
api.use('ecmascript');
|
||||||
|
api.use('reactive-dict');
|
||||||
|
|
||||||
|
// Main module definition
|
||||||
|
api.mainModule('main.js', 'client');
|
||||||
|
});
|
||||||
@ -7,19 +7,23 @@ Package.describe({
|
|||||||
Package.onUse(function(api) {
|
Package.onUse(function(api) {
|
||||||
api.versionsFrom('1.4');
|
api.versionsFrom('1.4');
|
||||||
|
|
||||||
api.use('ecmascript');
|
api.use(['ecmascript',
|
||||||
api.use('standard-app-packages');
|
'standard-app-packages',
|
||||||
api.use('http');
|
'http',
|
||||||
api.use('jquery');
|
'jquery',
|
||||||
api.use('stylus');
|
'stylus',
|
||||||
api.use('momentjs:moment');
|
'momentjs:moment',
|
||||||
api.use('validatejs');
|
'validatejs',
|
||||||
api.use('u2622:persistent-session');
|
'u2622:persistent-session'
|
||||||
|
]);
|
||||||
|
|
||||||
// Our custom packages
|
// OHIF dependencies
|
||||||
api.use('ohif:design');
|
api.use([
|
||||||
api.use('ohif:core');
|
'ohif:design',
|
||||||
api.use('ohif:log');
|
'ohif:core',
|
||||||
|
'ohif:hotkeys',
|
||||||
|
'ohif:log'
|
||||||
|
]);
|
||||||
|
|
||||||
const assets = [
|
const assets = [
|
||||||
'assets/icons.svg',
|
'assets/icons.svg',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user