ToolBarService
This commit is contained in:
parent
aec30e0db1
commit
6a3e0db53e
@ -28,12 +28,9 @@ function ViewerLayout({
|
|||||||
rightPanels,
|
rightPanels,
|
||||||
viewports,
|
viewports,
|
||||||
children,
|
children,
|
||||||
ViewportGridComp
|
ViewportGridComp,
|
||||||
}) {
|
}) {
|
||||||
const [displaySets, setDisplaySets] = useState({});
|
const { ToolBarService } = servicesManager.services;
|
||||||
|
|
||||||
//const ViewportGrid = React.Children.only(children);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set body classes (tailwindcss) that don't allow vertical
|
* Set body classes (tailwindcss) that don't allow vertical
|
||||||
* or horizontal overflow (no scrolling). Also guarantee window
|
* or horizontal overflow (no scrolling). Also guarantee window
|
||||||
@ -47,6 +44,7 @@ function ViewerLayout({
|
|||||||
document.body.classList.remove('overflow-hidden');
|
document.body.classList.remove('overflow-hidden');
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getPanelData = id => {
|
const getPanelData = id => {
|
||||||
const entry = extensionManager.getModuleEntry(id);
|
const entry = extensionManager.getModuleEntry(id);
|
||||||
// TODO, not sure why sidepanel content has to be JSX, and not a children prop?
|
// TODO, not sure why sidepanel content has to be JSX, and not a children prop?
|
||||||
@ -70,27 +68,34 @@ function ViewerLayout({
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleToolBarSubscription = newToolBarLayout => {
|
||||||
|
debugger;
|
||||||
|
setToolBarLayout(newToolBarLayout);
|
||||||
|
};
|
||||||
|
|
||||||
|
const [toolBarLayout, setToolBarLayout] = useState([
|
||||||
|
{ tools: [], moreTools: [] },
|
||||||
|
{ tools: [] },
|
||||||
|
]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const { unsubscribe } = ToolBarService.subscribe(
|
||||||
|
ToolBarService.EVENTS.TOOL_BAR_MODIFIED,
|
||||||
|
handleToolBarSubscription
|
||||||
|
);
|
||||||
|
|
||||||
|
return unsubscribe;
|
||||||
|
}, []);
|
||||||
|
|
||||||
const leftPanelComponents = leftPanels.map(getPanelData);
|
const leftPanelComponents = leftPanels.map(getPanelData);
|
||||||
const rightPanelComponents = rightPanels.map(getPanelData);
|
const rightPanelComponents = rightPanels.map(getPanelData);
|
||||||
const viewportComponents = viewports.map(getViewportComponentData);
|
const viewportComponents = viewports.map(getViewportComponentData);
|
||||||
|
|
||||||
// let { toolBarLayout } = useToolbarLayout();
|
|
||||||
// if (!toolBarLayout.length) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// TODO -> make toolbar service
|
|
||||||
const toolBarLayout = { tools: [], moreTools: [] };
|
|
||||||
|
|
||||||
//const [primaryToolBarLayout, secondaryToolBarLayout] = toolBarLayout;
|
|
||||||
const primaryToolBarLayout = toolBarLayout;
|
|
||||||
const secondaryToolBarLayout = toolBarLayout;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Header
|
<Header
|
||||||
tools={primaryToolBarLayout.tools}
|
tools={toolBarLayout[0].tools}
|
||||||
moreTools={primaryToolBarLayout.moreTools}
|
moreTools={toolBarLayout[0].moreTools}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className="flex flex-row flex-no-wrap items-stretch overflow-hidden w-full"
|
className="flex flex-row flex-no-wrap items-stretch overflow-hidden w-full"
|
||||||
@ -105,7 +110,7 @@ function ViewerLayout({
|
|||||||
{/* TOOLBAR + GRID */}
|
{/* TOOLBAR + GRID */}
|
||||||
<div className="flex flex-col flex-1 h-full">
|
<div className="flex flex-col flex-1 h-full">
|
||||||
<div className="flex flex-2 w-100 border-b border-transparent h-12">
|
<div className="flex flex-2 w-100 border-b border-transparent h-12">
|
||||||
<Toolbar type="secondary" tools={secondaryToolBarLayout.tools} />
|
<Toolbar type="secondary" tools={toolBarLayout[1].tools} />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-1 h-full overflow-hidden bg-black items-center justify-center pb-2 pt-1">
|
<div className="flex flex-1 h-full overflow-hidden bg-black items-center justify-center pb-2 pt-1">
|
||||||
<ViewportGridComp
|
<ViewportGridComp
|
||||||
|
|||||||
@ -12,8 +12,10 @@ export default function mode({ modeConfiguration }) {
|
|||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: 'viewer',
|
path: 'viewer',
|
||||||
init: ({ toolBarManager }) => {
|
init: ({ servicesManager, extensionManager }) => {
|
||||||
toolBarManager.addButtons([
|
const { ToolBarService } = servicesManager.services;
|
||||||
|
ToolBarService.init(extensionManager);
|
||||||
|
ToolBarService.addButtons([
|
||||||
{
|
{
|
||||||
id: 'Zoom',
|
id: 'Zoom',
|
||||||
namespace: 'org.ohif.cornerstone.toolbarModule.Zoom',
|
namespace: 'org.ohif.cornerstone.toolbarModule.Zoom',
|
||||||
@ -53,7 +55,7 @@ export default function mode({ modeConfiguration }) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Could import layout selector here from org.ohif.default (when it exists!)
|
// Could import layout selector here from org.ohif.default (when it exists!)
|
||||||
toolBarManager.setToolBarLayout([
|
ToolBarService.setToolBarLayout([
|
||||||
// Primary
|
// Primary
|
||||||
{
|
{
|
||||||
tools: ['Zoom', 'Levels', 'Pan', 'Capture', 'Layout'],
|
tools: ['Zoom', 'Levels', 'Pan', 'Capture', 'Layout'],
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
export default class toolBarManager {
|
|
||||||
constructor(extensionManager) {
|
|
||||||
this.buttons = {};
|
|
||||||
this.extensionManager = extensionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
addButtons(buttons) {
|
|
||||||
buttons.forEach(button => {
|
|
||||||
const buttonDefinition = this.extensionManager.getModuleEntry(
|
|
||||||
button.namespace
|
|
||||||
);
|
|
||||||
|
|
||||||
const id = button.id || buttonDefinition.id;
|
|
||||||
|
|
||||||
this.buttons[id] = buttonDefinition;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setToolBarLayout(layouts) {
|
|
||||||
const toolBarLayout = [];
|
|
||||||
|
|
||||||
layouts.forEach(layout => {
|
|
||||||
const toolBarDefinitions = { tools: [], moreTools: [] };
|
|
||||||
|
|
||||||
const { tools, moreTools } = layout;
|
|
||||||
|
|
||||||
tools &&
|
|
||||||
tools.forEach(element => {
|
|
||||||
const button = this.buttons[element];
|
|
||||||
|
|
||||||
toolBarDefinitions.tools.push(button);
|
|
||||||
});
|
|
||||||
|
|
||||||
moreTools &&
|
|
||||||
moreTools.forEach(element => {
|
|
||||||
const button = this.buttons[element];
|
|
||||||
|
|
||||||
toolBarDefinitions.moreTools.push(button);
|
|
||||||
});
|
|
||||||
|
|
||||||
toolBarLayout.push(toolBarDefinitions);
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO -> Change this to a service. => emit an event to subscribers to update the toolbar layout.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -20,7 +20,6 @@ import studies from './studies/';
|
|||||||
import ui from './ui';
|
import ui from './ui';
|
||||||
import user from './user.js';
|
import user from './user.js';
|
||||||
import dicomMetadataStore from './dicomMetadataStore';
|
import dicomMetadataStore from './dicomMetadataStore';
|
||||||
import ToolBarManager from './ToolBarManager';
|
|
||||||
import { ViewModelProvider, useViewModel } from './ViewModelContext';
|
import { ViewModelProvider, useViewModel } from './ViewModelContext';
|
||||||
import {
|
import {
|
||||||
ToolbarLayoutProvider,
|
ToolbarLayoutProvider,
|
||||||
@ -35,6 +34,7 @@ import {
|
|||||||
UINotificationService,
|
UINotificationService,
|
||||||
UIViewportDialogService,
|
UIViewportDialogService,
|
||||||
DisplaySetService,
|
DisplaySetService,
|
||||||
|
ToolBarSerivce,
|
||||||
} from './services';
|
} from './services';
|
||||||
|
|
||||||
import IWebApiDataSource from './DataSources/IWebApiDataSource';
|
import IWebApiDataSource from './DataSources/IWebApiDataSource';
|
||||||
@ -73,10 +73,10 @@ const OHIF = {
|
|||||||
UIViewportDialogService,
|
UIViewportDialogService,
|
||||||
DisplaySetService,
|
DisplaySetService,
|
||||||
MeasurementService,
|
MeasurementService,
|
||||||
|
ToolBarSerivce,
|
||||||
IWebApiDataSource,
|
IWebApiDataSource,
|
||||||
dicomMetadataStore,
|
dicomMetadataStore,
|
||||||
//
|
//
|
||||||
ToolBarManager,
|
|
||||||
ViewModelProvider,
|
ViewModelProvider,
|
||||||
useViewModel,
|
useViewModel,
|
||||||
};
|
};
|
||||||
@ -114,9 +114,9 @@ export {
|
|||||||
UIViewportDialogService,
|
UIViewportDialogService,
|
||||||
DisplaySetService,
|
DisplaySetService,
|
||||||
MeasurementService,
|
MeasurementService,
|
||||||
|
ToolBarSerivce,
|
||||||
IWebApiDataSource,
|
IWebApiDataSource,
|
||||||
dicomMetadataStore,
|
dicomMetadataStore,
|
||||||
ToolBarManager,
|
|
||||||
ViewModelProvider,
|
ViewModelProvider,
|
||||||
useViewModel,
|
useViewModel,
|
||||||
ToolbarLayoutProvider,
|
ToolbarLayoutProvider,
|
||||||
|
|||||||
@ -98,9 +98,9 @@ export default class DisplaySetService {
|
|||||||
displaySetsAdded = displaySets;
|
displaySetsAdded = displaySets;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If array of array of instances
|
if (displaySetsAdded.length) {
|
||||||
|
this._broadcastChange(EVENTS.DISPLAY_SETS_ADDED, displaySetsAdded);
|
||||||
this._broadcastChange(EVENTS.DISPLAY_SETS_ADDED, displaySetsAdded);
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
makeDisplaySetForInstances(instances) {
|
makeDisplaySetForInstances(instances) {
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
import pubSubServiceInterface from '../pubSubServiceInterface';
|
import pubSubServiceInterface from '../pubSubServiceInterface';
|
||||||
|
|
||||||
|
const EVENTS = {
|
||||||
|
TOOL_BAR_MODIFIED: 'event::toolBarService:toolBarModified',
|
||||||
|
};
|
||||||
|
|
||||||
export default class ToolBarService {
|
export default class ToolBarService {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.displaySets = {};
|
this.displaySets = {};
|
||||||
@ -26,6 +30,23 @@ export default class ToolBarService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcasts displaySetService changes.
|
||||||
|
*
|
||||||
|
* @param {string} eventName The event name
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
_broadcastChange = (eventName, callbackProps) => {
|
||||||
|
const hasListeners = Object.keys(this.listeners).length > 0;
|
||||||
|
const hasCallbacks = Array.isArray(this.listeners[eventName]);
|
||||||
|
|
||||||
|
if (hasListeners && hasCallbacks) {
|
||||||
|
this.listeners[eventName].forEach(listener => {
|
||||||
|
listener.callback(callbackProps);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
setToolBarLayout(layouts) {
|
setToolBarLayout(layouts) {
|
||||||
const toolBarLayout = [];
|
const toolBarLayout = [];
|
||||||
|
|
||||||
@ -51,6 +72,8 @@ export default class ToolBarService {
|
|||||||
toolBarLayout.push(toolBarDefinitions);
|
toolBarLayout.push(toolBarDefinitions);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO -> Change this to a service. => emit an event to subscribers to update the toolbar layout.
|
this.toolBarLayout = toolBarLayout;
|
||||||
|
|
||||||
|
this._broadcastChange(this.EVENTS.TOOL_BAR_MODIFIED, toolBarLayout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
platform/core/src/services/ToolBarService/index.js
Normal file
8
platform/core/src/services/ToolBarService/index.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import ToolBarService from './ToolBarService';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ToolBarService',
|
||||||
|
create: ({ configuration = {} }) => {
|
||||||
|
return new ToolBarService();
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -5,6 +5,7 @@ import UIModalService from './UIModalService';
|
|||||||
import UINotificationService from './UINotificationService';
|
import UINotificationService from './UINotificationService';
|
||||||
import UIViewportDialogService from './UIViewportDialogService';
|
import UIViewportDialogService from './UIViewportDialogService';
|
||||||
import DisplaySetService from './DisplaySetService';
|
import DisplaySetService from './DisplaySetService';
|
||||||
|
import ToolBarSerivce from './ToolBarService';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
MeasurementService,
|
MeasurementService,
|
||||||
@ -14,4 +15,5 @@ export {
|
|||||||
UINotificationService,
|
UINotificationService,
|
||||||
UIViewportDialogService,
|
UIViewportDialogService,
|
||||||
DisplaySetService,
|
DisplaySetService,
|
||||||
|
ToolBarSerivce,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import {
|
|||||||
UIDialogService,
|
UIDialogService,
|
||||||
MeasurementService,
|
MeasurementService,
|
||||||
DisplaySetService,
|
DisplaySetService,
|
||||||
|
ToolBarSerivce,
|
||||||
// utils,
|
// utils,
|
||||||
// redux as reduxOHIF,
|
// redux as reduxOHIF,
|
||||||
} from '@ohif/core';
|
} from '@ohif/core';
|
||||||
@ -45,6 +46,7 @@ function appInit(appConfigOrFunc, defaultExtensions) {
|
|||||||
UIDialogService,
|
UIDialogService,
|
||||||
MeasurementService,
|
MeasurementService,
|
||||||
DisplaySetService,
|
DisplaySetService,
|
||||||
|
ToolBarSerivce,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,55 +0,0 @@
|
|||||||
import { useEffect, useCallback } from 'react';
|
|
||||||
import {
|
|
||||||
displaySetManager,
|
|
||||||
ToolBarManager,
|
|
||||||
useViewModel,
|
|
||||||
useToolbarLayout,
|
|
||||||
} from '@ohif/core';
|
|
||||||
|
|
||||||
export default function DisplaySetCreator({
|
|
||||||
location,
|
|
||||||
mode,
|
|
||||||
dataSourceName,
|
|
||||||
extensionManager,
|
|
||||||
DisplaySetService,
|
|
||||||
}) {
|
|
||||||
console.warn('DisplaySetCreator rerendering');
|
|
||||||
const { routes, sopClassHandlers } = mode;
|
|
||||||
const dataSources = extensionManager.getDataSources(dataSourceName);
|
|
||||||
// TODO: For now assume one unique datasource.
|
|
||||||
|
|
||||||
const dataSource = dataSources[0];
|
|
||||||
const route = routes[0];
|
|
||||||
|
|
||||||
// Add toolbar state to the view model context?
|
|
||||||
const { displaySetInstanceUIDs, setDisplaySetInstanceUIDs } = useViewModel();
|
|
||||||
|
|
||||||
const { toolBarLayout, setToolBarLayout } = useToolbarLayout();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let toolBarManager = new ToolBarManager(extensionManager, setToolBarLayout);
|
|
||||||
route.init({ toolBarManager });
|
|
||||||
}, [mode, dataSourceName, location]);
|
|
||||||
|
|
||||||
const createDisplaySets = useCallback(() => {
|
|
||||||
// Add SOPClassHandlers to a new SOPClassManager.
|
|
||||||
displaySetManager.init(extensionManager, sopClassHandlers, {
|
|
||||||
displaySetInstanceUIDs,
|
|
||||||
setDisplaySetInstanceUIDs,
|
|
||||||
});
|
|
||||||
|
|
||||||
const queryParams = location.search;
|
|
||||||
|
|
||||||
// Call the data source to start building the view model?
|
|
||||||
dataSource.retrieve.series.metadata(
|
|
||||||
queryParams,
|
|
||||||
displaySetManager.makeDisplaySets
|
|
||||||
);
|
|
||||||
}, [displaySetInstanceUIDs, location]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
createDisplaySets();
|
|
||||||
}, [mode, dataSourceName, location]);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@ -1,12 +1,10 @@
|
|||||||
import React, { useEffect, useCallback } from 'react';
|
import React, { useEffect, useCallback } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
//
|
//
|
||||||
import { ToolBarManager } from '@ohif/core';
|
|
||||||
import { DragAndDropProvider } from '@ohif/ui';
|
import { DragAndDropProvider } from '@ohif/ui';
|
||||||
//
|
//
|
||||||
import ViewportGrid from '@components/ViewportGrid';
|
import ViewportGrid from '@components/ViewportGrid';
|
||||||
import Compose from './Compose';
|
import Compose from './Compose';
|
||||||
//import DisplaySetCreator from './DisplaySetCreator';
|
|
||||||
|
|
||||||
export default function ModeRoute({
|
export default function ModeRoute({
|
||||||
location,
|
location,
|
||||||
@ -58,9 +56,7 @@ export default function ModeRoute({
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// TODO -> Make this into a service
|
route.init({ servicesManager, extensionManager });
|
||||||
let toolBarManager = new ToolBarManager(extensionManager); //, setToolBarLayout);
|
|
||||||
route.init({ toolBarManager });
|
|
||||||
}, [mode, dataSourceName, location]);
|
}, [mode, dataSourceName, location]);
|
||||||
|
|
||||||
const createDisplaySets = useCallback(() => {
|
const createDisplaySets = useCallback(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user