From 18a3bcba30b29c9f0ed7297983d520e20763ce31 Mon Sep 17 00:00:00 2001 From: Erik Ziegler Date: Fri, 21 Sep 2018 20:02:29 +0200 Subject: [PATCH] fix(client-only): Fix client-only Server & CurrentServer usage (#276) --- OHIFViewer/client/config.js | 6 +++ OHIFViewer/client/routes.js | 5 +- .../client/protocolStore/defaultStrategy.js | 10 ++-- .../both/collections/currentServer.js | 7 ++- .../ohif-servers/both/collections/servers.js | 7 ++- .../ohif-servers/client/collections/index.js | 1 - .../client/collections/subscriptions.js | 4 -- Packages/ohif-servers/client/index.js | 2 +- Packages/ohif-servers/client/startup.js | 32 ++++++++++++ Packages/ohif-servers/server/startup.js | 49 ++++++++++--------- 10 files changed, 86 insertions(+), 37 deletions(-) delete mode 100644 Packages/ohif-servers/client/collections/index.js delete mode 100644 Packages/ohif-servers/client/collections/subscriptions.js create mode 100644 Packages/ohif-servers/client/startup.js diff --git a/OHIFViewer/client/config.js b/OHIFViewer/client/config.js index c9cf87abd..c726f5a64 100644 --- a/OHIFViewer/client/config.js +++ b/OHIFViewer/client/config.js @@ -30,3 +30,9 @@ Meteor.startup(function() { } }); }); + +if (Meteor.settings && + Meteor.settings.public && + Meteor.settings.public.clientOnly === true) { + Meteor.disconnect(); +} diff --git a/OHIFViewer/client/routes.js b/OHIFViewer/client/routes.js index f8e3b0d0b..7b0935ae0 100644 --- a/OHIFViewer/client/routes.js +++ b/OHIFViewer/client/routes.js @@ -1,3 +1,4 @@ +import { Meteor } from "meteor/meteor"; import { Router } from 'meteor/clinical:router'; import { OHIF } from 'meteor/ohif:core'; @@ -12,7 +13,9 @@ Router.configure({ // // In this case, the developer is required to add Servers and specify // a CurrentServer with some other approach (e.g. a separate script). -if (Meteor.settings.public && Meteor.settings.public.clientOnly !== true) { +if (Meteor.settings && + Meteor.settings.public && + Meteor.settings.public.clientOnly !== true) { Router.waitOn(function() { return [ Meteor.subscribe('servers'), diff --git a/Packages/ohif-hanging-protocols/client/protocolStore/defaultStrategy.js b/Packages/ohif-hanging-protocols/client/protocolStore/defaultStrategy.js index c3684af7b..bd78131ba 100644 --- a/Packages/ohif-hanging-protocols/client/protocolStore/defaultStrategy.js +++ b/Packages/ohif-hanging-protocols/client/protocolStore/defaultStrategy.js @@ -1,3 +1,4 @@ +import { Meteor } from "meteor/meteor"; // The ProtocolStore default strategy is used to persist hanging protocols in // the MongoDB collection 'HangingProtocols' in the application server. @@ -9,11 +10,6 @@ var defaultStrategy = (function () { console.log('Inserting default protocols'); addProtocol(HP.defaultProtocol); - - //addProtocol(HP.testProtocol); - /* HP.demoProtocols.forEach(protocol => { - addProtocol(protocol); - });*/ } function getDatabaseIdByProtocolId(protocolId) { @@ -303,7 +299,9 @@ var clientOnlyStrategy = (function () { // If we are running a disconnect client similar to the StandaloneViewer // (see https://docs.ohif.org/standalone-viewer/usage.html) we don't want // our HangingProtocol strategy to try to use Meteor methods or Pub / Sub -if (Meteor.settings.public && Meteor.settings.public.clientOnly === true) { +if (Meteor.settings && + Meteor.settings.public && + Meteor.settings.public.clientOnly === true) { HP.ProtocolStore.setStrategy(clientOnlyStrategy); } else { HP.ProtocolStore.setStrategy(defaultStrategy); diff --git a/Packages/ohif-servers/both/collections/currentServer.js b/Packages/ohif-servers/both/collections/currentServer.js index 94ee8e5c9..5e34836ab 100644 --- a/Packages/ohif-servers/both/collections/currentServer.js +++ b/Packages/ohif-servers/both/collections/currentServer.js @@ -2,7 +2,12 @@ import { Mongo } from 'meteor/mongo'; import { OHIF } from 'meteor/ohif:core'; // CurrentServer is a single document collection to describe which of the Servers is being used -const CurrentServer = new Mongo.Collection('currentServer'); +let collectionName = 'currentServer'; +if (Meteor.settings && Meteor.settings.public && Meteor.settings.public.clientOnly === true) { + collectionName = null; +} + +const CurrentServer = new Mongo.Collection(collectionName); CurrentServer._debugName = 'CurrentServer'; OHIF.servers.collections.currentServer = CurrentServer; diff --git a/Packages/ohif-servers/both/collections/servers.js b/Packages/ohif-servers/both/collections/servers.js index 1c9663e6b..4579c1118 100644 --- a/Packages/ohif-servers/both/collections/servers.js +++ b/Packages/ohif-servers/both/collections/servers.js @@ -2,8 +2,13 @@ import { Mongo } from 'meteor/mongo'; import { OHIF } from 'meteor/ohif:core'; // import { Servers as ServerSchema } from 'meteor/ohif:servers/both/schema/servers.js'; +let collectionName = 'servers'; +if (Meteor.settings && Meteor.settings.public && Meteor.settings.public.clientOnly === true) { + collectionName = null; +} + // Servers describe the DICOM servers configurations -const Servers = new Mongo.Collection('servers'); +const Servers = new Mongo.Collection(collectionName); // TODO: Make the Schema match what we are currently sticking into the Collection //Servers.attachSchema(ServerSchema); Servers._debugName = 'Servers'; diff --git a/Packages/ohif-servers/client/collections/index.js b/Packages/ohif-servers/client/collections/index.js deleted file mode 100644 index 8e673e096..000000000 --- a/Packages/ohif-servers/client/collections/index.js +++ /dev/null @@ -1 +0,0 @@ -import './subscriptions.js'; diff --git a/Packages/ohif-servers/client/collections/subscriptions.js b/Packages/ohif-servers/client/collections/subscriptions.js deleted file mode 100644 index 85a3cb1bf..000000000 --- a/Packages/ohif-servers/client/collections/subscriptions.js +++ /dev/null @@ -1,4 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -Meteor.subscribe('servers'); -Meteor.subscribe('currentServer'); diff --git a/Packages/ohif-servers/client/index.js b/Packages/ohif-servers/client/index.js index 1a0a81c4b..54ffeab14 100644 --- a/Packages/ohif-servers/client/index.js +++ b/Packages/ohif-servers/client/index.js @@ -1,2 +1,2 @@ -import './collections'; +import './startup.js'; import './components'; diff --git a/Packages/ohif-servers/client/startup.js b/Packages/ohif-servers/client/startup.js new file mode 100644 index 000000000..de120dcc1 --- /dev/null +++ b/Packages/ohif-servers/client/startup.js @@ -0,0 +1,32 @@ +// Check the servers on meteor startup +import { Meteor } from "meteor/meteor"; +import { Servers, CurrentServer } from 'meteor/ohif:servers/both/collections'; + +if (Meteor.settings && + Meteor.settings.public && + Meteor.settings.public.clientOnly === true && + Meteor.settings.public.servers) { + OHIF.log.info('Updating servers information from JSON configuration'); + + const servers = Meteor.settings.public.servers; + + Object.keys(servers).forEach((serverType) => { + const endpoints = servers[serverType]; + endpoints.forEach((endpoint) => { + const server = Object.assign({}, endpoint); + server.origin = 'json'; + server.type = serverType; + + Servers.insert(server); + }); + }); + + const newServer = Servers.findOne(); + + CurrentServer.insert({ + serverId: newServer._id + }); + + console.log('test'); +} + diff --git a/Packages/ohif-servers/server/startup.js b/Packages/ohif-servers/server/startup.js index a28c6d7a6..e34a2cca4 100644 --- a/Packages/ohif-servers/server/startup.js +++ b/Packages/ohif-servers/server/startup.js @@ -5,30 +5,35 @@ import { Servers } from 'meteor/ohif:servers/both/collections'; import { ServerConfiguration } from 'meteor/ohif:servers/both/schema/servers.js'; // Check the servers on meteor startup -Meteor.startup(function() { - OHIF.log.info('Updating servers information from JSON configuration'); +if (Meteor.settings && + Meteor.settings.public && + Meteor.settings.public.clientOnly !== true) { - _.each(Meteor.settings.servers, function(endpoints, serverType) { - _.each(endpoints, function(endpoint) { - const server = _.clone(endpoint); - server.origin = 'json'; - server.type = serverType; + Meteor.startup(function() { + OHIF.log.info('Updating servers information from JSON configuration'); - // Try to find a server with the same name/type/origin combination - const existingServer = Servers.findOne({ - name: server.name, - type: server.type, - origin: server.origin + _.each(Meteor.settings.servers, function(endpoints, serverType) { + _.each(endpoints, function(endpoint) { + const server = _.clone(endpoint); + server.origin = 'json'; + server.type = serverType; + + // Try to find a server with the same name/type/origin combination + const existingServer = Servers.findOne({ + name: server.name, + type: server.type, + origin: server.origin + }); + + // Check if server was already added. Update it if so and insert if not + if (existingServer) { + Servers.update(existingServer._id, { $set: server }); + } else { + Servers.insert(server); + } }); - - // Check if server was already added. Update it if so and insert if not - if (existingServer) { - Servers.update(existingServer._id, { $set: server }); - } else { - Servers.insert(server); - } }); - }); - OHIF.servers.control.resetCurrentServer(); -}); + OHIF.servers.control.resetCurrentServer(); + }); +}