diff --git a/OHIFViewer/client/components/ohifViewer/ohifViewer.js b/OHIFViewer/client/components/ohifViewer/ohifViewer.js index ab8ef732f..27f7046f4 100644 --- a/OHIFViewer/client/components/ohifViewer/ohifViewer.js +++ b/OHIFViewer/client/components/ohifViewer/ohifViewer.js @@ -57,6 +57,91 @@ Template.ohifViewer.onCreated(() => { // Set the viewer open state on session Session.set('ViewerOpened', isViewer); }); + + // Add plugin reloader + class OHIFPlugin { + // TODO: this class is here for development purposes. + // Once it is fleshed out it would go in the OHIF + // base deployment and be available for plugins + // to inherit from. + + constructor () { + this.name = "Unnamed plugin"; + this.description = "No description available"; + } + + // load an individual script URL + static loadScript(scriptURL) { + const script = document.createElement("script"); + script.src = scriptURL; + script.type = "text/javascript"; + script.async = false; + const head = document.getElementsByTagName("head")[0]; + head.appendChild(script); + head.removeChild(script); + return (script) + } + + // reload all the dependency scripts and also + // the main plugin script url. + static reloadPlugin(plugin) { + plugin.scriptURLs = plugin.scriptURLs || {}; + plugin.scriptURLs.forEach(scriptURL => { + this.loadScript(scriptURL).onload = function() { + } + }); + let scriptURL = plugin.url; + if (!plugin.allowCaching) { + scriptURL += "?" + performance.now(); + } + this.loadScript(scriptURL).onload = function() { + if (OHIFPlugin.entryPoints[plugin.name]) { + OHIFPlugin.entryPoints[plugin.name](); + } + } + } + } + + // each plugin registers an entry point function to be called + // when the loading is complete (called above in reloadPlugin). + OHIFPlugin.entryPoints = {}; + + window.OHIFPlugin = OHIFPlugin; + + // TODO: this information should come from a plug registry + let volumeRenderingPlugin = { + name: "VolumeRenderingPlugin", + url:"https://rawgit.com/OHIF/VTKPlugin/master/vtkVolumeRendering/volumeRendering.js", + allowCaching: false, + scriptURLs: [ + "https://unpkg.com/vtk.js", + ] + }; + + // // TODO: this information should come from a plug registry + // let mprPlugin = { + // name: "MPRPlugin", + // url:"http://localhost/pluginsource/mprplugin.js", + // allowCaching: false, + // scriptURLs: [ + // "https://unpkg.com/vtk.js", + // ] + // }; + + OHIF.commands.contexts.viewer.reloadVolumeRendering = { + name: "reloadVolumeRendering", + action: function(event) { + OHIFPlugin.reloadPlugin(volumeRenderingPlugin); + } + } + + // OHIF.commands.contexts.viewer.reloadVolumeRendering = { + // name: "reloadMPR", + // action: function(event) { + // OHIFPlugin.reloadPlugin(mprPlugin); + // } + // } + }); Template.ohifViewer.events({ diff --git a/OHIFViewer/client/components/toolbarSection/toolbarSection.js b/OHIFViewer/client/components/toolbarSection/toolbarSection.js index 9d0eb3601..4a8065bf5 100644 --- a/OHIFViewer/client/components/toolbarSection/toolbarSection.js +++ b/OHIFViewer/client/components/toolbarSection/toolbarSection.js @@ -84,6 +84,13 @@ Template.toolbarSection.helpers({ iconClasses: 'fa fa-crosshairs' }); + extraTools.push({ + id: 'stackScroll', + title: 'Stack Scroll', + classes: 'imageViewerTool', + iconClasses: 'fa fa-bars' + }); + extraTools.push({ id: 'magnify', title: 'Magnify', @@ -164,11 +171,13 @@ Template.toolbarSection.helpers({ const buttonData = []; + // TODO: this is just a temp hook for the volume rendering + // There needs to be a way for plugins to register new tools buttonData.push({ - id: 'stackScroll', - title: 'Stack Scroll', - classes: 'imageViewerTool', - iconClasses: 'fa fa-bars' + id: 'reloadVolumeRendering', + title: 'Volume Renderin', + classes: 'imageViewerCommand', + iconClasses: 'fa fa-undo' }); buttonData.push({