LT-67: Refactoring schema validation
This commit is contained in:
1 parent
9e2ab2d21a
commit
2a119a5464
12 files changed
+156
-176
No files matched your search
@@ -31,7 +31,7 @@ OHIF.blaze.getParentView = (view, parentViewName) => {
|
||||
};
|
||||
|
||||
// Search for the parent component of the given view
|
||||
OHIF.blaze.getParentComponent = (view) => {
|
||||
OHIF.blaze.getParentComponent = view => {
|
||||
let currentView = view;
|
||||
while (currentView) {
|
||||
currentView = currentView.originalParentView || currentView.parentView;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import './blaze.js';
|
||||
import './object.js';
|
||||
import './string.js';
|
||||
import './user.js';
|
||||
@@ -0,0 +1,50 @@
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.object = {};
|
||||
|
||||
// Transforms a shallow object with keys separated by "." into a nested object
|
||||
OHIF.blaze.getNestedObject = shallowObject => {
|
||||
var nestedObject = {};
|
||||
for (var key in shallowObject) {
|
||||
var value = shallowObject[key];
|
||||
var propertyArray = key.split('.');
|
||||
var currentObject = nestedObject;
|
||||
while (propertyArray.length) {
|
||||
var currentProperty = propertyArray.shift();
|
||||
if (!propertyArray.length) {
|
||||
currentObject[currentProperty] = value;
|
||||
} else {
|
||||
if (!currentObject[currentProperty]) {
|
||||
currentObject[currentProperty] = {};
|
||||
}
|
||||
|
||||
currentObject = currentObject[currentProperty];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nestedObject;
|
||||
};
|
||||
|
||||
// Transforms a nested object into a shallowObject merging its keys with "." character
|
||||
OHIF.blaze.getShallowObject = nestedObject => {
|
||||
var shallowObject = {};
|
||||
var putValues = function(baseKey, nestedObject, resultObject) {
|
||||
for (var key in nestedObject) {
|
||||
var currentKey = baseKey ? baseKey + '.' + key : key;
|
||||
var currentValue = nestedObject[key];
|
||||
if (typeof currentValue === 'object') {
|
||||
if (currentValue instanceof Array) {
|
||||
currentKey += '[]';
|
||||
}
|
||||
|
||||
putValues(currentKey, currentValue, resultObject);
|
||||
} else {
|
||||
resultObject[currentKey] = currentValue;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
putValues('', nestedObject, shallowObject);
|
||||
return shallowObject;
|
||||
};
|
||||
Reference in new issue
Block a user