reorganize packages, start converting overall app to react (very broken at the moment)

This commit is contained in:
Erik Ziegler committed 2018-12-12 18:06:25 +01:00
1 parent 024fe1a448
commit 5f30f7bd35
479 files changed
+5364 -11611

No files matched your search

@@ -0,0 +1,19 @@
import { OHIF } from 'meteor/ohif:core';
// Return an absolute URL with the page domain using sub path of ROOT_URL
// to let multiple domains directed to the same server work
OHIF.utils.absoluteUrl = function(path) {
let absolutePath = '/';
const absoluteUrl = Meteor.absoluteUrl();
const absoluteUrlParts = absoluteUrl.split('/');
if (absoluteUrlParts.length > 4) {
const rootUrlPrefixIndex = absoluteUrl.indexOf(absoluteUrlParts[3]);
absolutePath += absoluteUrl.substring(rootUrlPrefixIndex) + path;
} else {
absolutePath += path;
}
return absolutePath.replace(/\/\/+/g, '/');
};
+13
View File
@@ -0,0 +1,13 @@
/**
* Create a random GUID
*
* @return {string}
*/
export default function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
+8
View File
@@ -0,0 +1,8 @@
import { OHIF } from 'meteor/ohif:core';
import './absoluteUrl';
import './objectPath';
import guid from './guid';
OHIF.utils = OHIF.utils || {}
OHIF.utils.guid = guid;
@@ -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;