Exposing tool groups mapping as a static method in the API class

This commit is contained in:
Bruno Alves de Faria 2017-02-10 19:57:23 -02:00
parent 1582ba3ad0
commit 8fa437b2c2

View File

@ -1,4 +1,5 @@
import { Mongo } from 'meteor/mongo'; import { Mongo } from 'meteor/mongo';
import { Tracker } from 'meteor/tracker';
import { _ } from 'meteor/underscore'; import { _ } from 'meteor/underscore';
import { OHIF } from 'meteor/ohif:core'; import { OHIF } from 'meteor/ohif:core';
@ -13,6 +14,14 @@ class MeasurementApi {
return configuration; return configuration;
} }
static getToolsGroupsMap() {
const toolsGroupsMap = {};
configuration.measurementTools.forEach(toolGroup => {
toolGroup.childTools.forEach(tool => (toolsGroupsMap[tool.id] = toolGroup.id));
});
return toolsGroupsMap;
}
constructor(timepointApi) { constructor(timepointApi) {
if (timepointApi) { if (timepointApi) {
this.timepointApi = timepointApi; this.timepointApi = timepointApi;
@ -20,7 +29,7 @@ class MeasurementApi {
this.toolGroups = {}; this.toolGroups = {};
this.tools = {}; this.tools = {};
this.toolsGroupsMap = {}; this.toolsGroupsMap = MeasurementApi.getToolsGroupsMap();
this.changeObserver = new Tracker.Dependency(); this.changeObserver = new Tracker.Dependency();
configuration.measurementTools.forEach(toolGroup => { configuration.measurementTools.forEach(toolGroup => {
@ -34,7 +43,6 @@ class MeasurementApi {
collection._debugName = tool.name; collection._debugName = tool.name;
collection.attachSchema(tool.schema); collection.attachSchema(tool.schema);
this.tools[tool.id] = collection; this.tools[tool.id] = collection;
this.toolsGroupsMap[tool.id] = toolGroup.id;
const addedHandler = measurement => { const addedHandler = measurement => {
let measurementNumber; let measurementNumber;
@ -117,7 +125,7 @@ class MeasurementApi {
const changedHandler = () => { const changedHandler = () => {
this.changeObserver.changed(); this.changeObserver.changed();
} };
const removedHandler = measurement => { const removedHandler = measurement => {
const measurementNumber = measurement.measurementNumber; const measurementNumber = measurement.measurementNumber;
@ -203,7 +211,7 @@ class MeasurementApi {
delete measurement._id; delete measurement._id;
// @TODO: check if this conditional is ok, because is throwing // @TODO: check if this conditional is ok, because is throwing
// an error for temp measurements -> measurement.toolType is undefined // an error for temp measurements -> measurement.toolType is undefined
if(measurement.toolType && this.tools[measurement.toolType]) { if (measurement.toolType && this.tools[measurement.toolType]) {
this.tools[measurement.toolType].insert(measurement); this.tools[measurement.toolType].insert(measurement);
} }
}); });