feat(plugins): Add pluginData to viewportData so that plugins can manage their own data

This commit is contained in:
Erik Ziegler 2018-08-09 10:45:58 +02:00
parent f6b82baae3
commit ddbe8b38aa
3 changed files with 11 additions and 6 deletions

View File

@ -241,16 +241,18 @@ export class LayoutManager {
// If we have been provided with a plugin to use, use it.
// Otherwise, use whichever plugin is currently in use in this viewport.
const plugin = data.plugin || this.viewportData[viewportIndex].plugin;
const pluginData = data.pluginData || this.viewportData[viewportIndex].pluginData;
// Update the dictionary of loaded displaySet for the specified viewport
this.viewportData[viewportIndex] = {
viewportIndex: viewportIndex,
viewportIndex,
displaySetInstanceUid: data.displaySetInstanceUid,
seriesInstanceUid: data.seriesInstanceUid,
studyInstanceUid: data.studyInstanceUid,
renderedCallback: data.renderedCallback,
currentImageIdIndex: data.currentImageIdIndex || 0,
plugin,
pluginData,
};
const newViewportContainer = document.createElement('div');
@ -282,7 +284,7 @@ export class LayoutManager {
container.innerHTML = '';
container.appendChild(newViewportContainer);
}
this.updateSession();
}

View File

@ -43,7 +43,9 @@ export class OHIFPlugin {
scriptURL += "?" + performance.now();
}
this.loadScript(scriptURL).onload = function() {
const type = plugin.module === true ? 'module' : 'text/javascript'
this.loadScript(scriptURL, type).onload = function() {
const entryPointFunction = OHIF.plugins.entryPoints[plugin.name];
if (entryPointFunction) {

View File

@ -64,7 +64,6 @@ export class ViewportPlugin extends OHIFPlugin {
const viewportData = layoutManager.viewportData[viewportIndex];
if (viewportData.plugin === this.name) {
OHIF.log.info(`setViewportToPlugin: Viewport ${viewportIndex} already set to plugin ${this.name}`);
return;
}
viewportData.plugin = this.name;
@ -102,16 +101,18 @@ export class ViewportPlugin extends OHIFPlugin {
// Retrieve the list of all viewports, so we can figure out the viewport details
const allViewports = Array.from(document.querySelectorAll('.viewportContainer'));
const { layoutManager } = OHIF.viewerbase;
emptyPluginDivs.forEach(div => {
// Identify the Viewport index, and any display set that is currently
// hung in the viewport
const viewportIndex = allViewports.indexOf(div.parentNode);
const viewportDetails = { viewportIndex };
const viewportData = layoutManager.viewportData[viewportIndex];
const displaySet = ViewportPlugin.getDisplaySet(viewportIndex);
// Use the plugin's setupViewport function to render the contents
// of this viewport.
this.setupViewport(div, viewportDetails, displaySet);
this.setupViewport(div, viewportData, displaySet);
});
}