diff --git a/Packages/ohif-core/both/index.js b/Packages/ohif-core/both/index.js index 94b130b86..cbe6bea3f 100644 --- a/Packages/ohif-core/both/index.js +++ b/Packages/ohif-core/both/index.js @@ -1 +1,3 @@ +import './utils'; + import './schema.js'; diff --git a/Packages/ohif-core/both/utils/index.js b/Packages/ohif-core/both/utils/index.js new file mode 100644 index 000000000..c1ac814cf --- /dev/null +++ b/Packages/ohif-core/both/utils/index.js @@ -0,0 +1 @@ +import './objectPath'; diff --git a/Packages/ohif-core/both/utils/objectPath.js b/Packages/ohif-core/both/utils/objectPath.js new file mode 100644 index 000000000..bde1b3994 --- /dev/null +++ b/Packages/ohif-core/both/utils/objectPath.js @@ -0,0 +1,116 @@ +import { OHIF } from 'meteor/ohif:core'; + +class ObjectPath { + + /** + * Set an object property based on "path" (namespace) supplied creating + * ... intermediary objects if they do not exist. + * @param object {Object} An object where the properties specified on path should be set. + * @param path {String} A string representing the property to be set, e.g. "user.study.series.timepoint". + * @param value {Any} The value of the property that will be set. + * @return {Boolean} Returns "true" on success, "false" if any intermediate component of the supplied path + * ... is not a valid Object, in which case the property cannot be set. No excpetions are thrown. + */ + static set(object, path, value) { + + let components = ObjectPath.getPathComponents(path), + length = components !== null ? components.length : 0, + result = false; + + if (length > 0 && ObjectPath.isValidObject(object)) { + + let i = 0, + last = length - 1, + currentObject = object; + + while (i < last) { + + let field = components[i]; + + if (field in currentObject) { + if (!ObjectPath.isValidObject(currentObject[field])) { + break; + } + } else { + currentObject[field] = {}; + } + + currentObject = currentObject[field]; + i++; + + } + + if (i === last) { + currentObject[components[last]] = value; + result = true; + } + + } + + return result; + + } + + /** + * Get an object property based on "path" (namespace) supplied traversing the object + * ... tree as necessary. + * @param object {Object} An object where the properties specified might exist. + * @param path {String} A string representing the property to be searched for, e.g. "user.study.series.timepoint". + * @return {Any} The value of the property if found. By default, returns the special type "undefined". + */ + static get(object, path) { + + let found, // undefined by default + components = ObjectPath.getPathComponents(path), + length = components !== null ? components.length : 0; + + if (length > 0 && ObjectPath.isValidObject(object)) { + + let i = 0, + last = length - 1, + currentObject = object; + + while (i < last) { + + let field = components[i]; + + const isValid = ObjectPath.isValidObject(currentObject[field]); + if (field in currentObject && isValid) { + currentObject = currentObject[field]; + i++; + } else { + break; + } + + } + + if (i === last && components[last] in currentObject) { + found = currentObject[components[last]]; + } + + } + + return found; + + } + + /** + * Check if the supplied argument is a real JavaScript Object instance. + * @param object {Any} The subject to be tested. + * @return {Boolean} Returns "true" if the object is a real Object instance and "false" otherwise. + */ + static isValidObject(object) { + return ( + typeof object === 'object' && + object !== null && + object instanceof Object + ); + } + + static getPathComponents(path) { + return (typeof path === 'string' ? path.split('.') : null); + } + +} + +OHIF.utils.ObjectPath = ObjectPath; diff --git a/Packages/ohif-core/client/lib/utils.js b/Packages/ohif-core/client/lib/utils.js index a164f02eb..7bd90c660 100644 --- a/Packages/ohif-core/client/lib/utils.js +++ b/Packages/ohif-core/client/lib/utils.js @@ -1,7 +1,5 @@ import { OHIF } from 'meteor/ohif:core'; -OHIF.utils = {}; - // Return the array sorting function for its object's properties OHIF.utils.sortBy = function() { var fields = [].slice.call(arguments), diff --git a/Packages/ohif-core/main.js b/Packages/ohif-core/main.js index 6ea81a663..92bc8d806 100644 --- a/Packages/ohif-core/main.js +++ b/Packages/ohif-core/main.js @@ -7,6 +7,7 @@ import { Meteor } from 'meteor/meteor'; const OHIF = { log: {}, ui: {}, + utils: {}, viewer: {} }; diff --git a/Packages/ohif-measurements/both/configuration/measurements.js b/Packages/ohif-measurements/both/configuration/measurements.js index bd60196d9..4e723c81e 100644 --- a/Packages/ohif-measurements/both/configuration/measurements.js +++ b/Packages/ohif-measurements/both/configuration/measurements.js @@ -21,6 +21,7 @@ class MeasurementApi { this.toolGroups = {}; this.tools = {}; this.toolsGroupsMap = {}; + this.changeObserver = new Tracker.Dependency(); configuration.measurementTools.forEach(toolGroup => { const groupCollection = new Mongo.Collection(null); @@ -77,6 +78,9 @@ class MeasurementApi { location } }); + + // Enable reactivity + this.changeObserver.changed(); }; const removedHandler = measurement => { @@ -107,6 +111,9 @@ class MeasurementApi { collection.update(filter, operator, options); }); } + + // Enable reactivity + this.changeObserver.changed(); }; collection.find().observe({ @@ -264,15 +271,15 @@ class MeasurementApi { }); } - fetch(measurementTypeId, selector, options) { - if (!this.toolGroups[measurementTypeId]) { - throw 'MeasurementApi: No Collection with the id: ' + measurementTypeId; + fetch(toolGroupId, selector, options) { + if (!this.toolGroups[toolGroupId]) { + throw 'MeasurementApi: No Collection with the id: ' + toolGroupId; } selector = selector || {}; options = options || {}; const result = []; - const items = this.toolGroups[measurementTypeId].find(selector, options).fetch(); + const items = this.toolGroups[toolGroupId].find(selector, options).fetch(); items.forEach(item => { result.push(this.tools[item.toolId].findOne(item.toolItemId)); }); diff --git a/Packages/ohif-measurements/client/components/caseProgress/caseProgress.html b/Packages/ohif-measurements/client/components/caseProgress/caseProgress.html index dd55654c0..e359e6586 100644 --- a/Packages/ohif-measurements/client/components/caseProgress/caseProgress.html +++ b/Packages/ohif-measurements/client/components/caseProgress/caseProgress.html @@ -1,8 +1,8 @@