diff --git a/Packages/ohif-hanging-protocols/client/components/ruleTable/ruleTable.html b/Packages/ohif-hanging-protocols/client/components/ruleTable/ruleTable.html
index 0ae6b1cdd..3af9e7e65 100644
--- a/Packages/ohif-hanging-protocols/client/components/ruleTable/ruleTable.html
+++ b/Packages/ohif-hanging-protocols/client/components/ruleTable/ruleTable.html
@@ -14,7 +14,7 @@
- {{displayConstraint attribute constraint}}
+ {{displayConstraint attribute constraint ../attributes}}
{{ #unless rulePassed }}Fail{{ /unless }}
|
|
diff --git a/Packages/ohif-hanging-protocols/client/helpers/attributes.js b/Packages/ohif-hanging-protocols/client/helpers/attributes.js
index 464908940..c1815874b 100644
--- a/Packages/ohif-hanging-protocols/client/helpers/attributes.js
+++ b/Packages/ohif-hanging-protocols/client/helpers/attributes.js
@@ -1,19 +1,22 @@
-UI.registerHelper('viewportSettingsTypes', function() {
+import { Blaze } from 'meteor/blaze';
+
+
+Blaze.registerHelper('viewportSettingsTypes', function() {
return HP.viewportSettingsTypes;
});
-UI.registerHelper('toolSettingsTypes', function() {
+Blaze.registerHelper('toolSettingsTypes', function() {
return HP.toolSettingsTypes;
});
-UI.registerHelper('studyAttributes', function() {
+Blaze.registerHelper('studyAttributes', function() {
return HP.studyAttributes;
});
-UI.registerHelper('seriesAttributes', function() {
+Blaze.registerHelper('seriesAttributes', function() {
return HP.seriesAttributes;
});
-UI.registerHelper('instanceAttributes', function() {
+Blaze.registerHelper('instanceAttributes', function() {
return HP.instanceAttributes;
});
diff --git a/Packages/ohif-hanging-protocols/client/helpers/displayConstraint.js b/Packages/ohif-hanging-protocols/client/helpers/displayConstraint.js
index daae772f3..09e9a0509 100644
--- a/Packages/ohif-hanging-protocols/client/helpers/displayConstraint.js
+++ b/Packages/ohif-hanging-protocols/client/helpers/displayConstraint.js
@@ -1,39 +1,71 @@
-function humanize(text) {
- var humanized = text.replace(/([A-Z])/g, ' $1'); // insert a space before all caps
- humanized = humanized.replace(/^./, function(str) { // uppercase the first character
+import { Blaze } from 'meteor/blaze';
+
+const attributeCache = Object.create(null);
+const REGEXP = /^\([x0-9a-f]+\)/;
+
+const humanize = text => {
+ let humanized = text.replace(/([A-Z])/g, ' $1'); // insert a space before all caps
+
+ humanized = humanized.replace(/^./, str => { // uppercase the first character
return str.toUpperCase();
- })
+ });
+
return humanized;
-}
+};
-UI.registerHelper('displayConstraint', function(attribute, constraint) {
- if (!constraint) {
+/**
+ * Get the text of an attribute for a given attribute
+ * @param {String} attributeId The attribute ID
+ * @param {Array} attributes Array of attributes objects with id and text properties
+ * @return {String} If found return the attribute text or an empty string otherwise
+ */
+const getAttributeText = (attributeId, attributes) => {
+ // If the attribute is already in the cache, return it
+ if (attributeId in attributeCache) {
+ return attributeCache[attributeId];
+ }
+
+ // Find the attribute with given attributeId
+ const attribute = attributes.find(attribute => attribute.id === attributeId);
+
+ let attributeText;
+
+ // If attribute was found get its text and save it on the cache
+ if (attribute) {
+ attributeText = attribute.text.replace(REGEXP, '');
+ attributeCache[attributeId] = attributeText;
+ }
+
+ return attributeText || '';
+};
+
+Blaze.registerHelper('displayConstraint', (attributeId, constraint, attributes) => {
+ if (!constraint || !attributeId) {
return;
}
- if (!attribute) {
+ const validatorType = Object.keys(constraint)[0];
+ if (!validatorType) {
return;
}
- var validatorType = Object.keys(constraint)[0];
- if (!attribute) {
+ const validator = Object.keys(constraint[validatorType])[0];
+ if (!validator) {
return;
}
- var validator = Object.keys(constraint[validatorType])[0];
- if (!attribute) {
+ const value = constraint[validatorType][validator];
+ if (value === void 0) {
return;
}
- var value = constraint[validatorType][validator];
- if (value === undefined) {
- return;
- }
-
- var comparator = validator;
+ let comparator = validator;
if (validator === 'value') {
comparator = validatorType;
}
- return humanize(attribute) + ' ' + humanize(comparator).toLowerCase() + ' ' + value;
+ const attributeText = getAttributeText(attributeId, attributes);
+ const constraintText = attributeText + ' ' + humanize(comparator).toLowerCase() + ' ' + value;
+
+ return constraintText;
});
\ No newline at end of file