Switch folder; dependency injection; note about moving to extensions

This commit is contained in:
dannyrb 2019-06-02 22:43:04 -04:00
parent b0706e5544
commit c1f8984c1b
5 changed files with 139 additions and 131 deletions

View File

@ -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

60
src/appCommands/index.js Normal file
View File

@ -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,
};

View File

@ -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;

View File

@ -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,
};