From c1f8984c1b46549662b770f4bcbc49725defd67c Mon Sep 17 00:00:00 2001 From: dannyrb Date: Sun, 2 Jun 2019 22:43:04 -0400 Subject: [PATCH] Switch folder; dependency injection; note about moving to extensions --- src/{commands => appCommands}/README.md | 0 src/{commands => appCommands}/cornerstone.js | 128 +++++++++---------- src/appCommands/index.js | 60 +++++++++ src/{commands => appCommands}/viewer.js | 30 ++--- src/commands/index.js | 52 -------- 5 files changed, 139 insertions(+), 131 deletions(-) rename src/{commands => appCommands}/README.md (100%) rename src/{commands => appCommands}/cornerstone.js (100%) create mode 100644 src/appCommands/index.js rename src/{commands => appCommands}/viewer.js (96%) delete mode 100644 src/commands/index.js diff --git a/src/commands/README.md b/src/appCommands/README.md similarity index 100% rename from src/commands/README.md rename to src/appCommands/README.md diff --git a/src/commands/cornerstone.js b/src/appCommands/cornerstone.js similarity index 100% rename from src/commands/cornerstone.js rename to src/appCommands/cornerstone.js index ab8974ea4..89699a226 100644 --- a/src/commands/cornerstone.js +++ b/src/appCommands/cornerstone.js @@ -1,69 +1,5 @@ import cornerstone from 'cornerstone-core'; -const definitions = { - rotateViewportCW: { - commandFn: actions.rotateViewport, - storeContexts: ['viewports'], - options: { rotation: 90 }, - }, - rotateViewportCCW: { - commandFn: actions.rotateViewport, - storeContexts: ['viewports'], - options: { rotation: -90 }, - }, - invertViewport: { - commandFn: actions.invertViewport, - storeContexts: ['viewports'], - options: {}, - }, - flipViewportVertical: { - commandFn: actions.flipViewportVertical, - storeContexts: ['viewports'], - options: {}, - }, - flipViewportHorizontal: { - commandFn: actions.flipViewportHorizontal, - storeContexts: ['viewports'], - options: {}, - }, - scaleUpViewport: { - keys: '', - commandFn: actions.scaleViewport, - storeContexts: ['viewports'], - options: { direction: 1 }, - }, - scaleDownViewport: { - keys: '', - commandFn: actions.scaleViewport, - storeContexts: ['viewports'], - options: { direction: -1 }, - }, - fitViewportToWindow: { - commandFn: actions.scaleViewport, - storeContexts: ['viewports'], - options: { direction: 0 }, - }, - resetViewport: { - commandFn: actions.resetViewport, - storeContexts: ['viewports'], - options: {}, - }, - // TODO: Clear Annotations - // TODO: Next/Previous image - // TODO: First/Last image - // Next/Previous series/DisplaySet - nextViewportDisplaySet: { - commandFn: actions.updateViewportDisplaySet, - storeContexts: [], - options: { direction: 1 }, - }, - previousViewportDisplaySet: { - commandFn: actions.updateViewportDisplaySet, - storeContexts: [], - options: { direction: 1 }, - }, -}; - const actions = { rotateViewport: ({ viewports, rotation }) => { const enabledElement = _getActiveViewportEnabledElement( @@ -157,6 +93,70 @@ const actions = { }, }; +const definitions = { + rotateViewportCW: { + commandFn: actions.rotateViewport, + storeContexts: ['viewports'], + options: { rotation: 90 }, + }, + rotateViewportCCW: { + commandFn: actions.rotateViewport, + storeContexts: ['viewports'], + options: { rotation: -90 }, + }, + invertViewport: { + commandFn: actions.invertViewport, + storeContexts: ['viewports'], + options: {}, + }, + flipViewportVertical: { + commandFn: actions.flipViewportVertical, + storeContexts: ['viewports'], + options: {}, + }, + flipViewportHorizontal: { + commandFn: actions.flipViewportHorizontal, + storeContexts: ['viewports'], + options: {}, + }, + scaleUpViewport: { + keys: '', + commandFn: actions.scaleViewport, + storeContexts: ['viewports'], + options: { direction: 1 }, + }, + scaleDownViewport: { + keys: '', + commandFn: actions.scaleViewport, + storeContexts: ['viewports'], + options: { direction: -1 }, + }, + fitViewportToWindow: { + commandFn: actions.scaleViewport, + storeContexts: ['viewports'], + options: { direction: 0 }, + }, + resetViewport: { + commandFn: actions.resetViewport, + storeContexts: ['viewports'], + options: {}, + }, + // TODO: Clear Annotations + // TODO: Next/Previous image + // TODO: First/Last image + // Next/Previous series/DisplaySet + nextViewportDisplaySet: { + commandFn: actions.updateViewportDisplaySet, + storeContexts: [], + options: { direction: 1 }, + }, + previousViewportDisplaySet: { + commandFn: actions.updateViewportDisplaySet, + storeContexts: [], + options: { direction: 1 }, + }, +}; + /** * Grabs `dom` reference for the enabledElement of * the active viewport diff --git a/src/appCommands/index.js b/src/appCommands/index.js new file mode 100644 index 000000000..66ab50fa6 --- /dev/null +++ b/src/appCommands/index.js @@ -0,0 +1,60 @@ +import cornerstoneCommandDefinitions from './cornerstone.js'; +import viewerCommandDefinitions from './viewer.js'; + +const CONTEXTS = { + viewer: 'VIEWER', + cornerstone: 'VIEWER::CORNERSTONE', +}; + +/** + * Register all commands. + * TODO: Extensions should self-register their commands + */ +function init(commandsManager) { + _registerViewerCommands(commandsManager); + _registerCornerstoneCommands(commandsManager); +} + +/** + * Register all Viewer commands + * + * @private + */ +function _registerViewerCommands(commandsManager) { + const commandContext = CONTEXTS.viewer; + + commandsManager.createContext(commandContext); + Object.keys(viewerCommandDefinitions).forEach(commandName => { + const commandDefinition = viewerCommandDefinitions[commandName]; + + commandsManager.registerCommand( + commandContext, + commandName, + commandDefinition + ); + }); +} + +/** + * Register all Cornerstone commands + * + * @private + */ +function _registerCornerstoneCommands(commandsManager) { + const commandContext = CONTEXTS.cornerstone; + + commandsManager.createContext(commandContext); + Object.keys(cornerstoneCommandDefinitions).forEach(commandName => { + const commandDefinition = cornerstoneCommandDefinitions[commandName]; + + commandsManager.registerCommand( + commandContext, + commandName, + commandDefinition + ); + }); +} + +export default { + init, +}; diff --git a/src/commands/viewer.js b/src/appCommands/viewer.js similarity index 96% rename from src/commands/viewer.js rename to src/appCommands/viewer.js index 7f0bc0f4d..fa7c02772 100644 --- a/src/commands/viewer.js +++ b/src/appCommands/viewer.js @@ -1,21 +1,7 @@ import { redux } from 'ohif-core'; -import store from './store'; +import store from './../store'; const { setViewportActive } = redux.actions; -const definitions = { - // Next/Previous active viewport - incrementActiveViewport: { - commandFn: actions.updateActiveViewport, - storeContexts: ['viewports'], - options: { direction: 1 }, - }, - decrementActiveViewport: { - commandFn: actions.updateActiveViewport, - storeContexts: ['viewports'], - options: { direction: -1 }, - }, -}; - const actions = { updateViewportDisplaySet: ({ direction }) => { // TODO @@ -33,4 +19,18 @@ const actions = { }, }; +const definitions = { + // Next/Previous active viewport + incrementActiveViewport: { + commandFn: actions.updateActiveViewport, + storeContexts: ['viewports'], + options: { direction: 1 }, + }, + decrementActiveViewport: { + commandFn: actions.updateActiveViewport, + storeContexts: ['viewports'], + options: { direction: -1 }, + }, +}; + export default definitions; diff --git a/src/commands/index.js b/src/commands/index.js deleted file mode 100644 index b577eb2b8..000000000 --- a/src/commands/index.js +++ /dev/null @@ -1,52 +0,0 @@ -import { CommandsManager } from 'ohif-core'; -import cornerstoneCommandDefinitions from 'cornerstone.js'; -import viewerCommandDefinitions from 'viewer.js'; - -const CONTEXTS = { - viewer: 'VIEWER', - cornerstone: 'VIEWER::CORNERSTONE', -}; - -/** - * Register all commands - */ -function init() { - _registerViewerCommands(); - _registerCornerstoneCommands(); -} - -/** - * Register all Viewer commands - * - * @private - */ -function _registerViewerCommands() { - const commandContext = CONTEXTS.viewer; - - CommandsManager.createContext(commandContext); - Object.keys(viewerCommandDefinitions).forEach(commandName => { - const commandDefinition = viewerCommandDefinitions[commandName]; - - CommandsManager.register(commandContext, commandName, commandDefinition); - }); -} - -/** - * Register all Cornerstone commands - * - * @private - */ -function _registerCornerstoneCommands() { - const commandContext = CONTEXTS.cornerstone; - - CommandsManager.createContext(commandContext); - Object.keys(cornerstoneCommandDefinitions).forEach(commandName => { - const commandDefinition = cornerstoneCommandDefinitions[commandName]; - - CommandsManager.register(commandContext, commandName, commandDefinition); - }); -} - -export default { - init, -};