From 8fa437b2c277339df239b1da65b505238315be08 Mon Sep 17 00:00:00 2001 From: Bruno Alves de Faria Date: Fri, 10 Feb 2017 19:57:23 -0200 Subject: [PATCH] Exposing tool groups mapping as a static method in the API class --- .../both/configuration/measurements.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Packages/ohif-measurements/both/configuration/measurements.js b/Packages/ohif-measurements/both/configuration/measurements.js index 29cbc8c2f..497b03802 100644 --- a/Packages/ohif-measurements/both/configuration/measurements.js +++ b/Packages/ohif-measurements/both/configuration/measurements.js @@ -1,4 +1,5 @@ import { Mongo } from 'meteor/mongo'; +import { Tracker } from 'meteor/tracker'; import { _ } from 'meteor/underscore'; import { OHIF } from 'meteor/ohif:core'; @@ -13,6 +14,14 @@ class MeasurementApi { return configuration; } + static getToolsGroupsMap() { + const toolsGroupsMap = {}; + configuration.measurementTools.forEach(toolGroup => { + toolGroup.childTools.forEach(tool => (toolsGroupsMap[tool.id] = toolGroup.id)); + }); + return toolsGroupsMap; + } + constructor(timepointApi) { if (timepointApi) { this.timepointApi = timepointApi; @@ -20,7 +29,7 @@ class MeasurementApi { this.toolGroups = {}; this.tools = {}; - this.toolsGroupsMap = {}; + this.toolsGroupsMap = MeasurementApi.getToolsGroupsMap(); this.changeObserver = new Tracker.Dependency(); configuration.measurementTools.forEach(toolGroup => { @@ -34,7 +43,6 @@ class MeasurementApi { collection._debugName = tool.name; collection.attachSchema(tool.schema); this.tools[tool.id] = collection; - this.toolsGroupsMap[tool.id] = toolGroup.id; const addedHandler = measurement => { let measurementNumber; @@ -117,7 +125,7 @@ class MeasurementApi { const changedHandler = () => { this.changeObserver.changed(); - } + }; const removedHandler = measurement => { const measurementNumber = measurement.measurementNumber; @@ -201,9 +209,9 @@ class MeasurementApi { measurements.forEach(measurement => { 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 - if(measurement.toolType && this.tools[measurement.toolType]) { + if (measurement.toolType && this.tools[measurement.toolType]) { this.tools[measurement.toolType].insert(measurement); } });