Permalink
Browse files

fix(client-only): Fix client-only Server & CurrentServer usage (#276)

  • Loading branch information...
swederik committed Sep 21, 2018
1 parent c4b1086 commit 18a3bcba30b29c9f0ed7297983d520e20763ce31
@@ -30,3 +30,9 @@ Meteor.startup(function() {
}
});
});
if (Meteor.settings &&
Meteor.settings.public &&
Meteor.settings.public.clientOnly === true) {
Meteor.disconnect();
}
@@ -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'),
@@ -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);
@@ -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;
@@ -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';

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,2 +1,2 @@
import './collections';
import './startup.js';
import './components';
@@ -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');
}
@@ -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();
});
}

0 comments on commit 18a3bcb

Please sign in to comment.