feat(plugins): Add initial version of ViewportPlugin class (#242)

* Add initial version of ViewportPlugin class
* Move entrypoints from OHIFPlugin to OHIF.plugins
* Add URL route to DICOMWeb server for Standalone Viewer
This commit is contained in:
Erik Ziegler authored and GitHub committed 2018-08-08 18:00:53 +02:00
1 parent ced47c765f
commit 53cd12a16a
18 files changed
+708 -562

No files matched your search

@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';import { Blaze } from 'meteor/blaze';
import { Meteor } from 'meteor/meteor';
import { Blaze } from 'meteor/blaze';
import { Session } from 'meteor/session';
import { Tracker } from 'meteor/tracker';
import { Template } from 'meteor/templating';
@@ -7,6 +8,8 @@ import { $ } from 'meteor/jquery';
import { OHIF } from 'meteor/ohif:core';
const PLUGIN_CORNERSTONE = 'cornerstone';
let isInteractingWithViewport = false;
Meteor.startup(() => {
const setInteracting = flag => {
@@ -41,11 +44,16 @@ export class LayoutManager {
this.isZoomed = false;
const updateSessionFn = () => Tracker.afterFlush(() => {
Session.set('LayoutManagerUpdated', Math.random());
const updateSessionFn = () => {
const random = Math.random();
Session.set('LayoutManagerUpdated', random);
this.observer.changed();
};
this.updateSession = _.throttle(updateSessionFn, 300, {
leading: true,
trailing: false
});
this.updateSession = _.throttle(updateSessionFn, 300);
}
/**
@@ -121,7 +129,8 @@ export class LayoutManager {
studyInstanceUid,
seriesInstanceUid,
displaySetInstanceUid,
sopInstanceUid
sopInstanceUid,
plugin: PLUGIN_CORNERSTONE
};
additionalData.push(data);
@@ -181,6 +190,12 @@ export class LayoutManager {
this.setDefaultViewportData();
}
this.viewportData.forEach(data => {
if (!data.plugin) {
data.plugin = PLUGIN_CORNERSTONE;
}
})
// imageViewerViewports occasionally needs relevant layout data in order to set
// the element style of the viewport in question
const layoutProps = this.layoutProps;
@@ -190,13 +205,13 @@ export class LayoutManager {
this.viewportData.forEach(viewportData => {
const viewportDataAndLayoutProps = $.extend(viewportData, layoutProps);
data.viewportData.push(viewportDataAndLayoutProps);
});
const layoutTemplate = Template[this.layoutTemplateName];
const $parentNode = $(this.parentNode);
$parentNode.html('');
this.parentNode.innerHTML = '';
this.updateLayoutClass();
Blaze.renderWithData(layoutTemplate, data, this.parentNode);
@@ -218,12 +233,15 @@ export class LayoutManager {
OHIF.log.info(`LayoutManager rerenderViewportWithNewDisplaySet: ${viewportIndex}`);
// The parent container is identified because it is later removed from the DOM
const element = $('.imageViewerViewport').eq(viewportIndex);
const container = element.parents('.viewportContainer').get(0);
const container = $('.viewportContainer').get(viewportIndex);
// Record the current viewportIndex so this can be passed into the re-rendering call
data.viewportIndex = viewportIndex;
// 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;
// Update the dictionary of loaded displaySet for the specified viewport
this.viewportData[viewportIndex] = {
viewportIndex: viewportIndex,
@@ -231,27 +249,40 @@ export class LayoutManager {
seriesInstanceUid: data.seriesInstanceUid,
studyInstanceUid: data.studyInstanceUid,
renderedCallback: data.renderedCallback,
currentImageIdIndex: data.currentImageIdIndex || 0
currentImageIdIndex: data.currentImageIdIndex || 0,
plugin,
};
// Remove the hover styling
element.find('canvas').not('.magnifyTool').removeClass('faded');
// Remove the whole template, add in the new one
const viewportContainer = element.parents('.removable');
const newViewportContainer = document.createElement('div');
newViewportContainer.className = 'removable';
// Remove the parent element of the template
// This is a workaround since otherwise Blaze UI onDestroyed doesn't fire
viewportContainer.remove();
container.appendChild(newViewportContainer);
// Render and insert the template
Blaze.renderWithData(Template.imageViewerViewport, data, newViewportContainer);
if (plugin === PLUGIN_CORNERSTONE) {
// Remove the hover styling
const element = $(container).find('.imageViewerViewport');
element.find('canvas').not('.magnifyTool').removeClass('faded');
// Remove the whole template, add in the new one
const viewportContainer = element.parents('.removable');
newViewportContainer.className = 'removable';
// Remove the parent element of the template
// This is a workaround since otherwise Blaze UI onDestroyed doesn't fire
viewportContainer.remove();
container.appendChild(newViewportContainer);
Blaze.renderWithData(Template.imageViewerViewport, data, newViewportContainer);
} else {
newViewportContainer.className = `viewport-plugin-${plugin}`;
newViewportContainer.style.width = '100%';
newViewportContainer.style.height = '100%';
container.innerHTML = '';
container.appendChild(newViewportContainer);
}
this.updateSession();
}
@@ -283,7 +314,7 @@ export class LayoutManager {
const layoutTemplate = Template.gridLayout;
$(this.parentNode).html('');
this.parentNode.innerHTML = '';
Blaze.renderWithData(layoutTemplate, data, this.parentNode);
this.isZoomed = true;