2016-08-10 15:39:31 +02:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-06-16 21:36:34 +02:00
|
|
|
import { OHIF } from 'meteor/ohif:core';
|
|
|
|
|
import { Servers, CurrentServer } from 'meteor/ohif:servers/both/collections';
|
2016-04-21 23:14:28 +02:00
|
|
|
|
2017-06-16 21:36:34 +02:00
|
|
|
OHIF.servers.control = {
|
|
|
|
|
writeCallback(error, affected) {
|
2016-06-01 19:50:17 +02:00
|
|
|
if (error) {
|
|
|
|
|
throw new Meteor.Error('data-write', error);
|
|
|
|
|
}
|
2017-06-16 21:36:34 +02:00
|
|
|
},
|
2016-06-01 19:50:17 +02:00
|
|
|
|
2017-06-16 21:36:34 +02:00
|
|
|
resetCurrentServer() {
|
2016-09-29 17:25:04 +02:00
|
|
|
const currentServer = CurrentServer.findOne();
|
|
|
|
|
if (currentServer && Servers.find({ _id: currentServer.serverId }).count()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const newServer = Servers.findOne({
|
|
|
|
|
origin: 'json',
|
|
|
|
|
type: Meteor.settings.defaultServiceType || 'dicomWeb'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (newServer) {
|
|
|
|
|
CurrentServer.remove({});
|
|
|
|
|
CurrentServer.insert({
|
|
|
|
|
serverId: newServer._id
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-06-16 21:36:34 +02:00
|
|
|
},
|
2016-09-29 17:25:04 +02:00
|
|
|
|
2017-06-16 21:36:34 +02:00
|
|
|
find(query) {
|
2016-09-29 17:25:04 +02:00
|
|
|
return Servers.find(query).fetch();
|
2017-06-16 21:36:34 +02:00
|
|
|
},
|
2016-09-29 17:25:04 +02:00
|
|
|
|
2017-06-16 21:36:34 +02:00
|
|
|
save(serverSettings) {
|
2016-09-29 17:25:04 +02:00
|
|
|
const query = {
|
2016-05-07 15:34:27 +02:00
|
|
|
_id: serverSettings._id
|
|
|
|
|
};
|
2016-09-29 17:25:04 +02:00
|
|
|
const options = {
|
2016-05-07 15:34:27 +02:00
|
|
|
upsert: true
|
|
|
|
|
};
|
2016-05-14 17:30:11 +02:00
|
|
|
|
|
|
|
|
if (!serverSettings._id) {
|
|
|
|
|
delete serverSettings._id;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 19:50:17 +02:00
|
|
|
return Servers.update(query, serverSettings, options, this.writeCallback);
|
2017-06-16 21:36:34 +02:00
|
|
|
},
|
2016-04-21 23:14:28 +02:00
|
|
|
|
2017-06-16 21:36:34 +02:00
|
|
|
setActive(serverId) {
|
2016-09-29 17:25:04 +02:00
|
|
|
CurrentServer.remove({});
|
|
|
|
|
CurrentServer.insert({
|
|
|
|
|
serverId: serverId
|
|
|
|
|
});
|
2017-06-16 21:36:34 +02:00
|
|
|
},
|
2016-05-07 15:34:27 +02:00
|
|
|
|
2017-06-16 21:36:34 +02:00
|
|
|
remove(serverId) {
|
2016-10-01 18:58:21 +02:00
|
|
|
const query = {
|
2016-05-15 04:46:10 +02:00
|
|
|
_id: serverId
|
|
|
|
|
};
|
2016-09-29 17:25:04 +02:00
|
|
|
|
|
|
|
|
const removeStatus = Servers.remove(query, this.writeCallback);
|
|
|
|
|
|
2017-06-16 21:36:34 +02:00
|
|
|
OHIF.servers.control.resetCurrentServer();
|
2016-09-29 17:25:04 +02:00
|
|
|
|
|
|
|
|
return removeStatus;
|
2016-05-07 15:34:27 +02:00
|
|
|
}
|
2017-06-16 21:36:34 +02:00
|
|
|
};
|